Winter 2017 - January to April 2017 - Updated 2017-09-21 02:49 EDT
/root
, HOME, /home
, and currentIndexSome people become confused about these terms:
/
Index/
(slash), but since slashes separate pathname components, this is wrong. But you can’t write nothing (““) easily, so slash /
is often used to mean the nameless system ROOT directory./etc/passwd
contains two directories – the nameless ROOT directory to the left of the first slash, and the directory etc
to the left of the second slash./root
Indexroot
account on many systems.root
is placed when root
logs in to the system as a user.root
account HOME directory is not under the usual directory named /home
, where most other account HOME directories are.root
account a separate /root
directory. (Some systems may even use the system ROOT /
directory as the HOME directory of the root
account.)/home/idallen
cd
with no arguments.$HOME
. The variable name $HOME
is UPPER CASE.~/assignments
, ~/letters
, etc./home
e.g. /home/abcd0001
, /home/zyxw0002
, etc., but this is not always true, or may not be true for all accounts/home
Indexhome
./home
is NOT your HOME directory; it is usually a system directory named /home
./etc
, /bin
, and /usr
./home
is a system directory; you do not own it and you cannot change it/home
contains all the user HOME directories, e.g. /home/idallen
, /home/abcd0001
, etc.cd
command.cd
command to change the current directory of the shell, you may or may not have permissions to list, read, or modify the filenames in the “current directory”; it depends where your current directory is!.
(dot)Problem: "Put the date into a file out.txt in the current directory."
Solution: date >out.txt -or- date >./out.txt # unnecessary ./
Problem: "Put the date into a file out.txt in your HOME directory."
Solution: date >"$HOME"/out.txt -or- date >~/out.txt
Problem: "List the names (including hidden names) in the /home directory."
Solution: ls -a /home
Problem: "List the names (including hidden names) in the /home directory
and append the output to file foobar.txt in your HOME directory."
Solution: ls -a /home >>"$HOME"/foobar.txt -or- ls -a /home >>~/foobar.txt
Problem: "Move the item named foo.txt from your HOME directory to the
item named bar.txt in the current directory."
Solution: mv "$HOME"/foo.txt bar.txt -or- mv ~/foo.txt bar.txt
Problem: "Copy the file foo.txt from the current directory to your
HOME directory."
Solution1: cp foo.txt "$HOME"/foo.txt
Solution2: cp foo.txt "$HOME"/
Solution3: cp foo.txt "$HOME"
# In most shells, you can use a leading tilde ~ in place of a leading "$HOME":
Solution1: cp foo.txt ~/foo.txt
Solution2: cp foo.txt ~/
Solution3: cp foo.txt ~
Pathnames that resolve to begin with a slash (the ROOT directory) are absolute pathnames. Shell variables may contain slashes, and a shell tilde expansion usually expands to start with a slash:
/home # absolute path starts with slash
/bin/bash # absolute path starts with slash
/etc/passwd # absolute path starts with slash
/home/idallen/.bashrc # absolute path starts with slash
$HOME/.bashrc # absolute because $HOME expands to /home/userid
"$HOME"/.bashrc # absolute because "$HOME" expands to /home/userid
~/.bashrc # absolute because leading ~ is the same as $HOME
~idallen/.bashrc # absolute because leading ~user is HOME of user
Adding quotes around an absolute pathname simply turns off the shell’s GLOB and space processing for the name; the name is still absolute (because the shell strips the quotes away before using the name).
All other pathnames (that do not start with a slash after being expanded) are relative pathnames. Relative pathnames behave as if the current directory were added to the front of all relative pathnames. For example, if the current directory is /foo/bar
, then:
In /foo/bar relative pathname "file" is actually "/foo/bar/file"
In /foo/bar relative pathname "./file" is actually "/foo/bar/./file"
In /foo/bar relative pathname "." is actually "/foo/bar/."
In /foo/bar relative pathname ".." is actually "/foo/bar/.."
In /foo/bar relative pathname "dir/xxx" is actually "/foo/bar/dir/xxx"
...etc...