Find the answer to your Linux question:
Results 1 to 8 of 8

Thread: I hate spaces

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    City of Salt

    I hate spaces

    I never used to care how files were named until I started using mostly terminal at work. Now I cannot stand it if a file name has any spaces or upper case characters don't bug me as much but those spaces are going to drive me nuts. If its not to hard I might make a script to remove spaces from file names and make an alias for it so I can do it with ease.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Have a look at detox
    A bit old. But still available, at least via the standard repository of a fedora 17.
    You must always face the curtain with a bow.

  3. #3
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Either at home or at work or down the pub
    I hear and feel the hate for spaces in file names. It turns out that detox is also available in the Ubuntu repositories.
    Should you be sitting wondering,
    Which Batman is the best,
    There's only one true answer my friend,
    It's Adam Bloody West!

    The Fifth Continent

  4. $spacer_open
  5. #4
    SuperMod (Back again) devils casper's Avatar
    Join Date
    Jun 2006
    Chandigarh, India
    I hate spaces too and I am using detox for a long time. Works really well and save a lot time.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #5
    Just Joined!
    Join Date
    Dec 2011
    yes ,you should make a script to rename your file ,and it's seem not difficult,but if you want to make a script auto rename each time ,it may be a little difficult, you can usd find . -name “*” get all your filename ,or "* *"pattern to match a file with at least one space , then there are sever ways to resolve this problem, you can choose one you like,
    1.use vi to make a list of command ,copy your find command output to vi,then use command :%s///g make the string "x1 x2" to "mv x1\ x2 x1x2" copy the list of the command to shell to execute or save as a script , go out of vi ,bash
    2.use shell script,
    3. use c language ,C can do anything you want ,but a little difficulter than shell scripter

  7. #6
    yeah, put me in the "hate names with spaces" camp. i've never heard of detox before, will be checking it out.

    here's a couple of things i've learned, which help me nowadays.

    1) when ditting around in the terminal, use a "\" character before the space in a file name (to "escape" it), then hit the [Tab] key, and bash will attempt to auto-complete the filename for you.

    2) when writing scripts to deal with filenames with spaces, you'll hear about changing the IFS (Input Field Separator) bash built-in variable. don't bother with that, just use command substitution in a loop. here's an example:
    # script to find files in the CWD and rename them, replacing spaces w/underscores
    while read file; do
      new=$(echo $file|sed -e 's| |_|g')
      mv -vi "$file" $new
    done < <(find . -mindepth 1 -maxdepth 1 -type f -name '* *')

  8. #7
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    The Keystone State
    Never heard of detox. I have to say I love this tool and it works great.
    Also available from the Sabayon repos too.


    The adventure of a life time.

    Linux User #296285
    Get Counted

  9. #8
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    City of Salt
    I installed detox at home and love it. I am unable to install at work so I wrote this script and it works great for replacing spaces with underscores and making every letter lower case.

    ls | while read -r FILE
    mv "$FILE" `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]' `
    It works great on a AIX system. I tried to use rename but it is not installed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts