When you request to open or save a file, your shell uses the current directory as the point of ref-
erence. Simply provide a filename when you save a file, and it is placed in the current directory.
Alternatively, you can identify a file by its relation to the current directory (relative path), or you
can ignore the current directory and identify a file by the full directory hierarchy that locates it
(absolute path). The structure and use of the file system is described in detail later in this chapter.
To find out what your current directory (the present working directory) is, type the
pwd
command:
$ pwd
/usr/bin
In this example, the current/working directory is
/usr/bin
. To find out the name of your home
directory, type the
echo
command, followed by the
$HOME
variable:
$ echo $HOME
/home/chris
Here, the home directory is
/home/chris
. To get back to your home directory, just type the
change directory (
cd
) command. (Although
cd
followed by a directory name changes the current
directory to the directory that you choose, simply typing cd with no directory name takes you to
your home directory.)
$ cd
Instead of typing $HOME, you can use the tilde (~) to refer to your home directory. So,
to see your home directory, you could simply type echo ~.
To list the contents of your home directory, either type the full path to your home directory, or use
the
ls
command without a directory name. Using the
-a
option to
ls
enables you to view the
hidden files (known as dot files because they start with that character) as well as all other files.
With the
-l
option, you can see a long, detailed list of information on each file. (You can put mul-
tiple single-letter options together after a single dash -- for example,
-la
.)
$ ls -la /home/chris
total 158
drwxrwxrwx 2 chris sales 4096 May 12 13:55 .
drwxr-xr-x 3 root root 4096 May 10 01:49 ..
-rw------- 1 chris sales 2204 May 18 21:30 .bash_history
-rw-r--r-- 1 chris sales 24 May 10 01:50 .bash_logout
-rw-r--r-- 1 chris sales 230 May 10 01:50 .bash_profile
-rw-r--r-- 1 chris sales 124 May 10 01:50 .bashrc
drw-r--r-- 1 chris sales 4096 May 10 01:50 .kde
-rw-rw-r-- 1 chris sales 149872 May 11 22:49 letter
^ ^ ^ ^ ^ ^ ^
col 1 col 2 col 3 col 4 col 5 col 6 col 7
Displaying a long list (
-l
option) of the contents of your home directory shows you more about
file sizes and directories. The
total
line shows the total amount of disk space used by the files in
NOTE
NOTE
42
Linux First Steps
Part I