For Legend look here

Files in Linux/Unix

Unix systems have a generell principle, that everything is a file.
And therefore somewhere in the directory structure.
To apply this concept to several different things in a computer, unix has
several different file types:

  1. Normal files
  2. Directories
  3. Links
  4. Pipes
  5. Sockets
  6. Device Files (Block / Character files)
  7. Door File

Working with Files

In unix systems, a file does not necessarily need a Filetype Extension.

# Have a file to do something with:
curl http://metaphorpsum.com/paragraphs/10/5 > lorem_ipsum.txt
  1. Create files:

    1. Empty file:

      touch test
    2. With some content:

      echo This text will be the content > test
  2. Delete files:

    1. Single file:

      rm test
    2. Multiple files:

      rm test_file another_file some_other_file
    3. File that match a pattern:

      rm *_file
      # deletes all files with names that end with _file
  3. Output contents of file:

    1. All content at once:

      cat 
    2. Content in scrollable view:

      less 
    3. (Only if installed) Syntax highlighted scrollable:

      bat 
    4. Get only first 10 lines:

      head 
    5. Get only last 10 lines:

      tail 
    6. Get all newly written lines of a file:

      tail -f 
      # Hint: Usefull to have a continues look at **Log-Files**
  4. Information about content of files:

    1. Get type of file (works also with directories):
      file 
    2. Count words:
      wc -w 
    3. Count lines:
      wc -l 
    4. Count bytes:
      wc -c 

Next:

File Permissions