Find the answer to your Linux question:
Results 1 to 6 of 6
I did a strange thing today. Code: mv myfile.zip mydir# Notice the hash symbol after my directory name. It hasn't created a directory, however I can view the contents of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    3

    Linux filenames


    I did a strange thing today.

    Code:
    mv myfile.zip mydir#
    Notice the hash symbol after my directory name. It hasn't created a directory, however I can view the contents of the zip file within the 'non directory' by using midnight commander.

    I cant find an explaination(googling) of what the hash does within a linux filename.

    Im using Bash. Can anyone help?

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    The hash symbol (or pound sign) has no special meaning in Linux filenames. It's just another character that can be used in filenames like the dash (-) or underscore (_).

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    3

    re:linux filenames

    when I try to cd to the directory I get an error...

    Code:
    bash: cd: mydir#: Not a directory
    I can only open the directory in midnight commander. Why does it have this affect if it has no special meaning within a filename?

  4. #4
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,864
    You basically just renamed myfile.zip to mydir# it never was or is a directory. It's still the same data, you just renamed it. If you want to change it back: mv mydir# myfile.zip
    If you can open it in a file browser, I think what you are seeing is the actual zip files.
    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.

    I'd rather be lost at the lake than found at home.

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    3

    re:linux filenames

    Lol!

    Now I see!! I spent a good hour googling that Now I can get on with what I was actually doing!

    Cheers!

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    To be more concrete, '#' might or might not have an special meaning.

    It has nothing to do with this issue, which was purely a confussion. But under some circumstances this character has a special meaning in bash.

    Quote Originally Posted by bash man page
    In a non-interactive shell, or an interactive shell in which the interac‐
    tive_comments option to the shopt builtin is enabled (see SHELL BUILTIN COM‐
    MANDS below), a word beginning with # causes that word and all remaining
    characters on that line to be ignored. An interactive shell without the
    interactive_comments option enabled does not allow comments. The interac‐
    tive_comments option is on by default in interactive shells.

Posting Permissions

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