Results 1 to 8 of 8

Thread: xargs and files names with spaces problem

  1. #1
    Join Date
    Feb 2006
    Location
    Cairo, Egypt
    Beans
    Hidden!
    Distro
    Kubuntu 10.10 Maverick Meerkat

    Question xargs and files names with spaces problem

    Hi,
    I'm trying to figure out a command to move or delete duplicate files from a directory using 'fdupes' and 'xargs'. Here's what I have so far
    Code:
    fdupes -f . | xargs mv -t ~/duplicates
    The problem with this command is that it can't handle file names with spaces in them. Reading xargs's man page there's a --delimiter option which is supposed to accepet /n but when I use it it still splits the file name:
    Code:
    fdupes -f . | xargs --delimiter=\n  mv -t ~/duplicates
    xargs also has -0 option with works with null sperators but fdupes only used \n as a seperator.
    Any ideas on how to do this?

    Thanks
    Last edited by abadr; February 20th, 2011 at 12:14 AM.
    A.B.

  2. #2
    Join Date
    Feb 2011
    Location
    not in Slovenia anymore
    Beans
    1,137
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: xargs and files names with spaces problem

    I don't know if this will help, but in Ubuntu, spaces are "escaped" with "\"

    example
    Code:
    env WINEPREFIX="/home/an/.wine" wine C:\\windows\\command\\start.exe /Unix /home/an/.wine/dosdevices/c:/users/an/Start\ Menu/Programs/Avery\ Dennison/DesignPro\ 5.lnk
    This is an actual link from WINE.
    Don't ask what your company can do for you.
    Ask what you can do for
    your company!

  3. #3
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: xargs and files names with spaces problem

    put the delimiter in quotes:
    Code:
    fdupes -f . | xargs --delimiter="\n"  mv -t ~/duplicates
    Last edited by MadCow108; February 14th, 2011 at 11:16 PM.

  4. #4
    Join Date
    May 2006
    Beans
    1,790

    Re: xargs and files names with spaces problem

    Quote Originally Posted by abadr View Post
    Hi,
    I'm trying to figure out a command to move or delete duplicate files from a directory using 'fdupes' and 'xargs'. Here's what I have so far
    Code:
    fdupes -f . | xargs mv -t ~/duplicates
    The problem with this command is that it can't handle file names with spaces in them. Reading xargs's man page there's a --delimiter option which is supposed to accepet /n but when I use it it still splits the file name:
    Code:
    fdupes -f . | xargs --delimiter=\n  mv -t ~/duplicates
    xargs also has -0 option with works with null sperators but fdupes only used \n as a seperator.
    Any ideas on how to do this?

    Thanks
    I don't know what 'fdupes' is, but 'xargs' has an option -0, which goes well together with the option -print0 of 'find'. Maybe 'fdupes' has something similar.

  5. #5
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: xargs and files names with spaces problem

    Assuming none of the filenames contain newlines, you can use a while read loop instead.

    Code:
    while IFS= read -r file; do 
      mv "$file" ~/duplicates
    done < <(fdupes -f .)
    See http://mywiki.wooledge.org/BashFAQ/001 for more.

  6. #6
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,701

    Re: xargs and files names with spaces problem

    Or this one?
    Code:
    IFS=$'\n'; for f in $(fdupes -f .) ; do mv -t ~/duplicates "$f" ; done

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

    Re: xargs and files names with spaces problem

    Quote Originally Posted by The Cog View Post
    Or this one?
    Code:
    IFS=$'\n'; for f in $(fdupes -f .) ; do mv -t ~/duplicates "$f" ; done
    Nope. Check out the link posted by geirha.

    If you use a for loop, you should disable pathname expansion:
    Code:
    oIFS=$IFS IFS=$'\n' ;set -o noglob; for file in $(fdubes -f ./); do echo "$file"; done; IFS=$oIFS ; set +o noglob

  8. #8
    Join Date
    Feb 2006
    Location
    Cairo, Egypt
    Beans
    Hidden!
    Distro
    Kubuntu 10.10 Maverick Meerkat

    Smile Re: xargs and files names with spaces problem

    Thank you all, the following worked by adding another "\" to the "\n":
    Code:
    fdupes -f . | xargs --delimiter=\\n  mv -t ~/duplicates
    A.B.

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
  •