engineering:computer_science:linux:linux_cheatsheet

Linux Cheatsheet

Linux Cheatsheet

CommandDescriptionSyntaxExampleNotes
jobsList jobs running in the background
jobs
jobs
bgChanges a job to the background.
bg %n
bg %1<n> being the value from a job.
fgChanges a job to the foreground.
fg %n
fg %2<n> being the value from a job.


CommandDescriptionSyntax
tmux list-sessionsShows all live tmux sessions
tmux list-sessions
tmux attach
Attaches to the last active tmux session.

The session can be specified.
tmux attach
tmux attach-session -t <sessionNumber>
CTRL+B - DDettachs to the current tmux session
CTRL+B - D
CTRL+B - %Creates a New Horizontally Aligned Tab
CTRL+B - %
CTRL+B - “Creates a New Vertically Aligned Tab
CTRL+B - "
CTRL+B - ArrowsMoves to existent Tabs
CTRL+B - Arrows


CommandDescriptionSyntaxNotes

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
lsShows 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


CommandDescriptionSyntaxNotes
ip a
OR
ifconfig
Check your machine IPs
ip a
ifconfig
dmidecode –type memoryShows 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 savingIn 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


  • engineering/computer_science/linux/linux_cheatsheet.txt
  • Last modified: 2024/08/16 13:56
  • by carlossousa