Find the answer to your Linux question:
Results 1 to 5 of 5
n00b note: I'm not sure that it makes any difference, but in this post when I say "shell" I mean the shell that is brought up by default in KDE's ...
  1. #1
    Just Joined! questio verum's Avatar
    Join Date
    Jun 2007
    Location
    Adrift in an ever-expanding universe, quietly contemplating the wondrous and the inevitable.
    Posts
    82

    The shell and spaces...

    n00b note: I'm not sure that it makes any difference, but in this post when I say "shell" I mean the shell that is brought up by default in KDE's Konsole. (I don't yet know if it's bash or what.)


    So... just exactly *as what* does the shell interpret spaces in a command?

    If they're interpreted as separators, then how is it that I'm encountering files with spaces in the filename? I've d/l'ed, for instance, a file from KDE-Look.org which ls displays as
    54701-Kore - Beryl Themes.tar.gz
    Being a dutiful little n00b, I've tried to clean up after myself. Here is the result of mv when removing the spaces from the filename
    user@user-desktop:~$ sudo mv /home/user/54701-Kore-BerylThemes.tar.gz /home/user/downloads/themes
    mv: cannot stat `/home/user/54701-Kore-BerylThemes.tar.gz': No such file or directory
    After checking and rechecking my syntax I tried leaving the spaces intact and was (to no surprise) still unable to move the file:
    user@user-desktop:~$ sudo mv /home/user/54701-Kore - Beryl Themes.tar.gz /home/user/downloads/themes
    mv: cannot stat `/home/user/54701-Kore': No such file or directory
    mv: cannot stat `-': No such file or directory
    mv: cannot stat `Beryl': No such file or directory
    mv: cannot stat `Themes.tar.gz': No such file or directory
    My only previous command line experience being limited mainly to DOS; I tried truncating, then substituting underscore for space. I was still unable to move the file.

    So tell me please... what gives? Is there some rule that I'm not aware of? What's up with those spaces being displayed? And what's preventing me from moving this file?
    Thx!

    qv

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Spaces seperate arguments to a command, such as a switch or a filename. If you need to use a space as part of a filename you can delimit it using a backslash. Just put a backslash before any space. You need to do this with some operators such as exclamation marks (!) and brackets.
    Code:
    54701-Kore\ -\ Beryl\ Themes.tar.gz

  3. #3
    Super Moderator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,144
    You can use the "dir" command to see exactly what bigtomrodney is talking about too.
    from a shell, type dir instead of ls
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

  4. #4
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    When dealing with filenames that have spaces in them you also can enclose them in either single or double quotes:

    '54701-Kore - Beryl Themes.tar.gz'
    or
    "54701-Kore - Beryl Themes.tar.gz"

    Also, if the filename has dollar signs ($) in them then you have to use single quotes:

    '54701-Kore $ Beryl Themes.tar.gz'

  5. #5
    Just Joined! questio verum's Avatar
    Join Date
    Jun 2007
    Location
    Adrift in an ever-expanding universe, quietly contemplating the wondrous and the inevitable.
    Posts
    82
    Amazing. Just... amazing! Thank you, guys.

    qv

Posting Permissions

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