Find the answer to your Linux question:
Results 1 to 7 of 7
So my shell tells me i am working in a "~" directory. However, i cannot figure out what it means? Is it an alias of some place in directory tree?...
  1. #1
    Amn
    Amn is offline
    Just Joined!
    Join Date
    Aug 2007
    Posts
    24

    Question What/where is the "~" directory?

    So my shell tells me i am working in a "~" directory. However, i cannot figure out what it means? Is it an alias of some place in directory tree?

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    in bash, "~" is short for your home directory: so if you say "cd ~"
    you'll be changed over to there. Handy
    the sun is new every day (heraclitus)

  3. #3
    Amn
    Amn is offline
    Just Joined!
    Join Date
    Aug 2007
    Posts
    24
    Thanks. I figure its an working alias for wherever home directory is, in case its not the default /home/<userid>, right ?

  4. #4
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    That's one way to put it.

    A command such as <cd ~other_user> brings you to the home dir of other_user (provided you have permision.

    By the way, a bare <cd> brings you to your own home dir
    Can't tell an OS by it's GUI

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Let's be a little clearer.

    ~user refers to that user's home directory. In addition to this being a much shorter way of accessing a home directory, you are correct in that it refers to the home directory wherever it exists, because they do not have to be under /home. The most obvious example is ~root, which would point to /root, but a user's home directory may be anywhere on the system.

    A simple '~' is an alias for your own home directory, which is very convenient. This allows me to give some advice in the form of (for instance, modifying their .xinitrc file): "Modify your ~/.xinitrc file", and I don't need to put in placeholders or generic names. Very nice.

    This also has a cool effect of letting you look up home directories easily, instead of having to search through /etc/passwd. I can just run:
    Code:
    echo ~ => /home/alex
    echo ~root => /root
    This is because Bash actually does the replacement here. When you say "cd ..", the program 'cd' receives a literal '..' and has to know what it means. But when you say "cd ~", Bash replaces the '~', so the program actually receives "/home/user". This means that ~ will work in EVERY program where paths are given as parameters.
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Just Joined!
    Join Date
    Jun 2007
    Posts
    15
    Quote Originally Posted by tpl View Post
    if you say "cd ~" you'll be changed over to there. Handy
    Yes, and "cd -" will bring you back to your previous directory.

  7. #7
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Speaking of which you can use pushd and popd to change to a completely different location and pop back to it. You can do this several times creating a 'deck'. Every time you run popd you go back one layer.

Posting Permissions

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