1833723 Members
2508 Online
110063 Solutions
New Discussion

tar

 
SOLVED
Go to solution
Anjaneyulu
Frequent Advisor

tar

hi problem with tar command.

i created two files in /home directory as 1 2.
after that i create one directory as a. Iam trying to restore the files in a directory.

tar cvf files.tar 1 2 a
cd a
tar xvf files.tar a
It gives the error like
tar: files.tar: No such file or directory

Please help me.

15 REPLIES 15
unixguy_1
Regular Advisor

Re: tar


Dear Anjaneyulu,

where you are going take a backup for using tar.

for examble u use the below method.

login to the home directory.

cd /home
home> tar -cvf files.tar 1 2 a

it's stored in the same home directory.like files.tar and remove it the exitsting directory.

then,

home> tar -xvf files.tar a

it will restore the mentioned directory.

u try this and revert back.....

Regards,
Unixguy.

Analyst
Trusted Contributor

Re: tar

Hi Anjaneyulu,

here the steps to follow.
tar options (destination) (source)
#tar cvf file.tar 1 2
#cd a
#tar xvf file.tar .



Anjaneyulu
Frequent Advisor

Re: tar

I followed your commands.

But it shows same error.

I want to copy the files from /home/anji to a1 directory
Venkatesh BL
Honored Contributor

Re: tar

> tar xvf files.tar a
> It gives the error like
> tar: files.tar: No such file or directory

After you did 'cd a'. you don't have to again specify 'tar xvf file.tar a'. Just specify 'tar xvf files.tar' (inside 'a' dir)
Anjaneyulu
Frequent Advisor

Re: tar

$ tar xvf file.tar
tar: file.tar: No such file or directory

It gives above error in dirctory a.
Ganesan R
Honored Contributor
Solution

Re: tar

Hi Anjaneyulu,

>>>I want to copy the files from /home/anji to a1 directory<<

First copy all the files from /home/anji and stored in /tmp/anji.tar

#tar -cvf /tmp/anji.tar /home/anji

Now goto the directory wherever you want to restore. Then extract the file.

#cd /tmp/a
#tar -xvf /tmp/anji.tar

It will restore all the files in /tmp/a directory.
Best wishes,

Ganesh.
unixguy_1
Regular Advisor

Re: tar








Hi Anjaneyulu,

Better u login to that directory.

cd /home/anji

home/anji> tar * files.tar

then that a1 directory is in home,login into a1.

home/anji>cp files.tar /home/a1

cd ..

cd a1

home/a1> tar -xvf files.tar

Hope now u r understood.

Regards,
Unixguy.




Jeeshan
Honored Contributor

Re: tar

you must not reside in the directory where you wanna restore files.

don't cd to a directory

cd to previous directory from where you taken the tar files and run command

#tar xvf files.tar a/
a warrior never quits
Wim Rombauts
Honored Contributor

Re: tar

Well, it's very simple :

tar cvf files.tar 1 2 a
cd a
tar xvf ../files.tar a

Since you create "files.tar" in the local directory and then do "cd" to a subdirectory, you have to go to the directory above to find your tar file.
Venkatesh BL
Honored Contributor

Re: tar


> tar cvf files.tar 1 2 a

As 'a' is the destination directory, that should not be specified during 'archival'

Example:

# ls
a.c a.out a1 a1.c a2 a2.c aa.c test
# tar -cvf a.tar a.c a1.c
a a.c 4 blocks
a a1.c 2 blocks

# mkdir xyz
# ls xyz
# mv a.tar xyz
# cd xyz
# tar -xvf a.tar
x a.c, 1631 bytes, 4 tape blocks
x a1.c, 781 bytes, 2 tape blocks
# ls
a.c a.tar a1.c
V. Nyga
Honored Contributor

Re: tar

Hi,

'tar cvf files.tar 1 2'
'mv files.tar a'
'cd a'
'tar xvf files.tar'

OR simply:

'mv 1 a'
'mv 2 a'
'cd a'

OR

'tar cvf a/files.tar 1 2'
'cd a'
'tar xvf files.tar'

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Prashanth Waugh
Esteemed Contributor

Re: tar

Hi ,

Pls try to understand the below ex.

1)tar - cvf /tmp/file.tar /home/pr/A/*
suppose i m going to diff directory
cd /home/qt
and run the below command
tar - xvf /tmp/file.tar
it will extarct the file in /home/xospnw01/A
============================================
now second example
cd /home/pr/A
tar - cvf /tmp/file.tar ./*
cd /home/qt
tar -xvf /tmp/file.tar
it will extact the file in /home/qt

==============================
If u r using the absolute path for doing the tar then u can extarct in the same path only.
=================================
if u r using relatve path for taring then u can exatrct in any path.

Hope u will underastand the concept

Reagrds
Prashant
For success, attitude is equally as important as ability
Steven Schweda
Honored Contributor

Re: tar

> I want to copy the files from /home/anji to
> a1 directory

Why didn't you say so at the beginning?

mkdir a # If needed.
( cd /home/anji ; tar cf - . ) | \
( cd a ; tar xf - )

There's no real need to create a "files.tar".
Prashanth Waugh
Esteemed Contributor

Re: tar

Hi ,
small correction here

1)tar - cvf /tmp/file.tar /home/pr/A/*
suppose i m going to diff directory
cd /home/qt
and run the below command
tar - xvf /tmp/file.tar
it will extarct the file in /home/pr/A

RegARDS
pRASHANT
For success, attitude is equally as important as ability
OldSchool
Honored Contributor

Re: tar

steven's solution is right on target...

and, of course, an example of that solution can be found in "man tar", had the original poster read it.