Results 1 to 7 of 7

Thread: How do I find .zip files and then delete them

  1. #1
    Join Date
    Feb 2009
    Location
    UK
    Beans
    83
    Distro
    Ubuntu 12.04 Precise Pangolin

    How do I find .zip files and then delete them

    Hi I want to use the shell to find .zip files in my music directory and all sub directories and then delete only these files.

    The following will find the files I want to delete

    Code:
    find /home/me/Music/ -name *.zip -ls
    What is the next step to delete *only* these files.

    Would it be a good idea to move them to another directory before doing the final rm - how would I do this?

    Thanks

  2. #2
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How do I find .zip files and then delete them

    Just pipe it to xargs.
    Code:
    find /home/me/Music/ -name "*.zip" | xargs rm

  3. #3
    Join Date
    Mar 2011
    Beans
    370

    Re: How do I find .zip files and then delete them

    execute rm -r along with the command
    Code:
    find /home/me/Music/ -name *.zip -exec rm -r {} \;
    Last edited by ~Plue; April 13th, 2011 at 08:52 PM. Reason: typo

  4. #4
    Join Date
    Feb 2011
    Location
    San Francisco
    Beans
    18
    Distro
    Ubuntu Development Release

    Re: How do I find .zip files and then delete them

    If you want to be extra cautious, you could do :

    Code:
    find /home/me/Music/ -name *.zip -print0 | xargs -0 -I{} mv {} /home/me/Music/zip-files
    This will move them to a folder that you can double-check before deleting.
    Last edited by danjahner; April 13th, 2011 at 08:58 PM.

  5. #5
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How do I find .zip files and then delete them

    find /home/me/Music/ -name *.zip -exec rm -r {} \;
    Why would you use exec over xargs? xargs is more efficient in that when you use "-exec" with 'find', it starts a new process for each file that is found. This can be very expensive for a large number of files.

    And, no need to pass the recursive flag to rm, as find is recursive by default.

  6. #6
    Join Date
    Mar 2011
    Beans
    370

    Re: How do I find .zip files and then delete them

    Quote Originally Posted by rubylaser View Post
    Why would you use exec over xargs? xargs is more efficient in that when you use "-exec" with 'find', it starts a new process for each file that is found. This can be very expensive for a large number of files.

    And, no need to pass the recursive flag to rm, as find is recursive by default.
    i thought the difference would be minimal. thanx for letting me know that.

  7. #7
    Join Date
    Feb 2009
    Location
    UK
    Beans
    83
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How do I find .zip files and then delete them

    Thanks All

Tags for this Thread

Bookmarks

Posting Permissions

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