LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-20-2006, 10:52 AM   #1
Drack
LQ Newbie
 
Registered: Feb 2006
Distribution: Gentoo and Debian
Posts: 8

Rep: Reputation: 0
Mass file manipulation


I have a few directories full of thousands of similar files, most of them redundant, taking up a huge amount of space. There are a few procedures that I'd like to run these files through to reclaim much of this space both by file compression and trimming the redundant files. I think that shell scripts would be the most effective tool for this but I need to know which programs I should be reading about to accomplish it.

Anyway, here are some of the batch procedures I'd like to do to organize this mess:

-Zip all files into individual zips. filename.ext becomes filename.zip with best compression (I hear 7zip makes the most compressed .zips).

-Delete all files whose filenames contain a substring
This has already been answered to my satisfaction - It was handed to me! This alone has reclaimed about a dozen gigs of space! I'd link to the post but I can't include links until I have at least 5 posts so just search under my username if you want the solution.

-Delete all files with filenames that contain substring1 but do not contain substring2

Here's where it starts getting tricky. The filenames are often in the format "Title (additional info)"
-Delete all files with one "additional info" string where another file with the same title with preferable additional info exists. For instance, delete any "Same Title (Revision A).zip" files if "Same Title (Revision B).zip" is found in the directory.

What programs can do this under linux? I think I have some manpages to read.

Last edited by Drack; 02-20-2006 at 10:55 AM.
 
Old 02-20-2006, 11:18 AM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
Here's a mass file zipping script (run from the directory with the files):

for i in *; do zip `basename $i .wmv`.zip $i; done


change the ".wmv" to whatever file extension you're zipping. If you leave out the basename text, you'll get filenames like "file.wmv.zip" instead of "file.zip". also, note those are back quotes (from the ~ key).

For the deleting, can't you just rm *\(Revision\ A\)*.zip. The "\" allows you to use special characters like parenthesis, spaces, etc.

Last edited by pljvaldez; 02-20-2006 at 11:19 AM.
 
Old 02-21-2006, 09:41 AM   #3
Drack
LQ Newbie
 
Registered: Feb 2006
Distribution: Gentoo and Debian
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks.
 
Old 02-21-2006, 09:45 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Its always good to understand find, for,.. but for the task of mass renaming, mass moving, mass linking you can try:
http://linux.maruhn.com/sec/mmv.html

There should be a downloadable package on every distribution, at least on Debian there is
 
Old 02-25-2006, 03:37 PM   #5
Drack
LQ Newbie
 
Registered: Feb 2006
Distribution: Gentoo and Debian
Posts: 8

Original Poster
Rep: Reputation: 0
Tried the for command, but it didn't work on filenames with spaces in them The spaces divided what was stored in i.
 
Old 02-27-2006, 06:40 AM   #6
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Code:
for i in *.wmv; do zip "`basename "$i" .wmv`".zip "$i"; done
Prevent bash interpretation of spacing by quoting $i

Here's one more general, use the replace of bash:

Code:
for i in *.wmv; do zip "${i/wmv/zip}" "$i"; done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script: File Manipulation simon_qwl Programming 2 10-29-2005 03:40 PM
file manipulation with c C.Aymen Programming 2 09-01-2005 12:48 PM
C File Manipulation in Linux drigz Programming 5 10-01-2004 07:28 AM
File name manipulation with tr, concatination troubles goofyheadedpunk Programming 9 07-06-2004 02:39 AM
File manipulation of NTFS from RHat 9 javadudd Linux - Newbie 3 04-01-2004 08:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration