linux_cheatsheet
Last updated: 11-23-2025
Misc Cheatsheet
list top 20 directories with the largest size; change “/” for non-full system
du -x -h --max-depth=1 / | sort -hr | head -n 20
list details of folder
ls -l
delete folder and all internal files / folders
rm -rf <folder>
mount share on synology from another linux computer
sudo mount -t cifs //192.168.1.169/video /mnt/hankvault -o username=gpa,vers=2.0
-make sure to create the mount folder first
-may have to adjust version
-may have to add line into /etc/fstab, likely just once for each server added, not each share
enable automatic security updates on Ubuntu:
dpkg-reconfigure -plow unattended-upgrades
command line checksum of downloaded files:
echo "5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931 *ubuntu-22.04.2-live-server-amd64.iso" | shasum -a 256 --check
GIT
Submodules
How to properly remove submodule from git:
- Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule - Remove the submodule directory from the superproject’s .git/modules directory
rm -rf .git/modules/path/to/submodule - Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule
Pull git submodules (ie fill directories) once you have pulled a repo, remote to local
- in root directory,
git submodule init git submodule update
Update a submodule in Hugo Blog:
- (optional–only for forked submodules) update your main repo and push to github per usual
- in Hugo project, go into themes/
and run a git fetchandgit merge origin/main - return to root folder, commit and push per usual.
General
Force pull (overide) local git with remote repo
git fetch --allgit reset --hard origin/master(can also replace ‘master’ with another branch)
Rollback to a specific commit:
git reset --hard <old-commit-id> (first 6 alphanum)
git push -f <remote-name> <branch-name>
Start a fresh local repo with remote github repo:
- create folder structure, including the root folder of your directory
- cd into root
git initgit remote add origin git@github.com:user/repo.gitgit pull origin master
Create a new local branch from master, then push to new remote branch:
git checkout -b newbranch- make change, add file, etc
git add . ; git commit -m "first commit newbranch" ; git push origin newbranch
Check recent commits: git log
Escape list of commits: q
NixOS cleanup
This will delete all generations older than the last 5 (or whatever you assign)
-
cd nixconfig
-
sudo nix-env -p /nix/var/nix/profiles/system –delete-generations +5 && sudo nix-collect-garbage && sudo nixos-rebuild boot –flake .
-
sudo reboot now
write an iso to thumb drive
-
Plug in your USB drive.
-
Find the device name of the USB drive (not a partition like /dev/sdb1, but the whole device like /dev/sdb):
lsblk
or
sudo fdisk -l
- Look for the size of your thumb drive to identify it. For example, if it’s /dev/sdb, that’s what you’ll use.
-
Unmount any mounted partitions of the USB drive (replace sdb1, sdb2 as needed):
sudo umount /dev/sdb* -
Write to the iso drive with dd:
sudo dd if=/path/to/your.iso of=/dev/sdX bs=4M status=progress oflag=sync
- Replace /path/to/your.iso with the path to your ISO file.
- Replace /dev/sdX with your USB device (e.g., /dev/sdb). Do not include a partition number like sdb1.
- bs=4M makes the copy faster.
- status=progress shows progress.
- oflag=sync ensures data is written safely.
-
Wait until the command finishes — it may take several minutes depending on the ISO size and USB speed.
-
Flush any remaining writes:
sync -
Eject disk
tar-gzip
tar-gzip a file
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
untar-gzip a file
tar -xzvf archive.tar.gz
exclude files while tarring
tar --exclude='/exclude/this/dir' --exclude='/exclude/this/dir2' -czvf tarfile.tar.gz /dir-or-file/to/tar/
SCP
scp local file to remote server directory:
scp file.txt remote_username@10.10.0.2:/remote/directory
scp local DIRECTORY to remote server directory:
scp -r /local/directory remote_username@10.10.0.2:/remote/directory
scp remote file to local directory:
scp remote_username@10.10.0.2:/remote/file.txt /local/directory
scp remote directory to local directory:
scp -r remote_username@10.10.0.2:/remote/directory /local/directory
command line for finding public IP address
dig +short myip.opendns.com @resolver1.opendns.com
remove execute permission from all files in a directory
chmod -x *
remove execute permission from all files recursively in a directory
chmod -R -x <directory_name>
find the bluray drive sg number
sg_map -a
SSH
create ssh keys and push to server
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
Copy your id_rsa.pub to another machine’s ~/.ssh/authorized_keys/ for
passwordless ssh
ssh-copy-id remote_username@server_ip_address
Add a server’s fingerprint to your client’s known_hosts file:
ssh-keyscan -H 192.168.1.162 >> ~/.ssh/known_hosts
Change ownership of folder and all contents within:
sudo chown -R mary ./archive/
Change ownership of folder and all contents within with new user group:
sudo chown -R mary:mary ./archive/
Get IP address of domain:
dig A <domain>
Encrypt/Decrypt a file using SSL
openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -in file.test -out file.test.openssl
openssl enc -aes-256-cbc -d -md sha512 -pbkdf2 -iter 100000 -salt -in file.test.openssl -out file.test
Encrypt/Decrypt a file using GPG (supposedly a better option than SSL)
gpg --output encrypted.data --symmetric --cipher-algo AES256 --no-symkey-cache un_encrypted.data
gpg --output un_encrypted.data --decrypt encrypted.data
Verify File with GPG
- Download files
- Run GPG’s fetch-keys command to import the projects’ public key from keyserver (like Keybase.io), into your computers keychain:
gpg --fetch-keys https://keybase.io/<USER_ALIAS>/pgp_keys.asc - Verify the signature file (the file may end in .sig or .asc)
gpg --verify <FILE_NAME>.amd64.deb.asc - If you have a shasum file, check it with this:
shasum -a 256 --ignore-missing --check <FILE_NAME>.sha256.txt
Add a “lazygit” function to bash
- add the following to ~./bashrc
function lazygit() {
git add .
git commit -m “$1”
git push -u origin master
}
- then use command:
source ~/.bashrc
Networking
Temporary IP address, static:
ip a #look for interface
sudo ip addr flush dev <enpXXX>
sudo ip addr add 192.168.1.XX/24 dev enp3s0
sudo ip link set dev <enpXXX> up
sudo ip route add default via <routerIP>
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf #optional
Disk Resizing
https://askubuntu.com/questions/498709/how-can-i-resize-an-active-lvm-partition
ZFS
list all snapshots:
zfs list -t snapshot
Server Maintenance
- Clean the package cache
Removes cached
.debfiles:
sudo apt-get clean
- Remove old docker images, containers, volumes
sudo docker system prune -af --volumes
- Clean systemd journal logs
sudo journalctl --vacuum-size=100M
- Clear temp files
sudo rm -rf /tmp/*
Verify available space after clean-up
```bash
df -h /
f60b7c9 @ 2025-11-23