Results 1 to 9 of 9
  1. #1

    Removing files w/ an ext?

    Is there a certain way in shell to use the rm cmd to use the rm command to remove all files in a directory, recursively, with a certain extension?

    Thanks

  2. #2
    Join Date
    Aug 2002
    Location
    here
    Posts
    1,568
    Sure
    rm -rf *.ext
    Dave

  3. #3
    Hello,

    rm -rf <file name> will delete single file and if you want to delete multiple file at a time then

    rm -rf *.<extention for the file you want to delete>

    but this will delete all the file from for the same extention also it will be delete any improtant file if having a same extenstion

    also if you want to delete a file which in folder then use following command

    rm -rf <folder name> -R

    Thank you.

    Regards,

  4. #4
    Join Date
    Dec 2004
    Location
    New York City, NY, USA
    Posts
    735
    Since the OP mentioned "recursively," I think he wanted to find all such-named files in a directory tree. rm itself cannot do this; GNU find to the rescue:

    find . -iname '*.ext' -exec rm -f "{}" \;

  5. #5
    Join Date
    Aug 2002
    Location
    here
    Posts
    1,568
    Quote Originally Posted by tamasrepus
    Since the OP mentioned "recursively," I think he wanted to find all such-named files in a directory tree. rm itself cannot do this; GNU find to the rescue:

    find . -iname '*.ext' -exec rm -f "{}" \;
    I'm sorry, I must of misread the OPS post as I thought he had stated "a directory".
    My bad.....

    -Dave
    Dave

  6. #6
    Thankyou very much

  7. #7
    Join Date
    Aug 2001
    Posts
    5,068
    Quote Originally Posted by tamasrepus
    Since the OP mentioned "recursively," I think he wanted to find all such-named files in a directory tree. rm itself cannot do this; GNU find to the rescue:

    find . -iname '*.ext' -exec rm -f "{}" \;
    Code:
    Usage: rm [OPTION]... FILE...
    Remove (unlink) the FILE(s).
    
      -d, --directory       unlink FILE, even if it is a non-empty directory
                              (super-user only; this works only if your system
                               supports `unlink' for nonempty directories)
      -f, --force           ignore nonexistent files, never prompt
      -i, --interactive     prompt before any removal
          --no-preserve-root do not treat `/' specially (the default)
          --preserve-root   fail to operate recursively on `/'
      -r, -R, --recursive   remove the contents of directories recursively
      -v, --verbose         explain what is being done
          --help     display this help and exit
          --version  output version information and exit
    
    To remove a file whose name starts with a `-', for example `-foo',
    use one of these commands:
      rm -- -foo
    
      rm ./-foo
    
    Note that if you use rm to remove a file, it is usually possible to recover
    the contents of that file.  If you want more assurance that the contents are
    truly unrecoverable, consider using shred.
    
    Report bugs to <[email protected]>.
    Sitemeer.com - Is your site up?
    Multi-Location Service Availability Check ● yes, we do HTTPS & IDN!


  8. #8
    Join Date
    Dec 2006
    Location
    /dev/null
    Posts
    41
    To the best of my knowledge the -r switch in rm will only recursively remove a directory, not allow you to specify a pattern/extension and have that be removed from the directory(ies) recursively. The post by tamasrepus is likely the most efficient method of completing what the OP requested.
    Caro.Net: Support is everything
    Offering High Quality Dedicated Servers.

  9. #9
    Join Date
    Aug 2001
    Posts
    5,068
    Quote Originally Posted by CaroNet-Chris
    To the best of my knowledge the -r switch in rm will only recursively remove a directory, not allow you to specify a pattern/extension and have that be removed from the directory(ies) recursively.
    You are right, sorry for my wrong information.
    Sitemeer.com - Is your site up?
    Multi-Location Service Availability Check ● yes, we do HTTPS & IDN!


Posting Permissions

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