Skip to main content
Engineering LibreTexts

04-E.12: Linux Directory Structure

  • Page ID
    26853
  • EXAM OBJECTIVES COVERED
    1.4 Given a scenario, manage storage in a Linux environment.

    Files

    In Linux, everything is a file. There are some special types of files, which we will talk about, but they are all files.

    The image to the right shows what the following table is referring to. The very first character on the output line is a dash and this will be the character that tells us what type of file we are dealing with. This image shows this first character is either "directory" or "file," but as we shall see there are several other file types.

    Shows linux permission and file type...very simple example. There are the owner permissions, the group permissions and the other permissions. Each set of permissions has a read bit in the binary 4 position, a write bit in the binary 2 position and an execute bit in the binary one position. You can add up the bits to determine a numerical value for the file.
    Figure \(\PageIndex{1}\): Breakdown of Linux Permissions. ("Linux Permissoins" by Bryant SonOpenSource.com is licensed under CC BY-SA 4.0)

    So, the following list outlines: 1) the character that will show up in the first column for the various file types 2) what it is called and 3) a brief description of that file type. We will cover this in much greater detail in a later section.

    -   Ordinary or Regular File - contain text, are executable programs or are data files used or created by the system
    -   Hard Link - an additional name for an existing file
    d   Directory - special files that store both other ordinary and special files in an organized manner
    c   Character special file - device files that communicates by sending and receiving single characters
    b   Block special file - device files that communicates by sending entire blocks of data
    l   Symbolic link - a reference that points to another file on the system
    p   Named pipe - a file that is used by two process to communicate with each other
    s   Socket - a file that connects the output of one process to the input of another process, thereby allowing the two processes to communicate

    Linux happens to provide a file command that basically helps you determine what type of file you are looking at. Here are some simple examples of the file command - see the man page for additional options.

    pbmac@pbmac-server $ file /home/pbmac
    /home/pbmac: directory
    
    pbmac@pbmac-server $ file /etc/passwd
    /etc/passwd: ASCII text
    
    pbmac@pbmac-server $ file vmlinuz
    vmlinuz: symbolic link to boot/vmlinuz-4.15.0-91-generic
    
    pbmac@pbmac-server $ file my-pipe 
    my-pipe: fifo (named pipe)

    File Naming Rules

    Each file name must be unique within the directory where it exists. File naming guidelines are as follows:

    • A file name can be up to 255 characters long and can contain letters, numbers, and underscores.
    • The operating system is case-sensitive, which means it distinguishes between uppercase and lowercase letters in file names. Therefore, FILEA, FiLea, and filea are three distinct file names, even if they reside in the same directory.
    • File names should be as descriptive and meaningful as possible.
    • Directories follow the same naming conventions as files.
    • Certain characters have special meaning to the operating system. Avoid using these characters when you are naming files. These characters include the following:
      \ " ' * ; - ? [ ] ( ) ~ ! $ { } &lt > # @ & | space tab newline
    • File names may NOT contain: a NULL character, or a / (forward slash).
    • A file may not be named . or .. as these are reserved names.
    • A file name is hidden from a normal directory listing if it begins with a dot (.). When the ls command is entered with the -a flag, the hidden files are listed along with regular files and directories.

    Adapted from:
    "A beginner's guide to Linux permissions " by Bryant Son, OpenSource.com is licensed under CC BY-SA 4.0

    • Was this article helpful?