Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line to delete matching files and directories recursively

How can I recursively delete all files & directories that match a certain pattern? e.g. remove all the ".svn" directories and the files they contain?

(Sadly DOS only)

like image 233
Rory Avatar asked Feb 10 '09 23:02

Rory


People also ask

What command will recursively delete a directory even if it has files in it?

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.

What command can be used to delete a directory recursively searching for files and other directories and deleting them?

To permanently remove a directory in Linux, use either rmdir or rm command: For empty directories, use rmdir [dirname] or rm -d [dirname] For non-empty directories, use rm -r [dirname]


1 Answers

Since you're looking for a DOS solution, last week's post was almost identical and the consensus was:

Command line tool to delete folder with a specified name recursively in Windows?

for /d /r . %d in (.svn) do @if exist "%d" rd /s/q "%d"

or

for /f "usebackq" %d in ("dir .svn /ad/b/s") do rd /s/q "%d"

Actually, SVN also gives you the option to export a working directory without the .svn/_svn directories.

Afterthoughts, three years later: I think the reason people end up needing to recursively delete the .svn/_svn folders is because they've directly copied their local working copy to a new location in order to do a folder comparison of their modified version compared to a clean export, i.e. after something goes awry with the modified local working copy. (At least that's why I've needed it. It's definitely easier/faster to just use 'svn export' when that's possible.)

like image 156
JMD Avatar answered Oct 05 '22 16:10

JMD