A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

1066

Quoting Wikipedia: On Unix-like operating systems (including BSD, GNU/Linux and Mac OS X), tilde often indicates the current user's home directory: for example, if the current user's home directory is /home/bloggsj, then cd, cd ~, cd /home/bloggsj or cd $HOME are equivalent. This practice derives from the Lear-Siegler ADM-3A terminal in common use ...


157

The Home key was also used for the tilde character on old terminals. See here for more details.


67

Both Debian and Ubuntu ship an /etc/sudoers file that contains Defaults env_reset, which resets environment variables. However, the behavior of env_reset was changed from not touching $HOME to resetting it to the home of the target user. Ubuntu decided to patch their version of sudo to keep the previous behavior: https://bugs.launchpad.net/ubuntu/+source/...


47

What's important to understand is that ~ expansion is a feature of the shell (of some shells), it's not a magic character than means your home directory wherever it's used. It is expanded (by the shell, which is an application used to interpret command lines), like $var is expanded to its value under some conditions when used in a shell command line before ...


44

A complement to jasonwryan's great answer, addressing some of your issues: Your $XDG_CONFIG_HOME is not set to ~/. It simply isn't set. So applications that follow the XDG Specification use the default ~/.config The dirs inside /.config are not hidden because they don't have to. The whole point of using a ~/.config dir is to un-clutter the user's $HOME. ...


41

Few reasons I can think of: In corporate environments, you can have thousands of users. If so, cron would have to scan through every single user's directory every single minute to check for the crontab file (whether it has been created, deleted, or modified). By keeping them in a single location, it doesn't have to do this intensive scan. Home directories ...


36

Either quote it: rm -i '~' rm -i "~" rm -i \~ Or reference it by a path, instead of just a basename: rm -i ./~ rm -i /path/to/~ Note that, despite being a funny-looking single character name, this is conceptually no different than if you had created a file named SOME$PATH by doing touch 'SOME$PATH' And tried to remove it by doing: rm -i SOME$PATH (...


33

In the case of csh and tcsh, it records the value of the $HOME variable at the time the shell was started (in its $home variable as noted by @JdeBP). If you unset it before starting csh, you'll see something like: $ (unset HOME; csh -c cd) cd: No home directory. For bash (and most other Bourne-like shells), I see a different behaviour than yours. bash-4....


27

The tilde ~ is interpreted by your shell. Your shell will interpret ~ as a short form of $HOME. Try (echo ~; HOME=foo; echo ~). This should first print your real home directory and afterwards "foo", as you set $HOME to that. The default value of $HOME comes from you system configuration. Use getent passwd to list all known users and their home directories. ...


26

You may put default configurations in /etc/skel so that useradd(8) can copy files in /etc/skel whenever it creates new user's directory by '-m' option. Note that this is used only for the new-user. Existing user accounts are not affected.


26

If your're using bash, then the dirs builtin has the desired behavior: dirs +0 ~/some/random/folder (Note +0, not -0.) With zsh: dirs ~/some/random/folder To be exactly, we first need to clear the directory stack, else dirs would print all contents: dirs -c; dirs Or with zsh's print builtin: print -rD $PWD or print -P %~ (that one turns prompt ...


25

This change was introduced by BSD after 1985 (BSD 4.2 was still documenting /usr) and in or before 1988 (BSD 4.3/SunOS 4.1 hier(7) manual page already documents /home). It was quickly followed by Solaris 2.0 (which kind of merged System V and BSD) and was later adopted by most other Unix vendors. This is from the Solaris 2.0 useradd manual page: -D ...


25

In any version of Bash on any system, yes. ~ as a term on its own is defined to expand to: The value of $HOME so it will always be the same as whatever $HOME is to the current shell. There are several other tilde expansions, such as ~user for user's home directory, but a single unquoted ~ on its own will always expand to "$HOME". Note that the behaviour ...


24

Because those applications that place configuration files in $HOME are ignoring the XDG Base Directory Specification, notably: There is a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME... If $XDG_CONFIG_HOME is either not set or empty, a ...


24

The problem is the fact that files permissions are too open. Try setting the mode of authorized_keys to 600 and the .ssh directory to 700.


22

The .config directory is a newish development courtesy of XDG that seems, deservedly, to have won favour. Personally, I don't mind a dot directory of your own. A bunch of separate dot files (ala bash and various old school tools) in the toplevel of $HOME is a bit silly. Choosing a single dot file is a bad idea, because if in the future you realize maybe ...


18

That line in your .profile should be one of export PATH="$PATH:$HOME/Unix/homebrew/bin" PATH="$PATH:$HOME/Unix/homebrew/bin" PATH=$PATH:$HOME/Unix/homebrew/bin PATH=$PATH:~/Unix/homebrew/bin The ~ character is only expanded to your home directory when it's the first character of a word and it's unquoted. In what you wrote, the ~ is between double quotes ...


18

~ is an alias for $HOME provided by a number of shells, but $HOME is more universal. $HOME actually asks the shell to insert (substitute) the environmental variable HOME here. There are quite a number of different environmental variable that can be substituted, try running env for a list. Note that ~ is not always recognized when it's not at the beginning ...


18

You can use Bash variable substring replacement feature: $ pwd /home/vagrant/foo/bar $ echo ${PWD/#$HOME/'~'} ~/foo/bar


17

~foo means 'the home directory of user foo'. This isn't done by the kernel, it's interpreted by the shell. Whenever the shell sees ~foo as an argument, it transparently replaces it with the home directory of user foo and passes that in its place. So when you run cd ~tandu, the shell is actually running cd /home/tandu.


17

Yes, there is at least one major pitfall when considering git to manage a home directory that is not a concern with subversion. Git is both greedy and recursive by default. Subversion will naively ignore anything it doesn't know about and it stops processing folders either up or down from your checkout when it reaches one that it doesn't know about (or ...


17

There are ways to install rpms in a user directory using rpm, but I don't believe it is straight-forward. I don't believe there is a way with yum. My standard practice has become to compile from source to a local directory in my home $ mkdir ~/local $ mkdir ~/local/bin $ mkdir ~/local/lib $ mkdir ~/local/include I download source as I would to /usr/local ...


17

The ~ can be used for more than just that. Any command can profit from having a shortcut to the home folder. So it is not necessary if you want to cd into your home, but what about ~/.config? $ cd ~/.config Otherwise you'd have to write out the home path, use the $HOME var, or do two cds. Also for copying or moving files: $ cp ~/downloads/some-file some/...


17

short answer : you can't. long answer: HOME dir is set in /etc/passwd, 6th field. It is read upon loggin, your shell is started with this home dir. The proper way to change home dir for joe is : have joe log off. use usermod -d /new/home joe to change home dir for subsequent session. Once session is run, you must do two things: edit $HOME to change ...


17

Use sudo -s -H -u git-auto-deploy. sudo by itself does not change the value of HOME, but does so when -H is used. This is why you're getting that "Permission denied" error. The user can't access root's home directory (and shouldn't be able to either). The -s option makes sudo start whatever shell is configured as the login shell for the specified user (i.e....


16

Yes. The POSIX specification requires the OS to set a value for $HOME: HOME The system shall initialize this variable at the time of login to be a pathname of the user's home directory. See pwd.h. What about user nobody? # su - nobody No directory, logging in with HOME=/ $ echo $HOME / Even though nobody has no true home, HOME is set ...


16

You can remove all of them except the newest one. They are created by the startx script. If X does not shut down gracefully, that files is not removed and stays forever (see that bug). You can change the line in the /usr/bin/startx file, to a more handy way: Search for xserverauthfile= in the script and replace the line with: xserverauthfile=$XAUTHORITY


15

According to the Filesystem Hierarchy Standard (FHS): /home : User home directories (optional) /root : Home directory for the root user (optional) A typical non-root user's home directory would be /home/$USER. /root is also special in that (in many distros) /root is readable only to root (700), but a normal user's home directory has read access to others (...


15

You can just temporarily displace them. cd ~ mkdir .trash find . ! -name . -prune ! -type d -atime +365 -exec \ sh -c 'touch -a -- "$@" mv -- "$@" ~/.trash ' -- {} + That will find all files in your $HOME directory - without recursing into child directories - which have not been accessed for a year. It will update the access time for ...


14

If you are using PAM for authentication, which is probably the most likely. As root head into /etc/passwd. There you should see your username and path! Change it there and you are home free! EDIT - Sorry it just occurred to me that you maybe didn't want to change your home folder. In that case, simply add: cd /home To the bottom of your .bashrc file!


Only top voted, non community-wiki answers of a minimum length are eligible