Basic commands
Last edited
perheral io
All input and output from peripheral devices flows through main memory, also as a bunch of bits. A CPU is just an operator on memory; it reads its instructions and data from the memory and writes data back out to the memory.
groups
The primary purpose of groups is to allow a user to share file and process access to other members of a group.
cd
The current working directory is the directory that a process (such as the shell) is currently in.
Each process can independently set its own current working directory. Use cd to change the processes working directory (WORKDIR).
Shell globbing
The shell expands globs before the command ever runs, and only then. If you want the program to receive a literal , quote it: ‘’, “*”, or *. Otherwise the command sees filenames, not the pattern.
find
find dir -name file -print
# Globbing
# find accepts special pattern-matching characters such as *, but you must enclose them in single quotes ('*') to protect the special characters from the shell’s own globbing feature
# Escaped by shell
find . -name 2_*commands.md
zsh: no matches found: 2_*commands.md
# Guarded in a string literal, find uses it
find . -name 2_'*'commands.md
./content/linux/how_linux_works/2_basic_commands.mdShell and Environment variables
All processes on Unix systems have environment variable storage.
shell variable temporary variables containing the values of text strings, stored in the shell process, not passed to child processes.
envrionment variable same as shell vars, but the operating system passes all of your shell’s environment variables to programs that the shell runs.
STUFF=blah # shell variable
export STUFF # env var, passed into child processes of the shellJob control
Shells support job control, a way to send TSTP (similar to STOP) and CONT signals to programs. You can send a TSTP signal with ctrl-Z and then start the process again by entering fg
Symbolic Links
Symbolic links are simply filenames that point to other names. Their names and the paths to which they point don’t have to mean anything.
Don’t forget the -s option when creating a symbolic link.
Without it, ln creates a hard link, giving an additional real filename to a single file
ln -s target linkname
ln -s /var/log/auth.log linkname
# /var/log/auth.log doesn't have to point to a real path
# The shell passes your path to a syscall unchanged, the kernel resolves symlinksArchiving and Compressing
gzip
gzup (GNU Zip) is a standard Unix compression program.
gunzip file.gz # uncompress and remove suffix
gzip file # compressTar
archive: is a single file that contains:
- files
- directories
- metadata (paths, directory structure, permissions, ownership, timestamps)
Most OSs zip multiple files, however gzip does not pack multiple files. To compress mulitple files you must use an archive

Creating a tar
# Normal usage
tar cvf archive.tar file1 file2 ...
# c = create mode
# v = verbose
# f = file (create one, not stdout), next arg must be the output filename
# Another way, same result
tar c file1 file2 > archive.tarUnpacking a tar
tar xvf archive.tar
# x = eXtract mode
# Extra flags
t # table of contents (instead of unpacking)
p # perserve permissions (from the original packer)Compressed Archives (.tar.gz)
gunzip file.tar.gz
tar xvf file.tarThis operation is so common, there was a faster method written as this wasted disk space and kernel I/O time.
It’s better to compine into a single pipeline
zcat file.tar.gz | tar xvf -
# zcat - just runs: gunzip --stdout
# pipe it into tar which we define the fd as stdin '-'File Heirarchy
/usr/ directory
/local- admins can intall their own software/share- files that should work on other kinda of Unix machines. Historically, networks of machines would share this dir, so that programs could be shared due to space constraints.
dd
dd is really good at low level control of file transfer.
Its main use: ISO to USB.
Since it writes straight to the raw block device, the image’s boot sector and partition table land on the disk verbatim. Other tools copy files into a mounted filesystem, dd instead ignores the filesystem entirely, and can even pick exactly where it starts and ends (byte-level).
So if you want to copy/transfer disks byte for byte (partitions too, not just the data), use dd.
- ISO to USB -
dd if=kali-live.iso of=/dev/sdX bs=4M status=progress oflag=sync - Backup a disk -
dd if=/dev/sda of=disk.img bs=4M status=progress - Restore it -
dd if=disk.img of=/dev/sda bs=4M status=progress - Clone disk to disk -
dd if=/dev/sda of=/dev/sdb bs=4M status=progress - Save the MBR -
dd if=/dev/sda of=mbr.bak bs=512 count=1 - Wipe a disk -
dd if=/dev/zero of=/dev/sdX bs=4M status=progress - Byte window -
dd if=disk.img of=chunk.bin bs=1 skip=1024 count=512
| option | meaning |
|---|---|
if=file | input file. Default is stdin |
of=file | output file. Default is stdout |
bs=size | block size, reads and writes this many bytes at a time. b = 512, k = 1024 |
ibs=, obs= | input and output block sizes. Use bs if they’re the same, these if not |
count=num | total blocks to copy. Stops at a fixed point, use with skip to pull a small piece out of a large file or device |
skip=num | skip the first num blocks of the input, don’t copy them |