Results 1 to 5 of 5
I want to delete all files within a specific folder without actually deleting the folder, what is a good bash command for this?. I found this one but encountered some ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-19-2010 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 10
Bash command to remove all files within a specific folder
I want to delete all files within a specific folder without actually deleting the folder, what is a good bash command for this?. I found this one but encountered some errors even though I am executing it within the specific folder:
useratdebian:/home/user/folder# find . -type f -exec rm -rf {} \;
[1] 5052
useratdebian:/home/user/folder# find: missing argument to `-exec'
[1]+ Exit 1 find . -type f -exec rm -rf
The command as it appears is:
find . -type f -exec rm -rf {} \;
Any ideas of how to delete only the files contained within the folder called "folder" for example?
- 10-19-2010 #2
You copy&paste is wrong.
The command should be something like
Replace <FOLDER> with the actual pathCode:find <FOLDER> -type f
If that returns *only* the files you want to delete:
fyi:Code:find <FOLDER> -type f -delete
You can also work with -exec, the syntax would be
Code:find <FOLDER> -type f -exec rm -f {} \;Last edited by Irithori; 10-19-2010 at 09:14 AM.
You must always face the curtain with a bow.
- 10-19-2010 #3Just Joined!
- Join Date
- Oct 2009
- Posts
- 10
Thanks/Danke Irithori!
Your 'find' command worked great!
I have another question:
I have about 36 other folders where I have to basically enter the folder pathname everytime, can the command be modified to delete the files contained within these folders, the folders are in this format:
A-ABC-20101020-0001 (numbers are in format DDMMYY-NN)
A-ABC-20100408-0002
A-ABC-20100306-0003
etc.....................................
So the command as it is, is:
find A-ABC-DDMMYY-NN/folder/subfolder -type f -delete
Can the command above be adjusted to delete files for each of the 36 folders in just one command without doing it for each separate folder?
- 10-19-2010 #4
Use globbing:
Code:find /<PATH_TO_DATADIR>/A-ABC-* -type f
You must always face the curtain with a bow.
- 10-19-2010 #5Just Joined!
- Join Date
- Oct 2009
- Posts
- 10
Danke schoen Irithori.
The command works great, very effective for a simple command.
Now I will add a simple crontab job to execute it!


Reply With Quote
