Computers & Electronics

LINUX - Need help with tar command

  • Last Updated:
  • Dec 21st, 2009 3:39 pm
Tags:
None
Deal Addict
Jan 6, 2004
4255 posts
833 upvotes
T.O.

LINUX - Need help with tar command

Hi,
I need some help with a tar command in linux.

I need to backup the contents of a folder, but also need to exclude some directories.

My directory structure.

home
>files
>names
>recordings
>laps
>>reside
>>receipe
>>koling
>hello

I need to tar the whole home directory, but exclude all the whole "recordings" directory, and also in the "lap" directory, I only need the files in it, but not the directories. Note that the directories in the laps folder are auto-generated and have different names, and the amounts of subdirectories are random aswell.

What's the most efficient way of doing this with a tar command?
Heatware: Link
HowardForums: Link
7 replies
Sr. Member
User avatar
Aug 14, 2005
667 posts
16 upvotes
Gloucester
if in the same dir as home:

tar -zcvf mybackup.tar --exclude='recordings' --exclude='reside' --exclude='receipe' --exclude='koling' /home
Banned
Jun 19, 2006
9349 posts
57 upvotes
Minh wrote: if in the same dir as home:

tar -zcvf mybackup.tar --exclude='recordings' --exclude='reside' --exclude='receipe' --exclude='koling' /home
The 'danger' in this is that there may be files named 'recordings', 'reside', 'receipe', 'koling', in other directories. These would get excluded, even though the intent is to exclude the directories.

And of course..."/home" might not be correct either unless "home" is a directory off of the root filesystem. OP hasn't given enough info on this.


(and of course...the 'z' in the command means you get a gzip archive instead of the tar archive that the OP wanted.... )
"I worked with several H1B employees that were/are borderline ********. One of them wanted to spray an electrical patch panel with solvent to see if it would make the “network go faster”". <--- lol (source)
Sr. Member
User avatar
Aug 14, 2005
667 posts
16 upvotes
Gloucester
pitz wrote: The 'danger' in this is that there may be files named 'recordings', 'reside', 'receipe', 'koling', in other directories. These would get excluded, even though the intent is to exclude the directories.

And of course..."/home" might not be correct either unless "home" is a directory off of the root filesystem. OP hasn't given enough info on this.


(and of course...the 'z' in the command means you get a gzip archive instead of the tar archive that the OP wanted.... )
Yes this is true, i was under the assumption OP knows how to use tar and just needed guidance in terms of tar syntax.
Deal Addict
Jan 6, 2004
4255 posts
833 upvotes
T.O.
Minh wrote: if in the same dir as home:

tar -zcvf mybackup.tar --exclude='recordings' --exclude='reside' --exclude='receipe' --exclude='koling' /home
The folders are in the laps sub-directory (reside,receipe,koling) where the recording is a direct sub-directory of home.


I'm pretty unfamiliar with the command > :(

So if there's a file called recording.xml or recoding.html anywhere else in any of the folders it will get excluded aswell?
Heatware: Link
HowardForums: Link
Deal Addict
Jan 6, 2004
4255 posts
833 upvotes
T.O.
pitz wrote: The 'danger' in this is that there may be files named 'recordings', 'reside', 'receipe', 'koling', in other directories. These would get excluded, even though the intent is to exclude the directories.

And of course..."/home" might not be correct either unless "home" is a directory off of the root filesystem. OP hasn't given enough info on this.


(and of course...the 'z' in the command means you get a gzip archive instead of the tar archive that the OP wanted.... )
I figured out that the home should be in the root, and I'll modify that accordingly.

Is there a way to exclude directories instead of filenames?
Heatware: Link
HowardForums: Link
Deal Addict
Jul 29, 2002
1958 posts
84 upvotes
Minh wrote: if in the same dir as home:

tar -zcvf mybackup.tar --exclude='recordings' --exclude='reside' --exclude='receipe' --exclude='koling' /home
perhaps modify the exclude so it's the complete path

--exclude='/home/recordings'. This way it shouldn't match a file named "recording" in another directory.
Sr. Member
User avatar
Aug 14, 2005
667 posts
16 upvotes
Gloucester
siriuskao wrote: perhaps modify the exclude so it's the complete path

--exclude='/home/recordings'. This way it shouldn't match a file named "recording" in another directory.
Yes you can use absoloute paths as a way....

OP you dont have to move the entire directory to the root, just adjust the last part /home to w/e the file "home" is located.

Top

Thread Information

There is currently 1 user viewing this thread. (0 members and 1 guest)