Register
It is currently Sun Apr 20, 2014 2:18 am

Looking for a script to tar all BASH SHELL SCRIPT files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed May 04, 2011 1:56 pm   

Joined: Wed May 04, 2011 1:50 pm
Posts: 3
I would like to tar and gzip all files which start with the line:
#!/bin/bash
Starting at / directory and recursively archiving all such files...

How would I easily go about this?
:-/ Martin


Top
 Profile  
 PostPosted: Thu May 05, 2011 8:21 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Code:
grep '^#!/bin/bash' -Hnr / | grep :1: | cut -f1 -d: | xargs tar -czf archive.tgz

Be patient, it can take some time.


Top
 Profile  
 PostPosted: Thu May 05, 2011 10:31 am   

Joined: Wed May 04, 2011 1:50 pm
Posts: 3
Thanks choroba... this looks like it should do the job...

Can you think of any way to avoid checking all the lines in the file for #!/bin/bash ??
I have some very large text files on the system and lots of 'em...

Martin :-/


Top
 Profile  
 PostPosted: Thu May 05, 2011 2:30 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
CRIPTKicker wrote:
Can you think of any way to avoid checking all the lines in the file for #!/bin/bash ??
I have some very large text files on the system and lots of 'em...

You're worried about text files? I'd be more worried about movies and mp3 collection all getting scanned by this :) But fair is fair, he did warn it could take a while ;)


Top
 Profile  
 PostPosted: Fri May 06, 2011 9:20 am   

Joined: Wed May 04, 2011 1:50 pm
Posts: 3
I have hundreds of multiple-GB sized text files... This is a work computer... there are no .mp3 files or movie files... :-O


Top
 Profile  
 PostPosted: Fri May 13, 2011 6:05 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 224
Location: London - UK
If you can be certain that the bash files are all limited to a maximum size, eg 10MB which is huge, then the 'find' command can be used to limit the search to only the smaller files.
It's also possible that using the 'file' command will run faster than grep for this, although it should be benchmarked :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP