Need some file pruning help...
I am an absolute Linux newbie, and am not even familiar enough with the find command and/or piping commands in order to figure this out.
I have a drive that needs periodic file pruning...here is the scenario: I have a directory called /var/vpopmail/domains with thousands of folders and subfolders and subfiles within. I need to know a command that can help me: 1) Search the subdirectories to find files over a given size (say 20MB for example) 2) A command that will search the subdirectories and find/list all subdirectories that contain more than 10,000 files 3) A command that will search the subdirectories and delete all files that are older than 180 days. Any help would be appreciated, i'm running out of disk space quickly! Thanks. jeff FYI, RedHat 9 |
Take a look to the man pages of:
whereis find locate |
Piping is very, very powerful. Piping is like process some shit and transfer it to something else. For example
ls -l | tr -s ' ' ' ' What this does use the ls command with the -l option. Instead of creating neat columns. Let's take out all the spaces and just leave one space to be processed with something later. Another one that is used a lot cat textfile | more The cat command list the textfile and pipes it to the more command. The more command displays a full screen at a time and waits for your response to continue. The less command does the samething as more. Quote:
You could probably just use the find command. Check the manual several times to get an idea. Quote:
[quote] 3) A command that will search the subdirectories and delete all files that are older than 180 days. [quote] Just use the find command. Something like find /var/vpopmail/domains -mtime 180 -exec rm -vf {} \; You probably want to redirect the output to a file for a log. mtime will be in 180 days and if its true delete it. The {} designates a place holder for files. Check the manual to make sure I'm right and some other options to tweak it to better suit you. I suggest playing with certain commands then place them in a script. |
1. find -size +39063
2. dunno, it's late and I'm tired 3. find /var/vpopmail/domains -mtime +180 -exec rm {} \; Notes: These are important. Pay attention. As the other posters have indicated, you need to read the man pages. Just enter this command: man find Practice these commands on "safe" files/directories so that if things go awry they won't have any significant impact. Comments: for the first item, I'll assume your system uses 512 blocks, therefore 20M/512 = 39063. The "+39063" indicates "greater than or equal to" Note that "-39063" would mean <= and "39063" would mean exactly =. For the third item, the +180 indicates >= 180 days old, -180 would mean <= 180 days, etc. Since this command will physically delete any files that meet the conditions, you would want to be very sure that the result set is correct before you execute it. To use a safer example, just substitute "ls -l" in place of "rm" as that will simply return a directory listing rather than to perform a delete. The main thing though is to read the manual: man find Good luck with it -- J.W. |
All times are GMT -5. The time now is 01:18 AM. |