script help

Bill Davidsen davidsen at tmr.com
Mon Dec 1 21:22:16 UTC 2008


adrian kok wrote:
> Hi
> 
> I have script to remove files but it can't work in
> directory
> 
> 
> ls *log | sort -r | sed -e 1,1d | xargs rm -f
> 
> those folders are:
> 
> Nov28-log
> Nov29-log
> Nov30-log
> 
What is it you are trying to do here? Are you trying to remove files in the 
directory leaving the directory name, or remove the directory, or ??? What is 
the sort trying to do, given that month names don't occur in alphabetical order...

If you are trying to remove all but the two most recent directories (I'm 
guessing here):
  ls -dt *-log | tail -n +3 | xargs rm -rf

That won't work if filenames contain blanks, something I fight daily.

-- 
Bill Davidsen <davidsen at tmr.com>
   "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot




More information about the fedora-list mailing list