Re [Gllug] rm -R not working on Fedora

Benedikt Heinen gllug at ml.icemark.net
Fri Feb 11 21:06:22 UTC 2005


> rm -R *.php.bak
>
> Example 1
> All the '.php.bak' files within the current directory are removed but none
> within the subdirectories, despite having the same file permissions.
>
> Example 2
> I enter my home diretory and issue these commands:
>
> mkdir exdir
> cd exdir
> touch file1.txt
> mkdir subdir
> cd subdir
> touch file2.txt
> cd ..
> rm -R *.txt
>
> Result: file1.txt is removed but file2.txt remains

Just a second - rm -R will remove everything starting from the 
files/directories given downward.

If you want to remove selective files from a directory structure, you have 
to use a different approach - select the files with find and then proceed 
to remove them.

 	find * -type f -name  "*.php.bak" -exec rm {} \;

or

 	find * -type f -name  "*.php.bak" | xargs rm

Note, you shouldn't use the latter if you have files/directories with 
spaces in their names, because rm will take the individual parts 
seperately, e.g. if find would come across a file "My Files/info.php.bak", 
the xargs approach would result in error messages, since rm would try to 
remove "My" and "Files/info.php.bak", both of which don't exist...

If you do NOT have files/directories with spaces in their names, then the 
second version with xargs has the big advantage that rm will get called 
for multiple files, whereas the "-exec rm {}" would call rm individually 
once for each file - which will result in slower execution...

If you only have a few files, you should just use the -exec version. If 
you try and remove loads of files, try the xargs version if you can.







   Benedikt

--
 	It seems I think I am, therefore it seems I am, I think!
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list