Sitemap

Top 50 Linux commands

3 min readDec 14, 2023

--

There are plenty of handful Linux commands that can make managing Linux easier. I encourage you to try these commands. Sometimes there are multiple commands to do the same thing. This document assumes you have basic knowledge of Linux.

Welcome to an amazing world of Linux! Enjoy!

System information

1. Display Linux version

hostnamectl

# or

cat /etc/os-release

2. Display Linux kernel version

hostnamectl

# or

uname -r

3. Display chip architecture

hostnamectl

# or

lscpu

4. Display number of CPUs

lscpu

5. Show CPU utilization

mpstat -p ALL

6. Show memory usage

free -h

7. Show mounted disks

df -h

# or

fdisk -l

8. Show disk usage

df -h

# or

fdisk -l

9. Show disks types

fdisk -l

10. Show how long system has been running

uptime -p

Processes

11. Show processes running

top

# or

htop

# or

ps aux

12. Kill process

kill <process-id>

# or

killall <process-name>

Jobs

13. Run command as a background job

<command> &

14. List jobs running in background

jobs

15. Bring job into foreground

fg %<job-number>

Services

16. Start, stop or restart service

systemctl enable|disable|start|stop|restart <service-name>

enable and disable subcommand turns on or off service on a permanent basis so the service state is preserved after a reboot, while start, stop, or restart subcommands are affecting the service up until the server is rebooted without saving a state after a reboot.

17. Check service status, duration, PID, memory, CPU

systemctl status <service-name>

18. List running services

systemctl --state=running

19. Check service logs

journalctl -u <service-name>

Cron jobs

20. List cron jobs for the user

crontab -l -u <user>

21. Edit cron jobs for the user

crontab -e -u <user>

Users

22. Display current user

whoami

23. Display active users and what they are doing

w

24. List last users who have logged in into the system

last

25. Display user information and assigned user groups

id <username>

26. List all users

cat /etc/passwd

See this article on how to read passwd file.

27. List all groups and assigned users

cat /etc/group

See this article on how to read group file.

28. Add a user, create user home directory and set a user password

useradd -m <username>

passwd <username>

29. Add a group

groupadd <groupname>

30. Add user to a group

groupmod -a -U <username> <groupname>

# or

usermod -a -G <groupname> <username>

# or

gpasswd -a <username> <groupname>

31. Remove user from a group

gpasswd -d <username> <groupname>

Files

32. List opened files

lsof

33. Find binary path

whereis <binary-name>

34. Find all files containing phrase in the current directory

grep -r -n "phrase" .

# or

find . -type f -exec grep -nH "phrase" {} +

35. Get files and directory sizes in the current directory

du -h -d 1 .

36. Monitor for the file change

watch tail -n 20 <file-path>

Networking

37. Display machine hostname

hostame

38. Display IP addresses attached to machine

hostname -I

39. List network interfaces

ifconfig

# or

ip a

40. List name servers used by the system

cat /etc/resolv.conf 

41. List listening ports

netstat -nutlp

42. Ping remote host

ping <hostname>

43. Check if port on a remote host is opened

telnet <hostname> <port>

To exit telnet press Ctrl+] and then type quit.

44. Check host IP addresses

 host <hostname>

46. Check host DNS information

dig <hostname>

Terminal

46. Show commands history

history

47. Run command as privileged user

sudo <command>

48. Switch to a privileged user

sudo su

Packages

49. Check if the package is installed (RHEL)

yum list <package> --installed

50. Find which package provides a binary

yum provides <binary>

51. Install a package (RHEL)

yum install <package>

Additional commands to explore: man, chmod, chown, ls, cd, mv, cp, cat, head, tail, grep, sed, touch, mkdir, vi, nano, wget, curl, tar, ssh, scp, rsync, tcpdump, screen, rpm.

Thanks for reading!

--

--

Ben Myrgorod
Ben Myrgorod

Written by Ben Myrgorod

Engineering leader specializing in cloud architecture, AI-powered automation, and reliable software delivery