Results 1 to 9 of 9

Thread: Search then delete files

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Beans
    16

    Search then delete files

    Hiya,

    I have lubuntu 11.10 installed on Acer Revo 3610

    I have always used windows and have recently changed my media PC to Lubuntu. All I want to do at the moment is search for all teh files on my PC with a certain file extension and delete them, a trivial thing to do in Windows.
    So far Ive had to download & install Cat Fish and so now I can search for them and find them all, but once it has completed the search I cant do a select all and delete. I can't do anything useful with the files once I have found them at all.

    How do I delete all these files?

    TIA,

  2. #2
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    5,840
    Distro
    Xubuntu 15.04 Vivid Vervet

    Re: Search then delete files

    A command like this should do it (assuming you want to delete .xyz files):
    Code:
    find / -name '*.xyz' -delete
    You may need to use sudo in front of the command if you don't have rights to delete all the files yourself.
    Code:
    sudo find / -name '*.xyz' -delete

  3. #3
    Join Date
    Jan 2005
    Location
    South Africa
    Beans
    2,098
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Search then delete files

    Although I've not used above command myself, I think a warning to the latter command will be in place. Use it incorrectly and you might render your installation useless.

    The '/' indicates the root directory, so it might delete everything. If these files that you want to delete are in your home directory, navigate there first and replace '/' by '.'

    Or use ~username (which will expand to /home/username)

    Code:
    find ~wim -name *.jpg
    will just find and display them; add '-delete' if you want to delete them.

    Note:
    running it from the root directory will also wipe the (backup) data from external hard disks.
    Last edited by Wim Sturkenboom; October 8th, 2012 at 01:33 PM.
    If you don't make backups of your important data, your data is obviously not important to you.

  4. #4
    Join Date
    Aug 2012
    Beans
    16

    Re: Search then delete files

    Quote Originally Posted by Wim Sturkenboom View Post
    Although I've not used above command myself, I think a warning to the latter command will be in place. Use it incorrectly and you might render your installation useless.

    The '/' indicates the root directory, so it might delete everything. If these files that you want to delete are in your home directory, navigate there first and replace '/' by '.'

    Or use ~username (which will expand to /home/username)

    Code:
    find ~wim -name *.jpg
    will just find and display them; add '-delete' if you want to delete them.

    Note:
    running it from the root directory will also wipe the (backup) data from external hard disks.
    I was just about to ask how to specify a directory and you beat me to it, perfect, all done and dusted now!!

    As a slight aside, as an expert windows user for many years (its my job) switching to Linux is a lot harder than I thought. Things I take for granted in wondows are not always simple in Linux

  5. #5
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    5,840
    Distro
    Xubuntu 15.04 Vivid Vervet

    Re: Search then delete files

    The warnings about that command are right. When used with sudo, it could delete parts of your system.

    find ~wim -name *.jpg
    will not work. You must put quotes round the '*.jpg' or the command interpreter will expand it into a list of all jpeg file in the current directory before it even reaches the find program.

    Things are not generally harder in Linux, just different. Take my word for it, when a Linux user tries to use Windows occasionally he really wonders why Windows has to make simple things so hard.

  6. #6
    Join Date
    Aug 2012
    Beans
    16

    Re: Search then delete files

    Quote Originally Posted by The Cog View Post
    Things are not generally harder in Linux, just different. Take my word for it, when a Linux user tries to use Windows occasionally he really wonders why Windows has to make simple things so hard.
    Haha, yeah you're probably right. Out of interest what does a linux user find difficult in windows?

  7. #7
    Join Date
    Aug 2011
    Beans
    339
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Search then delete files

    Doing that broad a search/remove without intervention is dangerous. Any little mistake and you have wiped out your machine.

    First, since you are new to linux, learn to use the man command. This will help you use specific commands (once you know what they are, of course). In this case the two commands you would want are find and rm.

    man find will tell you how to use find which will locate the files you want.

    man rm will tell you how to remove them - you will want to use wildcards and recursion. However, BE CAREFUL. Also realize you will need correct permissions.

    Since you were not more specific, I will leave the details up to you. As I said, though, blindly and automatically removing broad batches of files is very dangerous. A minor mistype and you have wiped out everything.

  8. #8
    Join Date
    Aug 2012
    Beans
    16

    Re: Search then delete files

    Quote Originally Posted by agillator View Post
    Doing that broad a search/remove without intervention is dangerous. Any little mistake and you have wiped out your machine.
    Its OK, I'm not deleting system files or anything like that, it is some partially downloaded files with a specific file extension

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
  •