3.2.Navigating the file system

You can find your way around the Linux file system using the commands listed in Table3.1, “Commands for navigating the file system” and the symbols listed in Table3.2, “Common symbols from the file system”. Note that ls will not display hidden files or directories (whose names start with a period, such as .history) unless you include the -a option by typing ls -a at the prompt.

The command find is particularly powerful, although I think that the example below illustrates the most common use you'll have for it. To learn about all that find can do, consult man find.

Example3.1.Using cd

cd (which is equivalent to cd ~) will take you to your home directory.[13]

cd foo will change your current directory to the subdirectory foo, displaying an error if foo doesn't exist.


Example3.2.Using du

The command du -ch ~ will tell you how much disk space each directory in your home directory[13] takes up. Since this command can produce a lot of output to the screen, try viewing the result with less[27] by typing du –ch ~ | less (the |, or “pipe,” is typically found on the same key used for the backslash (\)).

If you just want to see the total disk space usage only, type du -ch ~ | tac | sed 1q at the prompt (the next-to-last character is the number 1, not the letter l).[28]


Example3.3.Using find

find . -name "*.java" will print the locations of all files whose names end with .java in the current directory and in all of its subdirectories.


Example3.4.Using ls

ls (which is equivalent to ls .) will list files and directories in the current directory.

ls -al .. will list all files and directories (including hidden ones) in the directory that is one directory above . (the current directory) using a long-listing format.


Table3.1.Commands for navigating the file system

CommandAction

cd [directory]

Change to home directory [to specified directory]

du -ch path

Estimate file space usage, human-readable format with a grand total[a]

file file_name

Determine file type[b]

find path expression

Search for files in a directory hierarchy[c]

ls [-a] [-l] [path]

List contents of current directory [of the provided path instead] [include hidden files] [long listing format][d]

pwd

Print name of current/working directory[e]

which program_name

Show the full path of a (shell) command[f]

[a] Linux manual page for du.

[b] Linux manual page for file.

[c] Linux manual page for find.

[d] Linux manual page for ls.

[e] Linux manual page for pwd.

[f] Linux manual page for which.


Table3.2.Common symbols from the file system

SymbolMeaning
~ (tilde)User's home directory[13]
. (period)Current (working) directory
.. (double period)One directory up from current directory
/ (front slash)Root (top-level) directory
* (asterisk)Wildcard (can be used in many commands)



[27] The command less is discussed in Section3.5, “Working with text streams”.[a] You can always check man less as well.

[28] For your enlightenment, tac is from the GNU Core Utilities (or coreutils; see SectionA.3.5, “The GNU Core Utilities (coreutils)”), and sed (short for stream editor) filters text, as explained on GNU's page for its version of sed. In the example above, sed prints only the first line of the output. You can learn more about tac and sed by reading their man or info pages (such as man tac or info sed).


Back to Guide main page