Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-01-2002
Registered User
 

Join Date: Jun 2001
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Too many files to list / remove

I have a directory which has 614,000 files.

When attempting to do an ls -ralt in the directory an error too many arguments is shown.

1. I would like to see what files and their stats in the directory
2. I would like to delete certain files of a certain age
Sponsored Links
  #2  
Old 08-01-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Thanks: 0
Thanked 0 Times in 0 Posts
You should be able to manage this with a simple for loop.

for each_file in /path/directory/*
do
echo ls -latr $each_file >> directory_log
done

Now you can't have your cake and eat it to... so if you want to see this list first (beofre you remove the old files) then you can view this file.

If you then want to remove old files...

find /path/directory/ -mtime +29 -exec ls {} \;

Where +29 says anything over 29 days in the specified directory.

You could combnie these into one command if you want...but I'll leave you something to do!

Oh postscript.....the mtime is date modified !
  #3  
Old 08-01-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
Registered User
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,090
Thanks: 0
Thanked 6 Times in 3 Posts
Peter's quote:
Quote:
If you then want to remove old files...
find /path/directory/ -mtime +29 -exec ls {} \;
I believe he meant -exec rm {} \; . When testing this, I always put the ls instead of rm.

Another thought (I can't test it - none of my servers have that many files in one directory) is that Peter's -exec ls would give you a listing with no problem (it would not be ls -latr) but you would be able to see all the files.
  #4  
Old 08-02-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
Thanks: 0
Thanked 8 Times in 8 Posts
Handling a directory this large is going to require very careful attention to performance considerations. I usually hold my tongue when I see someone suggest the -exec option on a "find" command. But in this case, it will be a very large problem. A command like:

find /path/directory/ -mtime +29 -exec ls {} \;

is going to launch one "ls" process for each file. In this case, that is way too many. We need to get as many files on the "ls" (or "rm") command line as possible. That way, a single process will be handling dozens or maybe hundreds of files at once. We can do this with:

cd /path/directory
find . -mtime +29 -print | xargs ls -d

(I always use -d in a case like this in case the "find" output a subdirectory.) By cd'ing to the directory first and then use "." in the "find" command, we shorten the pathname that find will output. This means that xargs can collect more of them for each "ls" process that it invokes.

Using xargs is always better than -exec, but with a small number of files, it's not a big deal.

Peter may have meant "ls", the OP did request help obtaining such a listing. But can anyone read a listing that is 600,000 lines long? There is really no point to such a listing.

Any shell script written to process these files will also need careful attention to performance.
This:

for each_file in /path/directory/*

is not going to work. The shell will try to expand that asterisk and it will fail. Something like this:

#! /usr/bin/ksh
cd /path/directory
find . -print | while read each_file ; do

will work, but whatever the loop does it must be carefully coded. It must use only shell built-in commands and maybe some pre-launched co-processes. Invoking even 4 or 5 processes per loop will mean millions of total processes. Such a script would take a very long time to run.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
list the files but exclude the files in subdirectories shyjuezy UNIX for Dummies Questions & Answers 8 10-15-2008 01:42 PM
read list of filenames from text file and remove these files in multiple directories fxvisions Shell Programming and Scripting 5 08-07-2008 03:59 PM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 08:56 PM
How To Remove files starting with - rahulrathod UNIX for Advanced & Expert Users 2 09-29-2004 03:19 PM
remove files Nisha Shell Programming and Scripting 7 06-26-2002 12:04 AM



All times are GMT -4. The time now is 07:57 AM.