Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

General Info

Things that I find neat or wish I'd known earlier

  • pwd -P to avoid symlinks from obscuring the true full path of the current working directory.
  • diff -u file1 file2 for unified diff - great for patches
  • head shows the first 10 lines of a file.
  • Shell variables are not passed to programs that the shell runs. However, Environment variables are. Example:
FOO=bar # shell variable
export FOO # makes it an environment variable
  • The order of adding directories to $PATH actually matters. The shell looks through the directories in order. This means that, adding your new directory to the beginning of the path makes the shell look in it first.
  • man -k <keyword> lets you search for a manpage by keyword.
  • manpages have sections. ping(8) <- 8 is from the section System commands and servers. I finally know what the numbers mean :)
  • Redirect standard output and error using command > file 2>&1
  • Useful ps flags:
ps u # more info
ps w # show full command, no truncation
ps x # all of my running processes
ps ax # all running processes, not just mine
  • kill -l shows mapping of signal numbers to names.
  • jobs command shows any suspended processes.
  • nohup allows processes to live when the terminal gets killed.
  • Useful absolute permission modes:
ModeUsed forUserGroupOther
644filesrwrr
600filesrw--
755directories, programsrwxrxrx
700directories, programsrwx--
711directoriesrwxxx
  • Note how the directories are being given execute permissions. This is because you can list the contents of the file, if it is readable, but you can only access a file in a directory, if the directory is executable.

  • The kernel is generally a binary file /vmlinuz or /boot/vmlinuz. The boot-loader loads this during system boot. However, /lib/modules contain modules called loadable kernel modules that the kernel loads and unloads on demand.

Disks and File Systems

Archiving vs Compressing

  • Archiving packs multiple files and directories into a single file: tar -cf files file1 file2 gives me files.tar
  • Compressing is reducing the size: gzip file1 gives me file1.gz. gzip is for zipping, and gunzip is for unzipping. It is not gun-zip, it is g-unzip. It all makes a lot of sense now. 🤦
  • These generally go hand in hand, which is how we end up with .tar.gz files or .tgz.
  • If you want to view the contents of a file before extracting them, tar -tvf <filename>.tar.
  • To decompress and unarchive a file we do: tar -xvfz <filename>.tar.gz, where z is for zcat which is pretty muchgunzip with a couple flags.

Linux directory hierarchy

Here's a blogpost from linuxhandbook explaining it. Highlights:

  • /etc is pronounced EHT-see, like the store and et cetera. 🤦
  • /tmp is temporary files that get wiped, but /var/tmp isn't.
  • /opt is for additional third-party software. Not widely used, but the general practice is to symlink the binary from /opt to /bin.
  • /usr/local/include has the header files used by the C compiler.

Devices

  • ls /dev lists all devices. The first character represents the type of device:
    • b: block
    • c: character
    • s: socket
    • p: pipe

dd-command

The dd command can do a looooot of things, including copying files, wiping disks, creating backups.

References:

  1. How Linux Works - Brian Ward