My Linux Cheat Sheet

Kevin FOO
2 min readJul 1, 2020

--

Frequently needed but always forgotten.

Bash

# check folder size
du -h --max-depth=1
# list files in directory starts with z
ls z*
# list files starts with z and
# second character must be c or d
ls z[cd]*
# search for a keyword within all the files
# in the directory and all its subdirectory
grep -rnw . -e 'pattern'
# substring 'pot' from 'hippopotamus'
echo 'hippopotamus'|cut -c6-8
# file fruits.txt has 5lines, command to print line 2 to 4
# pear
# apple
# banana
# orange
# strawberry
sed -n -e '2,4p' fruits.txt
# if the path or filename has no spaces in it
find .|grep some_pattern|xargs rm -rf
# if the path or filename has space in it
find .|grep some_pattern|xargs -I @ sh -c 'rm -rf "@"'

Vim

# vimrc config
cd ~
echo 'set tabstop=2'>>.vimrc
echo 'set shiftwidth=2'>>.vimrc
echo 'filetype indent on'>>.vimrc
echo 'set hlsearch'>>.vimrc
# vim editor
shift + v = select line
ctrl + v = select char by char
# after selection
shift + i = insert char
shift + u = convert selection to uppercase
u = convert selection to lowercase

Virtualbox

Install Virtualbox guest additions. Tested working in Linux Mint 20 Ulyana. Ran properly for a while for Elementary OS 5.1.5 Hera, then crash. Did not manage to get it working with Ubuntu Mate 20.04, maybe I missed something.

sudo apt update
sudo apt upgrade -y
sudo apt install virtualbox-guest-x11 -y

After setting up the shared folder, run the command below to grant permission to the folder.

sudo adduser $USER vboxsf

Crontab

#run VNC server at display 1 after reboot using ubuntu user
@reboot su ubuntu -c 'vncserver :1'

Run script at server reboot with different user

< Back to all the stories I had written

--

--

Kevin FOO
Kevin FOO

Written by Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.

No responses yet