Operating System - Linux
1833832 Members
2385 Online
110063 Solutions
New Discussion

need syntax of tar command

 
SOLVED
Go to solution
Debbie Fleith
Regular Advisor

need syntax of tar command

I need to restore 4 files from a system backup tape written to with tar. If I backed up to tape with the following command:

tar -cvp . -X /usr/bin/backuproot.exclude --label="Root Backup created on `date
'+%d-%B-%Y'`" -f /dev/st0

What is the syntax of the tar command that will restore a list of 4 filenames that I will put in a /tmp/filelist file?

Do the full pathnames of the files I put in my /tmp/filelist file need a "/" in front?

4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: need syntax of tar command

tar xvf

P option will preserve absolute paths

F --file will let you retore one file from an archive and wildcards are accepted.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Debbie Fleith
Regular Advisor

Re: need syntax of tar command

I want to restore several files to a new path in one command if possible, and not overwrite the actual files. My tar command was executed from the / level.
Steven E. Protter
Exalted Contributor

Re: need syntax of tar command

I think it will take multiple files in the --file section.

Try the command with a smaller tar archive against the /tmp filesystem. That way the experimentation won't harm anything important.

Good Luck,

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Gopi Sekar
Honored Contributor
Solution

Re: need syntax of tar command


if you want to extract only one particular from a tar archive then this is the syntax

tar -xvf tar-file.tar file-to-extract

file-to-extract is the filename with full path in the same exact manner how it is stored in archive. eg: home/user1/test_123/test

you can use wild cards for file-to-extract. eg: home/user1/test_123/*

or you can have list of files to be extracted in to a single file and use that as referrence to extract

eg:
file1 contains:
home/user1/test_123/test
home/user2/test/user
tmp/output

to extract these files, you can use the tar
command: tar --files-from file1 -xvf tar-file.tar

this will extract the specified files and store them relative to the current path, if you have not used absolute path referrence while creating the archive

Regards,
Gopi
Never Never Never Giveup