I have a directory having many sub directories, now I need to delete some files in all sub directories which are having specific extension (say eg.jpg). Please help me on this.
The way to find out how to use commands in unix is to use the "man" command. That will get you a manual page on any command that you want to use. It's always advised to check your man pages since the commands may be slightly different on different systems or may vary over time.
In this case, rm is the standard "remove" or delete command, so "man rm" to read how to use it.
Afaik, to delete all jpg files from subdirectories, the command would be rm - r *.jpg
Would be handy if that worked but it doesn't, rm -r will remove directories (and their contents recursively), but won't descend the directories looking for matches.
The command to descend a directory hierarchy in unix is "find", the full command you want is (there are multiple ways to do this with find, but this is general):
find . -name "*.jpg" -exec rm {} \;
which means:
"find ." - start at the current directory "." (you could put some other path here)
"-name "*.jpg"" - look for files named *.jpg
"-exec rm {} \;" - execute the command after exec up to the "\;", {} is substituted for the file name matched
See the man page for find for more info (find is one of the more complicated commands in unix).
Something you should be aware of, especially when using a potentially destructive command like rm: some of these commands can vary slightly or significantly, depending on the shell you are using (sh, bash, csh, etc.), and whether you are operating as root or logged in as a regular user. I am not sure how much rm varies from one implementation to the next, but I have noticed other commands with serious potential to do some serious damage to your file system if you don't understand how it behaves in your particular environment. ALWAYS use the man command when trying out a new command for the first time...
Good Answers: