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?...
- 08-25-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 24
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?
- 08-25-2007 #2Linux 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)
- 08-25-2007 #3Just 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 ?
- 08-25-2007 #4
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 dirCan't tell an OS by it's GUI
- 08-27-2007 #5
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:
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.Code:echo ~ => /home/alex echo ~root => /root
DISTRO=Arch
Registered Linux User #388732
- 08-27-2007 #6Just Joined!
- Join Date
- Jun 2007
- Posts
- 15
- 08-27-2007 #7Linux 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.


Reply With Quote
