LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-21-2004, 01:54 PM   #1
smeenge
LQ Newbie
 
Registered: May 2004
Posts: 3

Rep: Reputation: 0
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

Last edited by smeenge; 05-21-2004 at 02:01 PM.
 
Old 05-21-2004, 07:34 PM   #2
Linux.tar.gz
Senior Member
 
Registered: Dec 2003
Location: Paris
Distribution: Slackware forever.
Posts: 2,328

Rep: Reputation: 89
Take a look to the man pages of:
whereis
find
locate
 
Old 05-21-2004, 08:15 PM   #3
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
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:
1) Search the subdirectories to find files over a given size (say 20MB for example)
Just use the du command and then use the redirect command like > or >>. The > is make a file and empty it out. It also takes an existing file and empties it out, so be careful. The >> is make a file and append or add to the file. If it exists just add to it.

You could probably just use the find command. Check the manual several times to get an idea.

Quote:
2) A command that will search the subdirectories and find/list all subdirectories that contain more than 10,000 files
You can use ls command or you could use find.

[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.
 
Old 05-22-2004, 04:02 AM   #4
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 83
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 11:22 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 04:15 AM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 10:11 PM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 11:31 AM
Pruning termcap aditya Linux - General 1 09-06-2002 04:03 AM


All times are GMT -5. The time now is 10:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration