Wednesday, September 21, 2011

linux: delete long list of files

i have a folder that contains 192k log files which i want to delete. what's the problem? that's k in count, not k(b) in size. so whenever i do an
# rm -rf *
i get this message:
bash: /bin/rm: Argument list too long

how to delete them? here are two ways i usually take, which ever i remember first LOL

a. you can write a file containing the list of files you want to delete
# ls > del_list
append a delete command at the start of each line
:%s/^/rm -rf /g
then execute
# sh del_list

b. you can use the find command with action
# find . -maxdepth 1 -type f -exec rm {} \;

use whichever suits your mood ;D

additional note: use this to delete directories 10 days and older, with spaces in filename...
find . -type d -mtime +10 -exec rm -r "{}" \;

No comments:

Post a Comment

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...