Filesystem

    Contents

  1. Filesystem structure
  2. Listing files
  3. Directory
  4. Creating files
  5. Reading files
  6. Editing files
  7. Moving files

On Unix systems everything is a file.

Filesystem structure #

A path on a filesystem is noted as a string starting with a /

Example:

/home/user/Documents/mydocument.odt

~ indicates the home directory of the current user (also in $HOME) . the current directory .. the parent directory

Listing files #

ls [directory]: lists files inside a directory, often you use ls without any arguments to show the files in the current directory

  • -l shows list with permissions are file sizes.
  • -a shows 'hidden' files often also called dotfiles which are files starting with a dot '.'
  • -h shows file sizes in a humman readable format instead of the byte count

Tip: you can combine these flags like this:

ls -lah

Common directories #

ls /

  • / filesystem root
  • /bin program binaries
  • /dev devices
  • /etc configuration files
  • /home home directories of normal users
  • /mnt mountpoints
  • /opt optional software
  • /proc virtual filesystem to access kernel data
  • /root home directory of the root user
  • /run runtime data, often for daemons (lost after reboot)
  • /srv services data, often for web services
  • /sys virtual filesystem for system devices
  • /tmp temorary data (lost after reboot)
  • /usr Unix System Resources, files that generally not change
  • /var variable data, files that frequently change like log files

Directory #

cd Change Directory

pwd shows current directory

Creating files #

touch [filename] creates an empty file

Reading files #

cat head tail

Editing files #

You can edit files on the terminal using a terminal text editor like Vi(m) or Nano. Often vi,vim and/or nano are installed by default on many linux distros.

Moving files #

  • cp for copy
  • mv for move/rename
  • rm for remove