Operators Link to heading
|: pipes the standard output (stdout) of the left command into the standard input of the right one|&: pipes stdout and stderr in the standard input of the right command&&: executes the right command if the left one succeeded||: executes the right command if the left one failed
General Link to heading
Find out linux version
cat /etc/os-release
Find out current user and its groups:
whoami # shows current user
groups # shows groups of current user
groups <user> # shows groups user belongs to
gentent group # list all groups
getent group <group> # shows members of a group
# add user to an additional group
sudo usermod -aG <group> <user>
# -a: append, otherwise user will be removed from all not listed groups
# -G: takes a comma separated list of groups
Reboot / shutting down
reboot
Updating packages on Ubuntu
sudo apt-get update
sudo apt-get upgrade # upgrades all packages that can be upgraded without breaking other packages
Managing environment variables
# setting env variable
export https_proxy=http://<user>:@<proxy_address>:8080
# removing env variable
unset https_proxys
# showing env variables
printenv
Commands Link to heading
TODO: df # total used and available disk space
TODO: nohup
TODO: tail -n 200 some.log
- tail -f some.log
chmod: changing rights
3 numbers: _ _ _ -> permission for user, group, others
parameters:
permission symbol number read r 4 write w 6 execute x 1 permissions add up: 6 = 4 + 2: read and write access
chmod 400 private-key-file.pem # restricting file access (read) to yourself chmod +x some_script.py # make a file executable
du:
- get the size of a folder:
du -hs /path/to/directorys: gives only the summary of the folder, not for every folder separatelyh: human readable size in MiB or GiB instead of exact KiB
- get the size of a folder:
grep:
i: case-insensitive search e.g. to search environment variablesenv | grep -i proxy- use regex: e.g. select the lines that contain either “hook id:” or “duration:”:
grep -E '(hook id:|duration:)' pre-commit-logs.txt
ln: command used to create links between files
s: create a symbolic (soft) link rather than a hard link# creating a symlink ln -s <path to real file e.g. ~/dotfiles/ghostty/config> <where the symlink should be created e.g. ~/.config/ghostty/config> # checking a symlink ls -l <path to symlink>
rm:
rm * # delete all files (no directories) in the current working directory rm -rf * # delete all files + directories recursively
Custom function Link to heading
# in .zshrc
start_ec2() {
export AWS_DEFAULT_REGION=eu-central-1
export AWS_PROFILE=<AWS profile name>
aws ec2 start-instances --instance-ids <instance id>
}
# use the command
start_ec2