Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove all of a file type from a directory and its children

I was under impression that

rm -r *.xml 

would remove all file from parent and child however:

*.xml: No such file or directory 
like image 802
Will Avatar asked Aug 17 '11 16:08

Will


People also ask

How do I delete all files from a certain type?

You can do this using the Windows GUI. Enter "*. wlx" in the search box in explorer. Then after the files have been found, select them all (CTRL-A) and then delete using the delete key or context menu.

How do you remove all recursive files from a directory?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do I delete all files from a specific type in Linux?

Using rm Command To remove a file with a particular extension, use the command 'rm'. This command is very easy to use, and its syntax is something like this. In the appropriate command, 'filename1', 'filename2', etc., refer to the names, plus their full paths.

Is there a way to erase all files in the current directory?

The procedure to remove all files from a directory: Open the terminal application. To delete everything in a directory run: rm /path/to/dir/* To remove all sub-directories and files: rm -r /path/to/dir/*


1 Answers

The man page of rm says:

 -r, -R, --recursive           remove directories and their contents recursively 

This means the flag -r is expecting a directory. But *.xml is not a directory.

If you want to remove the all .xml files from current directory recursively below is the command:

find . -name "*.xml" -type f|xargs rm -f 
like image 144
Vijay Avatar answered Sep 19 '22 21:09

Vijay