Results 1 to 10 of 10

Thread: Delete all files listed in a text file

  1. #1
    Join Date
    Mar 2010
    Location
    USA
    Beans
    12
    Distro
    Ubuntu 10.04 Lucid Lynx

    Delete all files listed in a text file

    Through various Windows reinstalls and switches within Linux distros, I have a massive amount of duplication within my music archive (on the order of 7+ dupes of each file). Now, I found a lovely program called "fdupes" and was able to build a list of all the duplicate files, and I'm trying to use "xargs" to remove then. However, when I try and run the command "xargs -0 --arg-file="dupes.txt" rm" or "xargs -0 rm < "dupes.txt"" it give me the following error: "xargs: argument line too long".

    Any idea what this is, or how perhaps a different way of accomplishing the same thing? I'm very new to Linux so I'm still in the learning phase

    Thanks in advance!

    Dan

  2. #2
    Join Date
    Jun 2006
    Location
    Nux Jam
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

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

    Re: Delete all files listed in a text file

    Try something like:
    Code:
    for file in $(< dupes.txt); do gvfs-trash "$file"; done
    gvfs-trash moves the files in the Trash.

  4. #4
    Join Date
    Oct 2005
    Location
    Carterville, IL, USA
    Beans
    211
    Distro
    Ubuntu UNR

    Re: Delete all files listed in a text file

    If the text file contains the entire path of the files you want to delete or the files are in your current directory, then you can do it with a simple Bash script. It would be something like this:

    Code:
    #!/usr/bin/env bash
    
    echo "Beginning to remove files."
    echo
    
    for file in $(cat dupes.txt); do
       echo "Now removing the file $file..."
       rm "$file"
    done
    
    echo
    echo "Finished removing files."
    exit
    That will delete the files and print out what it is doing at each step.

  5. #5
    Join Date
    Jun 2006
    Location
    Nux Jam
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Delete all files listed in a text file

    Quote Originally Posted by sisco311 View Post
    Try something like:
    Code:
    for file in $(< dupes.txt); do gvfs-trash "$file"; done
    gvfs-trash moves the files in the Trash.
    as i've understood its only a dupes's list, not the files that are dupes. After finding and selecting, he need to move them then delete them.

  6. #6
    Join Date
    Mar 2010
    Location
    USA
    Beans
    12
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Delete all files listed in a text file

    Quote Originally Posted by sisco311 View Post
    Try something like:
    Code:
    for file in $(< dupes.txt); do gvfs-trash "$file"; done
    gvfs-trash moves the files in the Trash.
    My next question is what do I do about spaces in the file names? I'm guessing into the loop, I'd need a way to not treat white space as the delimiter, but to use line breaks.

    This is what I'm seeing:

    Now removing the file Music/Jimmie's...
    Now removing the file Chicken...
    Now removing the file Shack/Pushing...
    Now removing the file The...
    Now removing the file Salmanilla...
    Now removing the file Envelope/Folder.jpg...

    I know with some programs, I can use -0 or -n, but that doesn't seem to work in this context.

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

    Re: Delete all files listed in a text file

    Try:
    Code:
    while read file; do gvfs-trash "$file"; done < dupes.txt
    Last edited by sisco311; May 26th, 2010 at 06:38 PM.

  8. #8
    Join Date
    Mar 2010
    Location
    USA
    Beans
    12
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Delete all files listed in a text file

    Quote Originally Posted by sisco311 View Post
    Try:
    Code:
    while read file; do gvfs-trash "$file"; done < dupes.txt
    That worked! So the "read" operator reads the whole line, rather than pulling in each individual word?

  9. #9
    Join Date
    Oct 2005
    Location
    Carterville, IL, USA
    Beans
    211
    Distro
    Ubuntu UNR

    Re: Delete all files listed in a text file

    Quote Originally Posted by seraieis View Post
    That worked! So the "read" operator reads the whole line, rather than pulling in each individual word?
    Yeah, that's correct. That's probably the better way of doing this for this exact reason.

    - Derrick

  10. #10
    Join Date
    Nov 2010
    Beans
    1

    Re: Delete all files listed in a text file

    Oh i had the same problem but i will say ubuntu 10 is marvellous,i used a tool for searching and wiping such duplicate files which is a free version available at www.duplicatefilesdeleter.com

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
  •