Results 1 to 9 of 9

Thread: Search then delete files

  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,469
    Distro
    Xubuntu 14.04 Trusty Tahr

    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
    Aug 2011
    Beans
    322
    Distro
    Xubuntu 13.04 Raring Ringtail

    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.

  4. #4
    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.

  5. #5
    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

  6. #6
    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

  7. #7
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    5,469
    Distro
    Xubuntu 14.04 Trusty Tahr

    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.

  8. #8
    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?

  9. #9
    Join Date
    Aug 2011
    Beans
    322
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: Search then delete files

    Almost everything. In my opinion it is a matter of 'way of thinking'. I came to Linux from Windows and will never go back. In my opinion, which admittedly is years old, . . . .

    Windows is ok as long as you don't care about security and are willing to do things the way others (Bill Gates and Company) think you should do them. The thinking is similar to Ford's 'They can have any color car they want as long as it is black.' You also have to realize that you will most likely live with any bugs until the new edition comes out and you spend money on it. The structure is totally different and requires getting used to. You are forced to use 'drives' and working on a network is a pain since Windows was not originally designed for networks. Oh, and try to get Windows to recognize a non-windows file system . . . . Another difference is that Windows programs tend to try to do everything. The Linux user is used to programs being designed to do one thing and do it well, but the system is designed to let these programs be tied together to do the big things - far more flexible.

    Linux, on the other hand, gives the user much more control and much more power. For that reason, if for no other, it is often a little difficult to learn. But once you understand the way of thinking and how to get information I actually found it easier to use than Windows. One example. To Linux, everything is a file. You do not have to care where something physically is located unless you want to. You only need to know where in the file structure. Documentation in Linux tends to be far better, in my experience. If there is a bug in a program, it is probably going to be found, fixed, and available far sooner (and without cost). Since Linux was designed for networks, networking is relatively easy and almost transparent. Security is much tighter. To someone new the permission system gets in the way. But you learn how to deal with that very quickly and soon are relying on it and miss it when you have to deal with Windows file systems that don't know about permissions.

    My opinions. Your mileage will vary.

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
  •