Recursive deletion of files (bash)
I’m familiar with how I would tackle this with PHP, however I’d like to get some more practice with bash scripting.
The task is to delete all files in a folder, which itself contains subfolders (with files). The files would typically be .pdf (or some variant: PDF, Pdf, pDf, ect), however there may occasionally be other file types including extensions unknown to me at this time.
Here’s what I have so far. It echoes the filename, but if I issue rm $i, the system returns file not found on each file.
for i in `ls -bRC1 /foo/temp_folders/* ` ; do echo $i ; rm $i ; done
How would I force the absolute path when issuing rm $i?
Per Zoredache… why not:
find /foo/temp_folders/ -type f -iname * -exec rm {} +
Edit: changed the trailing \; to + for performance as noted here
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
- SCP transfer only modified files
- How can I automate clearing and resetting a Linux user’s home directory to a default?
- Cron expression that runs every 5 minutes from 1:30 am – 6:00 am [duplicate]
- Understanding redundant power supplies
- Is there a way for administrators to disable users from installing Firefox extensions?
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





