Find the answer to your Linux question:
Results 1 to 10 of 10
hello Linuxers. bash on redhat9, delete all .jpg files in this folder and subfolders, thus, recursively : rm -rf *.jpg what am I missing ??...
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    14

    rm -rf *.jpg. What is wrong?

    hello Linuxers.

    bash on redhat9,

    delete all .jpg files in this folder and subfolders, thus, recursively :

    rm -rf *.jpg

    what am I missing ??

  2. #2
    Linux Newbie mazer's Avatar
    Join Date
    Jul 2006
    Location
    Tucson, Arizona, USA
    Posts
    109
    Quote Originally Posted by Linus73 View Post
    hello Linuxers.

    bash on redhat9,

    delete all .jpg files in this folder and subfolders, thus, recursively :

    rm -rf *.jpg

    what am I missing ??
    -r option is used to delete a folder plus content. It does not mean that
    you delete all files specified in all subfolders.

    Mazer
    I was seduced by SUSE 5.1.
    Registered Linux User #451562

  3. #3
    Linux User Giles's Avatar
    Join Date
    May 2005
    Location
    Gloucestershire and Cambridge, UK
    Posts
    283
    Unfortunately, what
    Code:
    rm -rf *.jpg
    does is to look for any folders with a name ending in .jpg and recursively remove such folders. In order to do what you want, I think you'd need to write a script that deals with recursion manually - I'm afraid I haven't done that myself, so i cant give an example.

    Giles
    "Our greatest fear is not that we are powerless. Our greatest fear is Microsoft"
    Registered linux user #391027

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Giles is mostly correct. More accurately, your command looks for all directories and files in the current directory that end in '.jpg'. It deletes all of them. If it's a directory, it does the same to all of its subdirectories.

    The problem is that this only addresses directories that end in '.jpg'. Fortunately, the find command offers an easy way to fix this:
    Code:
    find . -iname '*.jpg' -type f -exec rm -f {} \;
    This command starts in the current directory, recursing through the entire subtree, looking for files only that end with '.jpg'. It will delete any such files.

    find - the find program
    . - search the subtree starting in the current directory
    -iname '*.jpg' - find all elements that match the shell pattern '*.jpg'. This should be done case-INsensitively
    -type f - only match files
    -exec rm -f {} \; - execute the command "rm -f {}" for each matched file, where '{}' is replaced with the name of the matched file.
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Just Joined!
    Join Date
    Mar 2007
    Posts
    14
    Quote Originally Posted by Giles View Post
    Unfortunately, what
    Code:
    rm -rf *.jpg
    does is to look for any folders with a name ending in .jpg and recursively remove such folders. In order to do what you want, I think you'd need to write a script that deals with recursion manually - I'm afraid I haven't done that myself, so i cant give an example.

    Giles
    Thank you.

    that is fine, I will copy-paste the rm -f *.jpg to each subfolder in bash.

  6. #6
    Linux Newbie mazer's Avatar
    Join Date
    Jul 2006
    Location
    Tucson, Arizona, USA
    Posts
    109
    Quote Originally Posted by Cabhan View Post
    Giles is mostly correct. More accurately, your command looks for all directories and files in the current directory that end in '.jpg'. It deletes all of them. If it's a directory, it does the same to all of its subdirectories.

    The problem is that this only addresses directories that end in '.jpg'. Fortunately, the find command offers an easy way to fix this:
    Code:
    find . -iname '*.jpg' -type f -exec rm -f {} \;
    This command starts in the current directory, recursing through the entire subtree, looking for files only that end with '.jpg'. It will delete any such files.

    find - the find program
    . - search the subtree starting in the current directory
    -iname '*.jpg' - find all elements that match the shell pattern '*.jpg'. This should be done case-INsensitively
    -type f - only match files
    -exec rm -f {} \; - execute the command "rm -f {}" for each matched file, where '{}' is replaced with the name of the matched file.
    I think if you just add an -delete it should do the same.
    Code:
    find /yourdirectory -iname '*.jpg' -delete
    Mazer
    I was seduced by SUSE 5.1.
    Registered Linux User #451562

  7. #7
    Just Joined!
    Join Date
    Mar 2007
    Posts
    14
    Quote Originally Posted by Linus73 View Post
    Thank you.

    that is fine, I will copy-paste the rm -f *.jpg to each subfolder in bash.
    thank you.

    solved it out with this.


    rm -f 11/*.jpg
    rm -f 12/*.jpg
    rm -f 13/*.jpg
    rm -f 14/*.jpg
    rm -f 15/*.jpg
    rm -f 16/*.jpg
    rm -f 17/*.jpg
    rm -f 18/*.jpg
    rm -f 19/*.jpg
    rm -f 20/*.jpg
    rm -f 22/*.jpg
    rm -f 23/*.jpg
    rm -f 24/*.jpg
    rm -f 25/*.jpg
    rm -f 26/*.jpg
    rm -f 27/*.jpg
    rm -f 28/*.jpg
    rm -f 29/*.jpg
    rm -f 30/*.jpg
    rm -f 31/*.jpg
    rm -f 32/*.jpg
    rm -f 33/*.jpg
    rm -f 34/*.jpg
    rm -f 35/*.jpg
    rm -f 36/*.jpg
    rm -f 37/*.jpg
    rm -f 39/*.jpg
    rm -f 4/*.jpg
    rm -f 40/*.jpg
    rm -f 41/*.jpg
    rm -f 42/*.jpg
    rm -f 43/*.jpg
    rm -f 44/*.jpg
    rm -f 45/*.jpg
    rm -f 46/*.jpg
    rm -f 47/*.jpg
    rm -f 5/*.jpg
    rm -f 54/*.jpg
    rm -f 55/*.jpg
    rm -f 56/*.jpg
    rm -f 57/*.jpg
    rm -f 58/*.jpg
    rm -f 59/*.jpg
    rm -f 6/*.jpg
    rm -f 60/*.jpg
    rm -f 61/*.jpg
    rm -f 62/*.jpg
    rm -f 63/*.jpg
    rm -f 64/*.jpg
    rm -f 65/*.jpg
    rm -f 66/*.jpg
    rm -f 67/*.jpg
    rm -f 68/*.jpg
    rm -f 69/*.jpg
    rm -f 7/*.jpg
    rm -f 70/*.jpg
    rm -f 71/*.jpg
    rm -f 8/*.jpg
    rm -f 9/*.jpg


    greetings to those looking for a solution and find this..... thank you
    Last edited by devils casper; 08-09-2007 at 03:31 AM. Reason: Posting links of relegious sites is Not allowed.

  8. #8
    Just Joined!
    Join Date
    Mar 2007
    Posts
    14
    Quote Originally Posted by Cabhan View Post
    Giles is mostly correct. More accurately, your command looks for all directories and files in the current directory that end in '.jpg'. It deletes all of them. If it's a directory, it does the same to all of its subdirectories.

    The problem is that this only addresses directories that end in '.jpg'. Fortunately, the find command offers an easy way to fix this:
    Code:
    find . -iname '*.jpg' -type f -exec rm -f {} \;
    This command starts in the current directory, recursing through the entire subtree, looking for files only that end with '.jpg'. It will delete any such files.

    find - the find program
    . - search the subtree starting in the current directory
    -iname '*.jpg' - find all elements that match the shell pattern '*.jpg'. This should be done case-INsensitively
    -type f - only match files
    -exec rm -f {} \; - execute the command "rm -f {}" for each matched file, where '{}' is replaced with the name of the matched file.



    sweeeeeeeeeet. thank you very much.

    find . -iname '*.jpg' -type f -exec rm -f {} \;

    works perfectly.

  9. #9
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by Linus73 View Post
    thank you.

    solved it out with this.


    rm -f 11/*.jpg
    <SNIP>
    rm -f 9/*.jpg

    greetings to those looking for a solution and find this..... thank you
    Blimey, if it was all jpgs in a single subdirectory then rm -f */*.jpg would do. Unless you like typing, of course!

  10. #10
    Just Joined!
    Join Date
    Mar 2007
    Posts
    14
    Quote Originally Posted by scm View Post
    Blimey, if it was all jpgs in a single subdirectory then rm -f */*.jpg would do. Unless you like typing, of course!

    Blimey.....

    Definitions of Blimey on the Web:

    * (Brit.) 19th-century corruption of the oath, 'God blind me'.
    JoyZine - Australia Decoded: A Dictionary of Australian English: B-5

    * Minced oaths are corrupted forms of (usually religion-related) swear words that originally arose in English culture sometime before the Victorian Age, as part of the cultural impact of Puritanism after the Protestant Reformation. The censorship caused people to develop a wide variety of minced oaths to avoid swearing on holy names. They were used for swearing and other types of interjections. With time they came to have a mildly comedic effect. ...
    en.wikipedia.org/wiki/Blimey



    OK, now back to work

    no, it was the same type of file (.jpg) in tens of subdirectories....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...