PDA

View Full Version : [ubuntu] tilde filename question


japhyr
June 28th, 2008, 02:23 PM
I saw this command in a post about configuring emacs:

xrdb -merge ~/.Xdefaults

I have read the tilde is a shortcut to the home directory. Is this the same as writing

xrdb -merge /home/myusername/.Xdefaults

Does the tilde ever have a different meaning at the beginning of a path? (I know it refers to backup files when it's at the end of a path/filename.)

pytheas22
June 28th, 2008, 02:29 PM
I'm pretty sure it's always just a shortcut for /home/username. It makes it convenient for giving instructions or writing bash scripts without knowing a user's account name.

hyper_ch
June 28th, 2008, 02:30 PM
the ~ means the homefolder of the current user... if you're logged in as root it will be /root instead of /home/user

wrtpeeps
June 28th, 2008, 02:30 PM
I saw this command in a post about configuring emacs:

xrdb -merge ~/.Xdefaults

I have read the tilde is a shortcut to the home directory. Is this the same as writing

xrdb -merge /home/myusername/.Xdefaults

Does the tilde ever have a different meaning at the beginning of a path? (I know it refers to backup files when it's at the end of a path/filename.)

I believe it is the same.

My terminal (not sure if its the terminal or ubuntu itself) will convert ~/ to /home/andy/ as soon as I type it.

japhyr
June 28th, 2008, 02:33 PM
Thanks everyone, especially the part about writing general scripts that apply to anyone's username.

sdennie
June 28th, 2008, 02:34 PM
You should also be aware that ~ is resolved by the shell to $HOME. So ~ isn't always valid for a path name. One common example of this is if you create a custom panel launcher, ~ will not resolve properly and you need to use the full path.

japhyr
June 28th, 2008, 11:50 PM
Actually, that was a question I had around this. What is $HOME? What is the difference between /home/username/directory, ~/username/directory, and $HOME/username/directory?

dwhitney67
June 28th, 2008, 11:54 PM
Actually, I think you meant $HOME/directory.

$HOME = /home/username

$HOME is an environment variable that is initialized when you log in. To see all environment variables, open a terminal and run this command:
$ env