Tuesday, July 17, 2007

TIP: find and delete files recursively

Quick and dirty way of deleting a file named "vertito" recursively starting from / .

Let's find those files named "vertito" and list them out first:

# find / -name vertito -exec ls -la {} \;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-rw-r--r-- 1 root root 0 2007-07-17 22:52 /home/ver/vertito
-rw-r--r-- 1 root root 0 2007-07-17 22:52 /home/folder2/vertito
-rw-r--r-- 1 root root 0 2007-07-17 22:52 /home/folder1/vertito
-rw-r--r-- 1 root root 0 2007-07-17 22:52 /home/folder3/vertito
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/ = find the file starting from this folder
vertito = the name of the file
-exec = and execute the next command when item is found
ls -la = list more file's info
\; = loops back for a command redo

You can use wildcard but be very careful with it as you might delete critical files using this.

Once confirmed for deletion, delete them recursively:

# find / -name vertito -exec rm -rf {} \;

Cheers

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy