Copying all the .sh files into a tar file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying all the .sh files into a tar file
# 1  
Old 03-07-2013
Copying all the .sh files into a tar file

Hi All ,
I need to tar all the .sh files in a server along with the path .
Please let me know is there any way this can be accomplished .
Need to grep through all the directories and sub directories in a server and tar all the .sh scripts .
# 2  
Old 03-07-2013
This is pretty much straightforward task.

Run find and tar:
Code:
find . -name "*.sh" -type f | xargs tar -cvf sh_scripts.tar

# 3  
Old 03-07-2013
No need for xargs, mant tar runs, just use "T - " tar option to read files to archive. An * prevents them being all prefixed with './':
Code:
find * -name "*.sh" -type f | tar -cvT - -f sh_scripts.tar

Man Page for tar (all Section 0) - The UNIX and Linux Forums
# 4  
Old 03-07-2013
Quote:
Originally Posted by DGPickett
No need for xargs, mant tar runs, just use "T - " tar option to read files to archive. An * prevents them being all prefixed with './':
Code:
find * -name "*.sh" -type f | tar -cvT - -f sh_scripts.tar

Man Page for tar (all Section 0) - The UNIX and Linux Forums
Is that a standard option or a GNU one?
# 5  
Old 03-07-2013
Probably not for older tar's like my HPUX11.00. Solaris says -I, HP-UX 11.00 says nothing. I see tar can walk a tree, but no filter exclude/include options on old tar. Another reason to like cpio! Always took file names from stdin. Great for piping trees over the network:
Code:
find ... | cpio -o ... | bzip2 -9 | ssh somewho@somewhere 'cd target ; bunzip2 | cpio -i ...'

The compressor bzip2 multiplies the network speed and divides the ssh encryption cost. For some compress or gzip will be a better choice: less compression but faster flow.

Last edited by DGPickett; 03-07-2013 at 04:31 PM..
This User Gave Thanks to DGPickett For This Post:
# 6  
Old 03-07-2013
Another simple way.

Send find output to a file.
Then, use tar --files-from option, with the file just created.

If any question, can view the file to see what is going to be tarred.
# 7  
Old 03-08-2013
--files-from is -T, see man page link above.
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files to a directory, renaming it if a file with the same name already exists

Hi All, I need to copy files from one directory to another with the files to be renamed while copying if a file with the same name already exists in the target directory. THanks, Dev (2 Replies)
Discussion started by: dev.devil.1983
2 Replies

2. Shell Programming and Scripting

Copying a file to multiple other files using a text file as input

Hello, I have a file called COMPLIST as follows that contains 4 digit numbers.0002 0003 0010 0013 0015 0016 0022 0023 0024 0025 0027 0030 0031 0032 0033 0035 0038 0041 (3 Replies)
Discussion started by: sph90457
3 Replies

3. Shell Programming and Scripting

To tar the content while copying files

Any idea on how we can tar the content while copying the files from one location to another location using the bash script. (2 Replies)
Discussion started by: gsiva
2 Replies

4. Shell Programming and Scripting

Copying List of Files Under Different File Names ?!

Hi to all here , Excuse me for the lamer question but I need UNIX command for copying List of Files Under Different File Names ! for example I have this list: new_001.jpg new_002.jpg new_003.jpg ..... I want to copy all files that start with "new_" to the same directory but under... (7 Replies)
Discussion started by: boboweb_
7 Replies

5. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

6. UNIX for Dummies Questions & Answers

No such file or directory error while copying files

Hi, I need to copy files from one dir to another dir. The list of filesnames to be moved are in a file called files2cp.log Script: #!/bin/ksh exec 0</home/amdocs/files2cp.log while read LINE do cp -i /iccs33/attach/"$LINE" /iccs30/attach/"$LINE" done The output is "No such... (6 Replies)
Discussion started by: srinirsr
6 Replies

7. Shell Programming and Scripting

Perl-opening a file then copying files

Good morning guys!! Im still practicing with Perl and now Im trying to open a file, and copy its contents to another file. Them I want to remeove the information out of the orginal file after it is copied over. The flow should be messages-->messages1-->messages2. Kind of like a log... (1 Reply)
Discussion started by: bigben1220
1 Replies

8. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

9. AIX

copying files to a remote aix server using tar!

Hi, I am using AIX 5.2, and I want to copy some files from one server to a remote server using tar command. Can anybody tell me exact command? Thanks. Aqeel (2 Replies)
Discussion started by: system-admin
2 Replies

10. UNIX for Dummies Questions & Answers

Copying files from file to another

How do I copy one file from one unix file to another??? I'm new at this, please help.. (3 Replies)
Discussion started by: Tevin
3 Replies
Login or Register to Ask a Question