DEV Community

Vincent Caunegre
Vincent Caunegre

Posted on

Useful Linux Commands

In this article I will show you the commands that I use the most on my Ubuntu vps.

Navigation

Command Action
ls -alth show content of folder
wc -l <path to file> display the number of lines in a file
pushd <path> go to a directory and save the path in history
popd rollback to previous directory from pushd
dirs -v show pushd history
cd - get back to previous directory (reset history)
mkdir -p /folder/folder2 create a new directory with non existing folders
find . -name "*.yaml" find all files that end by ".yaml" in current directory

File editing

Command Action
pwd > test.txt send the content of a command to a file (erase the previous content)
pwd >> test.txt add the content of a command to the next line of a file
pwd | tee test.txt same as pwd > test.txt but print it in cli
pwd | tee -a test.txt same as pwd >> test.txt but print it in cli
grep "ubuntu" test.txt | wc -l connect commands (for instance to get number of line with a word)

System

Command Action
ps aux list all processes for all users
ps aux | grep Find a running process by name
top and htop List current running process by cpu usage
free -m get memory usage
df -h get volumes % still available, always check that biggest volume is not > 90%
sudo du -sh * | sort -h sort biggest folders
sudo du -ahx / | sort -rh head -n 20
sudo ss -tulpn | cat | grep :8080 => kill -15 find if a port is already used by a process, then kill it
dig google.com check if a domain name is valid
curl -v <url> execute an http request
ip a see private and public ip adress

systemctl

Command Action
sudo systemctl start my-api.service start systemctl
journalctl -u my-api.service -f show logs of a systemctl service in real time
journalctl -u my-api.service -p err show only errors for a systemctl service
sudo journalctl --vacuum-time=2d remove logs older than 2 days

Top comments (0)