Friday, June 22, 2007

Find a directory by name in linux

Command to find a directory by name in linux
>find /share/backup/ -type d -name '.svn' -ls
-type d == directory
-name '.svn' == all directories named .svn
-ls == converts unusual characters to C style escape sequences

To delete the list of directories returned by the above command execute
>find /share/backup/ -type d -name '.svn' | xargs /bin/rm -dr
xargs builds and executes command lines from standard input
/bin/rm -dr == remove command with the directory and recursive flags

2 comments:

manga online said...

How to find directory name more than one ? Lets say i have 10 directories start with 1 to 10.

I just want to find files inside directory 1 to 5 or 5 to 7, etc.

Is that possible?

mark said...

try the following command that uses the regex switch:

find /share/backup/ -type d -regex "\d*.*"