Useful Linux Commands

commands that i use often, but hard to remember lol

Back to guides…

Adding swap to Linux

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Replace 1G with whatever big you want.

BTRFS/CoW Filesystem

Swapfile can’t have CoW enabled, so we have to disable it

truncate -s 0 /swapfile
chattr +C /swapfile
fallocate -l 1G /swapfile
dd if=/dev/zero of=/swapfile bs=1MB count=1024
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap defaults 0 0" >> /etc/fstab

Replace 1G with whatever big you want. You will also need to replace 1024 in dd by the correct amount

GB Count
1G 1024
2G 2048
4G 4096
6G 6144
8G 8192

Find files containing string

grep -rnw './' -e '<string>'

Find files with certain extension

find . -type f -name "*.<ext>"

Quick Reverse SSH

Local Machine

ssh -R 9000:localhost:22 user@remote

Remote Machine

ssh -p 9000 user@localhost

Start screen with certain command

screen -d -m -S <name> "<command>"

Docker Compose Pull-Down-Up

docker compose pull && docker compose down && docker compose up -d

Opening archives

Tarballs

tar -xvf file.tar
tar -xzvf file.tar.gz
tar -xjvf file.tar.bz2

Zips

Needs unzip to be installed.

unzip file.zip -d <destination>

Run .jar with specified memory

java -Xmx1024M -Xms1024M -jar <jar> nogui