Top 50 Linux commands
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-release2. Display Linux kernel version
hostnamectl
# or
uname -r3. Display chip architecture
hostnamectl
# or
lscpu4. Display number of CPUs
lscpu5. Show CPU utilization
mpstat -p ALL6. Show memory usage
free -h7. Show mounted disks
df -h
# or
fdisk -l8. Show disk usage
df -h
# or
fdisk -l9. Show disks types
fdisk -l10. Show how long system has been running
uptime -pProcesses
11. Show processes running
top
# or
htop
# or
ps aux12. Kill process
kill <process-id>
# or
killall <process-name>Jobs
13. Run command as a background job
<command> &14. List jobs running in background
jobs15. 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=running19. 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
whoami23. Display active users and what they are doing
w24. List last users who have logged in into the system
last25. Display user information and assigned user groups
id <username>26. List all users
cat /etc/passwdSee this article on how to read passwd file.
27. List all groups and assigned users
cat /etc/groupSee 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
lsof33. 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
hostame38. Display IP addresses attached to machine
hostname -I39. List network interfaces
ifconfig
# or
ip a40. List name servers used by the system
cat /etc/resolv.conf 41. List listening ports
netstat -nutlp42. 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
history47. Run command as privileged user
sudo <command>48. Switch to a privileged user
sudo suPackages
49. Check if the package is installed (RHEL)
yum list <package> --installed50. 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!
