Skip to main content
Engineering LibreTexts

04-E.12.3: Linux Directory Structure - Paths

  • Page ID
    26852
  • Linux Paths

    Linux organizes files in a hierarchical tree, where relationships are thought of in teams of children and parent. Directories can contain other directories as well as regular files, which are the "leaves" of the tree. Any element of the tree can be referenced by a path name; an absolute path name starts with the character / (identifying the root directory, which contains all other directories and files), then every child directory that must be traversed to reach the element is listed, each separated by a / sign.

    A relative path name is one that doesn't start with / ; in that case, the directory tree is traversed starting from a given point (which changes depending on context) called the current directory. In every directory, there are two special directories called . and .. , which refer respectively to the directory itself, and to its parent directory.

    The fact that all files and directories have a common root means that, even if several different storage devices are present on the system, they are all seen as directories somewhere in the tree, once they are mounted to the desired place.

    An absolute path name, pointing to what is normally an executable file on a Linux system:

    /usr/bin/test

    This represents the file in the /usr/bin directory.

    An absolute path name, but pointing to a directory instead of a regular file:

    /usr/bin/

    Notice it ENDS with a /, thereby specifying the specified file is indeed a directory.

    A relative path name, which will point to /usr/bin/test only if the current directory is /usr/ :

    pbmac@pbmac-server $ pwd
    /usr
    pbmac@pbmac-server $ ls bin/test
    bin/test
    

    We are already sitting in the /usr directory, so an ls command can use a relative path to list the file test in the subdirectory bin.

    A relative path name, which will point to /usr/bin/test if the current directory is any directory in /usr/ , for instance /usr/share/ :

    pbmac@pbmac-server $ pwd
    /usr/local
    pbmac@pbmac-server $ ls ../bin/test
    ../bin/test
    

    We start with our current location in the /usr/local directory. We use the .. notation to tell our ls command to look up one directory, to /usr, and from there look in the bin subdirectory at the test command file.

    A path name using the special shortcut ~ , which refers to the current user's home directory:

    pbmac@pbmac-server $ cd ~/Desktop/

    No matter what your current directory is, this takes you to the Desktop directory in your home directory (because we used the tilde).

    Path names can contain almost any character, but some characters, such as space must be escaped in most software, usually by enclosing the name in quotation marks:

    "~/Examples/Experience ubuntu.ogg"

    or by employing the escape character \ in front of the space:

    ~/Examples/Experience\ ubuntu.ogg

    Command Review

    We have talked about several Linux commands:

    cd: The cd command will allow you to change directories. When you open a terminal you will be in your home directory. To move around the file system you will use cd in conjunction with absolute or relative path name.

    pwd: The pwd command will allow you to know in which directory you're located (pwd stands for "print working directory").

    ls: The ls command will show you ('list') the files in your current directory, or the directory specified with absolute/relative path names. With certain options, you can see sizes of files, when files were made, and permissions of files.

    Adapted from:
    "Linux Filesystem Tree Overview" by Edwin Khoo, Ubuntu Community is licensed under CC BY-SA 4.0
    "Using The Terminal" by Chris Perry, Ubuntu Community is licensed under CC BY-SA 4.0

    • Was this article helpful?