For Legend look here

Directory Structure

In Unix systems the complete directory structure begins at

/

the root directory.
_(Hint: Do not confuse with the MARKDOWN_HASH887904812217cca9bc2b9adb875daf42MARKDOWNHASH that is the Home-Directory of the
root user. And it is often also called the root-directory)

Special Directories

Also Unix system have two additional special directory entries:

  1. Pseudo directory that is the same as the current directory
    .
  2. Pseudo directory that is the same as the parent directory
    ..

Files

In Unix files do not necessarily need a filetype extension like .exe or
.jpg. The type of a file is determined by accessing the header of a file.

Unix also has a special meaning of files that start with a ., these files are
considered "hidden".

Directory and File Addressing (Path)

And there are two ways to specify a path to a destination directory:

  1. Absolute Path

    Absolute Paths start from always from the root of the directory structure.

    Example:

    /home/zasher
    # Is the path to the **Home-Directory** of user zasher
  2. Relative Path

    A relative path is always in relation to the current directory we are working
    in

    Example:

    # Current Working Directory is 
    /home
    # Then:
    zasher
    # is the path to the **Home-Directory** of user zasher

Common Locations on Linux

Most Distributions of Linux have a common directory structure,

  1. Personal Directories of users are located under:

    /home

    with additional seperation by user name.

  2. Executable programs are located under several locations:

    # Normal programs
    /bin
    /usr/bin
    /usr/local/bin
    # Super-User related programs
    /sbin 
    /usr/sbin
    /usr/local/sbin
  3. System-wide Configurations are located under:

    /etc
  4. System Log Files (Events happening in the System or Applications):

    /var/log

Locations in Home Directory

Some directories in the home directory of users have also special purposes.
They are defined by the Freedesktop XDG Base Directory
Specification

There should be special environment variables that lead to the corresponding
location.

Unfortunately not all applications, shell and distributions honor this.

  1. User Configurations should reside in:

    # Location
    /home//.config
    
    # Variable
    $XDG_CONFIG_HOME

    unfortunately not all applications honor this.

  2. Application-User specific files:

    # Location
    /home//.local/share
    
    # Variable
    $XDG_DATA_HOME
  3. User Caching Directory

    # Location
    /home//.cache
    
    # Variable
    $XDG_CACHE_HOME

Working with directories

We assume that the user is in /home/zasher if not stated otherwise.

  1. Finding the current directory:

    pwd
    # /home/zasher
  2. List all of files

    1. In current directory:

      ls
    2. In current directory but with more informations:

      ls -l
    3. In a different directory:

      ls 
  3. Change the current directory to an other directory

    1. To a direct subdirectory of

      pwd: cd 

      Example:

      pwd
      # /home/zasher
      cd projects
      pwd
      # /home/zasher/projects
    2. To a subdirectory of a subdirectory of pwd:

      cd /

      Example:

      pwd
      # /home/zasher/
      cd projects/code
      pwd
      # /home/zasher/projects/code
    3. To a directory in absolute path:

      cd /

      Example:

      pwd
      # /home/zasher/projects
      cd /home/zasher
      pwd
      # /home/zasher
    4. Change to parent directory:

      cd ..

      Example:

      pwd
      # /home/zasher/projects
      cd ..
      pwd
      # /home/zasher
    5. Change to parent of parent directory:

      cd ../..

      Example:

      pwd
      # /home/zasher/projects/code
      cd ../..
      pwd
      # /home/zasher
  4. Create Directory

    1. Single subdirectory:

      mkdir 

      Example:

      pwd
      # /home/zasher
      mkdir testdrive
      ls
      # list contents with testdrive in the list
    2. Subdirectory structure:

      mkdir -p /

      Here the -p is maybe needed to tell the command to create parent
      directory of <SUBDIRECTORY> if it does not exist.

      Example:

      
      pwd
      # /home/zasher
      mkdir -p testdrive/some_folder
      ls -R testdrive
      # should list the direcory structure under testdrive
  5. Delete a Directory
    In general, unix system do not have a trashcan, so all delete operations are
    inherently permanent.

    1. Empty subdirectory of pwd:

      rm -r 
    2. Non-Empty subdirectory of pwd:

      # ⚠⚠⚠ Be Aware, this will also delete all contents of  without question.
      rm -rf 
    3. Delete contents of a directory:

      # ⚠⚠⚠ Be Aware, this will delete all contents of  without question.
      rm -rf /*

Next:

Working with files