Results 1 to 15 of 15
  1. #1
    Join Date
    Nov 2005
    Location
    Palma de Mallorca, Spain
    Posts
    259

    [How To] Delete some specific files from all subdirectories

    Hello,

    Useful unix-command trick to quickly remove i.e. Thumbs.db files, WS_FTP.LOG files or *.fla files, recursively through directories.

    It could be a real pain on a huge directory tree ;-)

    Removing all *.fla files from /home/user/ and subdirectories...
    Code:
    # find /home/user/ -name \*.fla -ok rm {} \;
    Removing all WS_FTP.LOG files from /home/user and subdirectories...
    Code:
    # find /home/user -name WS_FTP.LOG -ok rm {} \;
    Removing all Thumbs.db files from /home/user and subdirectories...
    Code:
    find /home/user -name Thumbs.db -ok rm -f {} \;
    Regards,

    Juan

  2. #2
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    687
    Thank you for this VERY useful tutorial

  3. #3
    Join Date
    Nov 2005
    Location
    Palma de Mallorca, Spain
    Posts
    259
    Glad you find it useful. Don't know why can't edit the post...

    Anyway, just a note...

    Using "rm -f" will *not* ask for delete confirmation on every file, as shown on the third example.

  4. #4
    You can also use:

    find /home/user -name Thumbs.db | xargs rm

  5. #5
    Join Date
    Jun 2008
    Location
    India
    Posts
    129
    yes, you can use the command suggested b sysgallery. Normally most of the techs will use that way to avoid again for cofirmation. You should be always safe to list the files by using find and then add he rm part........

  6. #6
    Thank you, I found that extremely useful!

  7. #7
    Join Date
    Apr 2009
    Location
    New York City
    Posts
    4,364
    So these are files that aren't needed? If im correct.

  8. #8
    Join Date
    Oct 2009
    Location
    Bangalore
    Posts
    12
    Hi,

    Your command was ok but change ok to exec and it will fine if you want to do it non interactively (CAREFUL COMMAND IS NON ITERATIVE)

    For Removing all *.fla files from /home/user/ and sub directories..

    -->>Following command will be the perfect . this will delete the files non interactively.


    #find /home/user -name \*.fla -exec rm -rf {} \

    -->> Removing all WS_FTP.LOG files from /home/user and subdirectories...(non interactively.)

    #find /home -name WS_FTP.LOG -exec rm -f {} \;

    -->>Removing all Thumbs.db files from /home/user and subdirectories...

    find /home/user -name Thumbs.db -exec rm -f {} \;

  9. #9
    @8 that creates too many instances of exec, I prefer find /home/user -name Thumbs.db | xargs rm
    >>> Guard your data with VPS Backup Solutions
    >>> Resell Domains for profit

  10. #10
    this helped me delete some stupid log files

  11. #11
    Quote Originally Posted by diggo View Post
    @8 that creates too many instances of exec, I prefer find /home/user -name Thumbs.db | xargs rm
    You can even skip rm exec by using:

    Code:
    find /home/user -name Thumbs.db -delete
    Then just "unlink()" syscall is issued (less overhead than fork() + exec() for /bin/rm).
    Homer knows about his website downtime, what about you?
    site-uptime.net site uptime monitor

  12. #12
    ya thanks it really useful

  13. #13
    this is a useful tutorial i will recommend everyone to usethis if they need it!

  14. #14
    Join Date
    Dec 2011
    Location
    Germany
    Posts
    1,017
    Using xargs is more simple than exec in my opinion.

    Code:
    find /path/to/dir -name "*.html" | xargs rm -f
    To force delete every .html file in directory /path/to/dir and all following subdirectories.
    r00t-Services.net | DDoS Protected VMs & Remote DDoS Protection, Security, Optimization.
    In business since 2011 | Contact us: support[at]r00t-services.net
    Affordable & Powerful DDoS Protection Service in Europe and the USA! (⌐■_■)--︻╦╤─ - - - DDoS

  15. #15
    That's very useful tutorial. Thanks for this nice share.

Related Posts from theWHIR.com

Posting Permissions

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