Some useful commands for Ubuntu terminal

# Checking the current version of installed ubuntu OS:
lsb_release -a
# checking disk space usage:
df -h
# checking disk space usage in a directory
du -hs *
# changing the password of the user:
passwd [username]
# listing the cronjobs:
crontab -l
# editing cronjobs:
crontab -e
# tailing logs
tail -f [filePath]

# tailing last 100 lines of the log file 
tail -f -n 100 [filePath]
# displaying contents of the file
cat [filePath]
more [filePath]
less [filePath]
# showing only lines which have the string "testString"
grep "testString" [file]

# grep with OR
grep "pattern1\|pattern2" [file]

# extended grep (below does the same like grep with OR, however escaping characters is not required here)
grep -e "pattern1|pattern2" [file]

# egrep (same like grep -e, which is extended grep)
egrep 'pattern1|pattern2' [file]

# show location in terminal shell prompt (you can add this to ~/.bashrc)
export PS1='$(whoami)@$(hostname):$(pwd)'

Find where inodes are being used:

# navigate to a specific directory
cd /
find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn

FInd where the storage space is used

# navigate to a specific directory
cd /
du -hs *

Majd Arbash

...

Leave a Reply