Find the answer to your Linux question:
Results 1 to 8 of 8
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187

    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
    Location
    Munich
    Posts
    3,439
    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
    Location
    Either at home or at work or down the pub
    Posts
    3,649
    I hear and feel the hate for spaces in file names. It turns out that detox is also available in the Ubuntu repositories.
    "I used to be with it, then they changed what it was.
    Now what was it isn't it, and what is it is weird and scary to me.
    It'll happen to you too."

    Grandpa Simpson



    The Fifth Continent

  4. $spacer_open
    $spacer_close
  5. #4
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    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
    Location
    China
    Posts
    1
    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 a.sh , go out of vi ,bash a.sh
    2.use shell script,
    3. use c language ,C can do anything you want ,but a little difficulter than shell scripter

  7. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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:
    Code:
    #!/bin/bash
    # 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
    Location
    The Keystone State
    Posts
    2,677
    Never heard of detox. I have to say I love this tool and it works great.
    Also available from the Sabayon repos too.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  9. #8
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    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.

    Code:
    #!/bin/bash
    ls | while read -r FILE
    do
    mv "$FILE" `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]' `
    done
    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
  •