Directories

In a hierarchical file system like Linux, the root directory is the highest directory in the hierarchy, and in Linux this is the / directory. The home directory is created for the user, and is typically located at /home/<username>. Commonly used shorthands for the home directory are ~ or $HOME. The home directory is usually the initial default working directory when you open a shell.

The absolute path or full path details the entire path through the directory structure to get to a file, starting at /. A relative path is the path from where you are now (your present working directory) to the file in question. An easy way to know if a path is absolute is to check if it contains the / character at the very beginning of the path.

The "." directory is a built-in shortcut for the current directory path and similarly the ".." directory is the directory above the current directory. These special shortcuts exist in every directory on the file system, except ".." does not exist in the root directory (/) because it is at the top. Files that begin with a dot "." (i.e. .bashrc) are called dot files and are hidden by default during navigation (in the sense that the ls command will not display them), since they are usually used for user preferences or system configuration.

Navigating

Here is a list of common commands used for navigating directories:

pwd command

pwdprint working directory. Prints the full path to the directory you are in, starting with the root directory. On Stampede2 you might see:

ls command
lslists the contents of a directory.
$ ls
test1.txt  test2.txt  test3.txt
  • Displays the files in the current directory or any directory specified with a path.
  • Use the wildcard * followed by a file extension to view all files of a specific type (i.e. ls *.c to display all C code files).
  • Use the -a option to display all files, including dot files.
  • There are many options for this command, so be sure to check the man pages. A Stampede2 example:
cd command

cdchange directory to the directory or path following the command. The following command will take you from your current directory to your home directory on most Linux systems:

$ cd ~ 
  • This example will take you up one directory, in this case to the root directory / , and then over to the var directory:
    $ cd ../var
  • With no arguments, cd will take you back to your home directory.
 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement