Buy Me a Coffee

Linux Handbook (🚧Continuous Update)

1. Set up permanent alias

alais boltbrowser="bb"
source .bashrc

2. Mount the external drive permanently

See other posts:

  1. How to mount the external hard drive permanently
  2. External hard drive is read-only

3. Check which process owns the specific port

sudo netstat -tulpn
sudo netstat -tulpn | grep 80

# or

sudo ss -tulpn
sudo ss -tulpn | grep 80

# or

sudo ps aux 
sudo ps aux | grep 80

4. Open an url in web browser from Terminal

xdg-open https://google.com

5. Delete the installed package with apt

# Check the apt installed history
gtrep " install " /var/log/apt/history.log

# Only remove the package but keep the configuration
sudo apt remove <package_name>

# Remove both package and configuration
sudo apt purge <package_name>

6. List all the block devices

lsblk -f

Output is like

sda                                                                                     
└─sda1      ntfs     Windows1    F8F4FE4CF4FE101C                      186.2G    17% /media/windows1
sdb                                                                                     
├─sdb1                                                                                  
└─sdb2      ntfs     Windows2 AC3E10303E4FF1DE                        3.4T     7% /media/windows2
nvme0n1                                                                                 
├─nvme0n1p1 vfat                    2142-6826                             505.8M     1% /boot/efi
└─nvme0n1p2 ext4                    34987fb7-46e7-4aa4-a62e-ee73fb7e033d    848G     14% /

7. Suppress the failure exit code while running a command or program

Attach || : to the running command

snyk test 2>/dev/null || :

8. Check the exit code of previous running command

After running the command, excute echo $?

9. Install/Remove .deb file

sudo dpkg -i xxx.deb
sudo dpkg --purge <deb_name>

Give a teamviewer as an example

# Install
sudo dpkg -i teamviewer_15.34.4_amd64.deb
# Remove
sudo dpkg --purge teamviewer

10. Upload file to remote server with scp

scp <local-file> <remote-server>:<remote-path> example: scp ./docker-compose.yml AWSServer01:~/

11. Find and replace words

:10,20s/foo/bar/g

12. Set up the local DNS

edit the file /etc/hosts

1127.0.0.1 localhost
2# new added
3127.0.0.1 example.org

13. List file tree with specifying pattern

Only show .env or .yml file, but ignore .git folder

tree -a -P '*.env|*.yml' -I '*.git'tree 

Enjoyed this article? Support my work with a coffee ☕ on Ko-fi.
Buy Me a Coffee at ko-fi.com
DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !