Tar-ing folders in a folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Tar-ing folders in a folder
# 1  
Old 08-01-2011
Tar-ing folders in a folder

How do I create individual tars of a all the directories in a directory? I have a directory called 'patients', each patient has a directory in the patients directory. I want to create tars such that each patient has their own tar file.

Thanks!
# 2  
Old 08-01-2011
Try:
Code:
for p in patients/*; do                                                   
    pd=`basename "$p"`
    tar -C patients -cf "$pd".tar "$pd"
done

# 3  
Old 08-31-2011
tar script

Yazu,
Thank you for the suggestion. It works great. Is there a way to have the folders tarred with relative paths?

Here is the script I have so far:
Code:
for p in /FOCUS/rtp99/0/*; do                                                   
   pd=`basename "$p"`
   tar -C /FOCUS/rtp99/0 -czvf "$pd".tgz "$pd"
done

It would be great if I could set it so that when it untars it only untars the files with the relative directory. For instance if my patient folder is A1000156, if I untar it it becomes:

/FOCUS/rtp99/0/A1000156

The reason I want to do this is because I tar it from one directory and untar it in another. It is a way of moving files form one of our clinics to another. So when I try to untar it into say the "1" directory it becomes:

/FOCUS/rtp99/1/FOCUS/rtp99/1/A1000156

Maybe if I place the script itself in the /FOCUS/rtp99/0/ directory and take out the "-C /FOCUS/rtp99/0"?

Thanks!!

HP

Last edited by vbe; 08-31-2011 at 10:44 AM.. Reason: please use code tags when required (code and data)
# 4  
Old 08-31-2011
switch
Code:
tar -C patients -cf "$pd".tar "$pd"

to
Code:
tar -cf "$pd".tar patients/"$pd"

# 5  
Old 08-31-2011
tar with relative path

Quote:
Originally Posted by sulti
switch
Code:
tar -C patients -cf "$pd".tar "$pd"

to
Code:
tar -cf "$pd".tar patients/"$pd"

If I do that will I will need to place the script in the patients directory?
# 6  
Old 08-31-2011
No. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping through all folders in a folder.

I am trying to write a script that loops through all the folders within a given folder. My intention is to access each folder and rename each file ending with fna.gz with the name of the folder it resides in. #!/bin/bash cd /p/w/d/ for f in /p/w/d/*; do echo $f done I'm... (13 Replies)
Discussion started by: Mr_Keystrokes
13 Replies

2. Shell Programming and Scripting

How to delete other's folders which are in our own folder?

Hi All, I need a solution for the following scenario. I am the owner for the particular folder and I have given 777 permissions for some specific reasons. So others can able to create folders and files. But when I am done with the work, I need to delete the folders which are created by... (4 Replies)
Discussion started by: manoj_thorali
4 Replies

3. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

4. UNIX for Advanced & Expert Users

Speed problems with tar'ing a 500Gb directory on an eSATA drive

I'm trying to compress a directory structure on an external hard drive, connected by eSATA cable to my linux (Ubuntu 10.04) desktop. The total volume is 500Gb with half a million files, ranging from Kb to Mb in size. The drive is 2Tb, with 0.8Tb free space before compression. running "tar -pcf... (10 Replies)
Discussion started by: omnisppot
10 Replies

5. Shell Programming and Scripting

grep'ing and sed'ing chunks in bash... need help on speeding up a log parser.

I have a file that is 20 - 80+ MB in size that is a certain type of log file. It logs one of our processes and this process is multi-threaded. Therefore the log file is kind of a mess. Here's an example: The logfile looks like: "DATE TIME - THREAD ID - Details", and a new file is created... (4 Replies)
Discussion started by: elinenbe
4 Replies

6. UNIX for Dummies Questions & Answers

Jar/Tar to a diffent folder/same folder w/ filename

Hi, I want to extract myfile.war to a folder which is in the same folder with war file.I did this as normal: jar -xvf myfile.war But it exploded all the content of file to the same level folder instead of that I was expecting to create a folder called myfile. This works with tar: ... (0 Replies)
Discussion started by: reis3k
0 Replies

7. UNIX for Dummies Questions & Answers

Tar-ing the correct directories

Hi all, my directory structure is as follows /a/b/c. I would like to tar the /a directory including the subdirectories b and c. i intend to use the command tar -cvfz a.tgz a/ My question is where do i execute the command? do i execute it at the '/' prompt or at '/a' prompt ? My concern at... (1 Reply)
Discussion started by: new2ss
1 Replies

8. UNIX for Dummies Questions & Answers

tar'ing and regular expressions

Hi, How do I tar all but a specific set of files in a directory? Is it possible to use regular expressions in the tar command? I want to tar all files except those beginning with D. I tried this tar -cvf files.tar ^ but this didn't work. Anyone any ideas. Thanks (2 Replies)
Discussion started by: sirbrian
2 Replies

9. UNIX for Dummies Questions & Answers

tar'ing and zipping files

If I have a directory /directory1 and want to tar and zip everything in it into a file new_tar.tar.gz on disk (not tape) How can I do it? I tried tar -cv /new_tar.tar /directory1/* But I got an error: tar: /dev/rmt/0: No such device or address (4 Replies)
Discussion started by: FredSmith
4 Replies

10. Solaris

Error tar'ing files to tape

I'm trying to tar a bunch of files off to a tape, but for one specific file (it is fairly large, roughly 10Gb) I get the error: too large to archive Does tar have a limit of the size of file it can write off to tape? I'm using SunOS 5.8. Thanks! -Fred (6 Replies)
Discussion started by: FredSmith
6 Replies
Login or Register to Ask a Question