Skip to content

Instantly share code, notes, and snippets.

@evgenyigumnov
Last active September 2, 2024 12:39
Show Gist options
  • Save evgenyigumnov/76c2e62f5d358bdda4f5 to your computer and use it in GitHub Desktop.
Save evgenyigumnov/76c2e62f5d358bdda4f5 to your computer and use it in GitHub Desktop.
useful linux commands (cheat sheet)

Check memory and disk usage

free -m
df -h

Proccess management

# print all proccesses like tree
ps axf
# find PID by name
ps ax|grep name
# kill by PID 123
kill -9 123
# kill all by name
killall name

Run process like daemon

nohup syncthing >syncthing.log 2>&1 &

Check perfomance problem

vmstat 10
iostat 10
top

Generate a new SSH key

ssh-keygen -t rsa -b 4096 -C "[email protected]"
cat ~/.ssh/id_rsa.pub

Check netstat

nestat -anp tcp

List which apps are using port 5000

lsof -i :5000

SSH port 8888 forward from localhost to server 8080

ssh -N -L 8888:localhost:8080 root@server 

Find the most recently changed file within a directory

find . -type f -exec ls -lt \{\} \+ | head

Check app's work problem by PID 123

strace -p 123

Create crypted disk by LUKS (dm-crypt)

# install dm-crypt
apt-get install cryptsetup
# create password for disk (say YES)
cryptsetup luksFormat /dev/sdb
# connect disk 
cryptsetup  luksOpen /dev/sdb sdb_crypt
# format disk
mkfs.ext4 -v -L DATA /dev/mapper/sdb_crypt
# mount disk to /data
mount /dev/mapper/sdb_crypt /data
# umount disk 
umount /data
# diskonnect disk
cryptsetup luksClose sdb_crypt
# connect and mount disk again
cryptsetup  luksOpen /dev/sdb sdb_crypt
mount /dev/mapper/sdb_crypt /data

Update packages on Ububtu

apt-get update        # Fetches the list of available updates
apt-get upgrade       # Strictly upgrades the current packages
apt-get dist-upgrade  # Installs updates (new ones)

Install java 8 on Ububtu

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer
apt-get install oracle-java8-set-default

Install Scala & Sbt

sudo apt-get remove scala-library scala
wget http://www.scala-lang.org/files/archive/scala-2.11.7.deb
sudo dpkg -i scala-2.11.7.deb
sudo apt-get update
sudo apt-get install scala

echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
sudo apt-get install sbt

Git clone by branch

git clone -b my-branch [email protected]:user/myproject.git

Swap file

sudo fallocate -l 512m /mnt/512MiB.swap
sudo chmod 600 /mnt/512MiB.swap
sudo mkswap /mnt/512MiB.swap
sudo swapon /mnt/512MiB.swap
mcedit /etc/fstab
# Add this line at the end of the file:
/mnt/512MiB.swap  none  swap  sw  0 0

Share current X11 session

x11vnc -display :0

Masquarding br1

root@opennebula:~# sudo iptables -t nat -A POSTROUTING -o br1 -j MASQUERADE
root@opennebula:~# sudo iptables -A FORWARD -i br1 -o br0 -m state --state RELATED,ESTABLISHED -j ACCEPT
root@opennebula:~# sudo iptables -A FORWARD -i br0 -o br1 -j ACCEPT

Calc folder size

du -shc /path-to-folders/*

Wine on ubuntu 14.04

sudo dpkg --add-architecture i386 
sudo add-apt-repository ppa:wine/wine-builds
sudo apt-get update
sudo apt-get install --install-recommends winehq-devel

Add ip alias

sudo ip addr add 192.168.190.3 brd + dev enx00e04c361945
sudo ip route add 192.168.190.0/24 dev enx00e04c361945 metric 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment