Results 1 to 5 of 5

Thread: Command Line Help - mass removal of files

  1. #1
    Join Date
    Jun 2008
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Command Line Help - mass removal of files

    I have a 320GB external hard drive that has a whole bunch of files I want to get rid of. Now, I know I can find these files in the terminal, like so:

    Code:
    sudo find /media/MyBook/ -name *filename*
    Each file contains the same word somewhere in the file name, so that command works.

    What I want to know is, how can I use the results of that "find" command and feed it into the "rm" command to delete all those files for me?

    Any help would be greatly appreciated.

  2. #2
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Command Line Help - mass removal of files

    If all of the files are in the same directory, you shouldn't have to use the find command at all.

    Code:
    sudo rm -i /media/MyBook/*filename*

  3. #3
    Join Date
    Jun 2008
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Command Line Help - mass removal of files

    Quote Originally Posted by golanbatrac View Post
    If all of the files are in the same directory, you shouldn't have to use the find command at all.

    Code:
    sudo rm -i /media/MyBook/*filename*
    They're all on the drive, but are scattered throughout different directories. That's why I used the "Find" command in the first place; I wasn't sure where they all were (my external drive is a mess, and I'm trying to clean it up today hehe).

    I'm not very familiar with the intricacies of the CLI, though, so I wanted to make sure before I inadvertently trashed the whole drive.

    Will the command you gave work since the files are scattered? And what's that "-i" option?

    Thanks.

  4. #4
    Join Date
    Oct 2006
    Beans
    58,282

    Re: Command Line Help - mass removal of files

    The help page is man rm

    -i prompt before every removal

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Command Line Help - mass removal of files

    First make sure that the find command returns the files you want to delete.

    Make sure that the trash works on the partition:

    create a file
    Code:
    > /media/MyBook/test-trash
    move it to the trash:
    Code:
    trash /media/MyBook/test-trash
    list the trash:
    Code:
    list-trash
    if the file is in the trash move the unneeded files to the trash:
    Code:
    find /media/MyBook/ -type f -name *filename* -exec trash '{}' \;
    to empty the trash:
    Code:
    empty-trash
    to restore the files:
    Code:
    restore-trash

    NOTE: you may have to install trash-cli:
    Code:
    sudo apt-get install trash-cli
    Last edited by sisco311; October 24th, 2009 at 09:50 PM.

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
  •