Linux Command

Set custom display resolution

cvt 1680 1050 60
cvt 1680 1050 60

1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
Modeline "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync

xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
xrandr --addmode <display_name> 1680x1050_60.00
xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
xrandr --addmode <display_name> 1680x1050_60.00
#Get display_name
xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/"
#Get display_name
xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/"

Create a file to run at startup

#!/bin/sh
xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
xrandr --addmode <display_name> 1680x1050_60.00
#!/bin/sh
xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
xrandr --addmode <display_name> 1680x1050_60.00

Wifi

iwconfig #show wireless card information
iwlist <wireless-card-id> scan #Show available networks
iwlist <wireless-card-id> scan | grep ESSID #Only show wifi ID
nmcli d wifi connect <wifi-id> password <wifi-password> #Connect to wifi
nmcli connection delete id <wifi-id> #Forget a wifi
nmcli c #Show a list of saved connections
nmcli c down id <SavedWiFiConn> #disconnect
nmcli c up id <SavedWiFiConn> #connect
iwconfig #show wireless card information
iwlist <wireless-card-id> scan #Show available networks
iwlist <wireless-card-id> scan | grep ESSID #Only show wifi ID
nmcli d wifi connect <wifi-id> password <wifi-password> #Connect to wifi
nmcli connection delete id <wifi-id> #Forget a wifi
nmcli c #Show a list of saved connections
nmcli c down id <SavedWiFiConn> #disconnect
nmcli c up id <SavedWiFiConn> #connect

Test internet speed

wget --output-document=/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip
wget --output-document=/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip

Set IP address

sudo ip a add 192.168.10.1/255.255.255.0 dev eno1
sudo ip a add 192.168.10.1/255.255.255.0 dev eno1

Check disk I/O status

dstat -D sdX
dstat -D sdX

Mount: Structure needs cleaning

sudo fsck.ext4 /dev/sda1
sudo fsck.ext4 /dev/sda1

Generate SSH key

ssh-keygen -t rsa
ssh-copy-id username@192.168.10.1 -p 1234
ssh-keygen -t rsa
ssh-copy-id username@192.168.10.1 -p 1234

Mount remote file system

sudo apt-get install sshfs
sudo sshfs -o port=1234,allow_other,default_permissions wu@192.168.10.2:/ /media/lrg/EXTRA/
sudo apt-get install sshfs
sudo sshfs -o port=1234,allow_other,default_permissions wu@192.168.10.2:/ /media/lrg/EXTRA/

Copy local files to SSH server

rsync -a -e 'ssh -p 1234' --info=progress2 /localDir/* wu@192.168.10.2:/media/remoteDir/
rsync -a -e 'ssh -p 1234' --info=progress2 /localDir/* wu@192.168.10.2:/media/remoteDir/

Tar

tar cvf FILENAME.tar DIRECTORY/ #Tar a folder (without compression)
tar -cvjf FILENAME.tar.bz2 DIRECTORY/* #Compress all files in DIRECTORY into FILENAME.tar.bz2
tar xC ./ -f FILENAME.tar.bz2 #Uncompress to the current directory. A folder named FILENAME will be created.
split -b 1M FILENAME.tar.bz2 "FILENAME.tar.bz2.part" #Split to 1-MB files
cat FILENAME.tar.bz2.part* > all.tar.bz2 #Combine
tar cvf FILENAME.tar DIRECTORY/ #Tar a folder (without compression)
tar -cvjf FILENAME.tar.bz2 DIRECTORY/* #Compress all files in DIRECTORY into FILENAME.tar.bz2
tar xC ./ -f FILENAME.tar.bz2 #Uncompress to the current directory. A folder named FILENAME will be created.
split -b 1M FILENAME.tar.bz2 "FILENAME.tar.bz2.part" #Split to 1-MB files
cat FILENAME.tar.bz2.part* > all.tar.bz2 #Combine

Convert HEIC images

sudo apt-get install libheif-examples
for file in *.HEIC; do heif-convert $file ${file/%.HEIC/.jpg}; done
sudo apt-get install libheif-examples
for file in *.HEIC; do heif-convert $file ${file/%.HEIC/.jpg}; done

Boot with no GUI

sudo systemctl disable gdm
sudo systemctl disable gdm

Stop GUI

sudo service gdm stop
sudo service gdm stop

Start GUI

sudo service gdm start
sudo service gdm start

Number of files and folders in a directory

ls directory | wc -l
ls directory | wc -l

Count files recursively in a directory

find directory -type f | wc -l
find directory -type f | wc -l

Size of a folder

du -sh folder_path
du -sh folder_path

When there are large amount of files in the directory to delete (-bash: /bin/rm: Argument list too long)

cd /home/wu/folder_to_delete
ls | xargs -n 10 rm -fr
cd /home/wu/folder_to_delete
ls | xargs -n 10 rm -fr