This is an old revision of the document!
Linux Cheatsheet
Linux Cheatsheet
Jobs:
Command | Description | Syntax | Example | Notes |
---|---|---|---|---|
jobs | List jobs running in the background | jobs
| jobs | |
bg | Changes a job to the background. | bg %n | bg %1 | <n> being the value from a job. |
fg | Changes a job to the foreground. | fg %n | fg %2 | <n> being the value from a job. |
tmux | Opens a shell so the user can logout and the process keeps running in the background. | tmux | tmux →CTRL+B | tmux starts the shell, CTRL+B puts it in the background. This prevents that if a user logged in via SSH, a software (for example a game server) to terminate once the user logged out. |
tmux attach | Attachs the shell to the tmux shell in the background | tmux attach | tmux attach → D | Attachs the shell to the last used tmux. |
Disks and File Transfer:
Command | Description | Syntax | Notes |
---|---|---|---|
scp -r * remoteuser@remoteserver:/remote/folder/ | Copy all files and folders recursively from local to remote | scp -r * remoteuser@remoteserver:/remote/folder/ | |
du -sh /mnt/zebrabackup01/test | Shows folder size | du -sh /mnt/zebrabackup01/test | |
ls | Shows object cont in folder | ls | wc -l | |
du -smh * | sort -nr | head -15 | List Files by Size in Human Readable Way > Sort and Reverse it > Show Top 15 | du -smh * | sort -nr | head -15 |
Administration:
Command | Description | Syntax | Notes |
---|---|---|---|
ip a OR ifconfig | Check your machine IPs | ip a
ifconfig
| |
dmidecode –type memory | Shows the installed memory on your system | dmidecode --type memory
| |
find /var/log -type f -regex ".*\.gz$" find /var/log -type f -regex ".*\.[0-9]$" | Find Rotated and Compressed Logs | find /var/log -type f -regex ".*\.gz$" find /var/log -type f -regex ".*\.[0-9]$" | Add '-delete' to actually delete the files found. |
for CLEAN in $(find /var/log/ -type f) do cp /dev/null $CLEAN done | Empty all Log Files | for CLEAN in $(find /var/log/ -type f) do cp /dev/null $CLEAN done | Deleting the files can cause issues. Emptying them is safer and recommended. |
sudo !! | Re-run last command as root | nano /etc/example.log sudo !! | |
CTRL+x+e | Opens an editor, to create long / complex commands. Runs on saving | In Terminal: CTRL+x+e ls -l CTRL+X ENTER | |
fc | Opens the last command in an editor to make it easier to fix it. | fc | |
disown -a && exit | Exit Terminal but leave all processes running | disown -a && exit |