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 patcheshead
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 sectionSystem 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:
Mode | Used for | User | Group | Other |
---|---|---|---|---|
644 | files | rw | r | r |
600 | files | rw | - | - |
755 | directories, programs | rwx | rx | rx |
700 | directories, programs | rwx | - | - |
711 | directories | rwx | x | x |
-
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 calledloadable 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 mefiles.tar
- Compressing is reducing the size:
gzip file1
gives mefile1.gz
.gzip
is for zipping, andgunzip
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
, wherez
is forzcat
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:
- How Linux Works - Brian Ward