Log in to your Red Hat Linux computer and open a GNOME Terminal session. In this case, you log in as the example user lidia. To find out where you are in the Linux file system, simply type pwd at the command prompt:
[lidia@cancun lidia]$pwd
You receive this response:
/home/lidia [lidia@cancun lidia]$
This response indicates that you’re logged in as lidia and are in the /home/ lidia directory. Unless your alter ego is out there, you should be logged in as yourself and be in the /home/yourself directory, where yourself is your login name.
The pwd command stands for print working directory. Your working directory is the default directory where Linux commands perform their actions; the working directory is where you are in the file system when you type a command. When you type the ls(1) command, for example, Linux shows you the files in your working directory. Any file actions on your part occur in your working directory unless you are root. For security reasons that we don’t go into here, the root user isn’t configured by default to be able to work on the current working directory. You can change this setting, but the root user generally must explicitly specify the working directory. For example, if you are root and are in the /etc directory and you want to indicate the hosts file, you must type cat ./hosts rather than just cat hosts.
Type this command:
ls -la
You see only the files in your working directory. If you want to specify a file that isn’t in your working directory, you have to specify the name of the directory that contains the file in addition to the name of the file. For example, this command lists the passwd file in the /etc directory:
ls -la /etc/passwd
If the file you want to read is in a subdirectory of the directory you’re in, you can reach the file by typing a relative filename. Relative filenames specify the location of files relative to where you are.
RememberIn addition to what we discuss earlier in this appendix about specifying directory paths, you need to know these three rules:
One dot (.) always stands for your current directory.
Two dots (..) specify the parent directory of the directory you’re in.
All directory paths that include (.) or (..) are relative directory paths.
You can see these files by using the -a option of the ls(1) command. Without the -a option, the ls(1) command doesn’t bother to list the . or .. files, or any filename beginning with a period. This statement may seem strange, but the creators of Unix thought that having some files that are normally hidden keeps the directory structure cleaner. Therefore, filenames that are always present (. and ..) and special-purpose files are hidden. The types of files that should be hidden are those a user normally doesn’t need to see in every listing of the directory structure (files used to tailor applications to the user’s preferences, for example).
Specify a pathname relative to where you are; for example:
[lidia@cancun lidia]$pwd /home/lidia [lidia@cancun lidia]$ ls -la ../../etc/passwd
The last line indicates that in order to find the passwd file, you move up two directory levels (../../) and then down to /etc.
If you want to see the login accounts on your system, you can issue this command from your home directory:
[lidia@cancun lidia]$ ls -la ..
This command lists the parent directory. Because the parent directory (/home) has all the login directories of the people on your system, this command shows the names of their login directories.
You have been looking at relative pathnames, which are relative to where you are in the file system. Filenames that are valid from anywhere in the file system are absolute filenames. These filenames always begin with the slash character (/), which signifies the root:
ls -la /etc/passwd
You occasionally (often?) want to change your working directory. Why? We’re glad you asked — because changing it enables you to work with shorter relative pathnames. To do so, you simply use the cd (for change directory) command.
To change from your working directory to the /usr directory, for example, type this command:
cd /usr
If you type cd by itself, without any directory name, you return to your home directory. Just knowing that you can easily get back to familiar territory is comforting. There’s no place like home.
You can also use cd with a relative specification; for example:
cd ..
If you’re in the directory /usr/bin and type the preceding command, Linux takes you to the parent directory named /usr:
[lidia@cancun lidia]$ cd /usr/bin [lidia@cancun bin]$ cd .. [lidia@cancun usr]$
TipHere are a couple of tricks: If you type cd ~, you go to your home directory (the tilde symbol (~) is synonymous with /home/username). If you type cd ~<username>, you can go to that user’s home directory. On very large systems, this command is useful because it eliminates the need for you to remember — and type — large directory specifications.
This list describes the shell redirection symbols:
> is known as redirect standard output. When you use it, you tell the computer “Capture the information that normally goes to the screen, create a file, and put the information in it.”
>> is known as append standard output. When you use this symbol, you tell the computer “Capture the information that would normally go to the screen and append the information to an existing file. If the file doesn’t exist, create it.”
< tells the computer, “Feed the information from the specified file to standard in (also known as standard input), acting as though the information is coming from the keyboard.”