Results 1 to 10 of 10
I am trying to find a one line command with linux find to delete all files in a directory.
I know the directories are called "logs" but the filenames in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-14-2011 #1Just Joined!
- Join Date
- Sep 2011
- Posts
- 1
use LINUX find commands to delete files in directory
I am trying to find a one line command with linux find to delete all files in a directory.
I know the directories are called "logs" but the filenames in them vary widely.
I tried a lot of approaches centered around
find `pwd` -name logs -type d -exec rm {}/* \;
[ this doesn't expand the star ]
find `pwd` -name logs -type d -exec ls {} \; | xargs rm
rm $(find `pwd` -name logs -type d -print)
[ this cannot find the files as the filenames are listed without the path - just filename ]
I appreciate if anyone knows the answer.
Ralf
- 09-14-2011 #2Just Joined!
- Join Date
- May 2011
- Posts
- 44
How about:
Works for me anyway.Code:find -name 'logs' -type d | perl -ne 'print `rm -vrf $_`'
(to be clear, the -n implies a while(<>){ } around your code, it is the same as writing
Code:find -name 'logs' -type d | perl -e 'while(<>){print `rm -vrf $_`}'
- 09-14-2011 #3
I'm sure it can be done more elegantly, but
should work.Code:find `pwd` -name logs -type d|while read dir do rm $dir/* done
- 09-14-2011 #4Just Joined!
- Join Date
- May 2011
- Posts
- 44
- 09-15-2011 #5Just Joined!
- Join Date
- Sep 2007
- Location
- Silver Spring, MD
- Posts
- 83
Remove files from a directory called logs
Code:find $PWD -name logs -type d -exec ls {} \; | xargs rm -rf
- 09-15-2011 #6Just Joined!
- Join Date
- May 2011
- Posts
- 44
Given that parameter,
orCode:find ./logs | perl -ne 'print `rm -vrf $_`'
Code:find ./logs | perl -ne '`rm -rf $_`'
- 09-15-2011 #7Just Joined!
- Join Date
- May 2011
- Posts
- 44
Or, even better still:
Code:cd logs; \ find | perl -ne '`rm -rf $_`'
- 09-15-2011 #8
- 09-15-2011 #9Just Joined!
- Join Date
- May 2011
- Posts
- 44
I KNOW, it is sooooo LAME when someone responds to a QUESTION!?!?!?!?
Where in VA are you? I was born in Leesburg, VA. IDR the name of the hospital, I was very young.
- 09-15-2011 #10
I'm near Richmond. Leesburg is in the state of Northern Virginia.


Reply With Quote

