DEV Community

Nnamdi Kenneth Nwosu
Nnamdi Kenneth Nwosu

Posted on • Updated on

50 basic Linux commands

Here are 50 basic Linux commands that are useful for navigating and managing your system:

  1. pwd - Print working directory.
  2. ls - List directory contents.
  3. cd - Change directory.
  4. touch - To create a file without any content.
  5. cat - Concatenate and display file content.
  6. cp - Copy files or directories.
  7. mv - Move or rename files or directories.
  8. rm - Remove files or directories.
  9. mkdir - Create a new directory.
  10. rmdir - Remove an empty directory.
  11. echo - Display a line of text or a variable value.
  12. nano - A simple text editor.
  13. vi - A powerful text editor.
  14. chmod - Change file or directory permissions.
  15. chown - Change file or directory owner and group.
  16. find - Search for files in a directory hierarchy.
  17. grep - Search text using patterns.
  18. man - Display the manual for a command.
  19. ps - Display information about running processes.
  20. kill - Terminate processes by PID.
  21. top - Display and update sorted information about processes.
  22. df - Report file system disk space usage.
  23. du - Estimate file space usage.
  24. free - Display memory usage.
  25. uname - Print system information.
  26. uptime - Tell how long the system has been running.
  27. whoami - Display the current user.
  28. sudo - Execute a command as another user, typically the superuser.
  29. apt-get - Package handling utility for Debian-based distributions.
  30. yum - Package manager for RPM-based distributions.
  31. tar - Archive files.
  32. zip - Package and compress (archive) files.
  33. unzip - Extract compressed files.
  34. wget - Retrieve files from the web.
  35. curl - Transfer data from or to a server.
  36. ssh - OpenSSH client (remote login program).
  37. scp - Secure copy (remote file copy program).
  38. rsync - Remote file and directory synchronization.
  39. hostname - Show or set the system's host name.
  40. ping - Send ICMP ECHO_REQUEST to network hosts.
  41. netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
  42. ifconfig - Configure a network interface.
  43. ip - Show/manipulate routing, devices, policy routing, and tunnels.
  44. iptables - Administration tool for IPv4 packet filtering and NAT.
  45. systemctl - Control the systemd system and service manager.
  46. journalctl - Query and display messages from the journal.
  47. crontab - Schedule periodic background jobs.
  48. sudo su - allows us to switch to a different user and execute one or more commands in the shell without logging out from our current session
  49. mount - Mount a file system.
  50. umount - Unmount a file system.

These commands form the basis of interacting with a Linux system and performing various administrative tasks.

Goodluck!

Top comments (27)

 
jonrandy profile image
Jon Randy 🎖️ • Edited

The touch command is actually used to update the last modified time and last accessed time of a file or directory. The fact that it creates a new empty file if the given filename does not exist is a convenient side-effect, but not the main function of the command.

A far simpler (and shorter) way is to just use >myFileName.txt, which will create the file 'myFileName.txt'

 
shricodev profile image
Shrijal Acharya

Exactly, it should be one of the most misunderstood CLI command. Almost everyone thinks of the "touch" command as a way to create an empty file.

I guess not everyone uses man pages to learn a new CLI tool. 🤷‍♂️

Image description

 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu

Touch : to create a file without any content

 
seanbracksdev profile image
SeanBracksDev • Edited

I wouldn’t say it’s misunderstood.
It’s a side-effect yes, but it’s still the simplest and easiest way to create an empty file, hence why it’s used this way.

Thread
 
shricodev profile image
Shrijal Acharya

Exactly. It's just that the command is not primarily used for its main purpose but rather as a fallback feature. However, the fallback feature seems more of a robust use case rather than its main feature.

 
josephj11 profile image
Joe

I expect that few people use man pages to learn new commands. Man pages remind you very tersely what a command does and tell you what the calling sequences and options are. Most do not even include one example. They exist primarily to quickly remind you of how to use things you already understand. The GNU info pages, when they exist, are usually far better.

 
davidgfriedman profile image
David G Friedman

Use "touch" to backdate a file's timestamp. There are legitimate uses for that btw.

 
stevenev38 profile image
Steven McCloud

Lol Certainly. Some recommended edits/additions

ifconfig is now outdated, as net-tools doesn't come by default anymore on most systems. ip is the successor.
Same goes for vi. Vim has the same/even more functionality and is the successor of vi (Vi-IMproved)—though it's true from my experience that vi typically comes out of the box, and vim does not

Some recommended additions:
dd
history
Redirections (>, >>)
usermod
adduser
addgroup
tail
head
less
more
lsmod
lsblk

Regarding touch, previous commenters are correct that it's primary function is to modify timestamps—which is still important when building and compiling—and no other basic tool has the functionality, so it's still significant for it's primary function. But on that note, one could argue that tools with which the primary purpose is to aid in the builds and compiling process would not fall under the "Basic Linux commands" category soo ¯_(ツ)_/¯

On that note, commands I do think should fall under basic tools—in that they're important to know in order to experience the the primary selling point of Linux, i.e. the functionality and efficiency—are as follows:
awk
ln
tee
cut
tr
sort
uniq

 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu

Thank so much

 
0nth0 profile image
Navneet Thillaisthanam

If you have iproute2 installed, then you can use ss (Socker Statistics) to see the status of the ports. This is cleaner than netstat

 
orenc profile image
Chanan Oren

ss is also the preferred tool since netstat is deprecated.

ifconfig and route are also deprecated, use ip address (can be shortened to ip addr or ip a) and ip route for those.

Also, dnf instead of yum on newer RPM-based distros.

 
dpacuszka profile image
dpacuszka

sudo su is redundant, just use sudo -i

 
tienttm profile image
Quang Tien Tran

Line 22 and 48 are the same

 
jonrandy profile image
Jon Randy 🎖️

Generative AI often does stuff like that 😉

 
shricodev profile image
Shrijal Acharya

Certainly! The first word provided another big hint that this might have been generated by Generative Models. It's fine to use those models as long as you're not simply copying and pasting, but rather gaining insights and using them thoughtfully. @dev-nnamdi, please don't take it the wrong way. 😊

Thread
 
jonrandy profile image
Jon Randy 🎖️

If indeed this is the case, there are guidelines that should be followed for such content.

 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu • Edited

No, was a mistake, fixed it

 
peter-fencer profile image
Peter Vivo

With my weak memory. may favorite is:

history | grep <search>
# or with ripgrep
history | rg <search>

~/.bashrc

HISTSIZE=100000
HISTFILESIZE=200000

alias h="history | rg"

so at the end just type (example) h commit I can found my latest commit - by the way I always use git from terminal because in this way git commands have memory, but this is true for every other bash command which I did.

 
josephj11 profile image
Joe

FYI: sudo is gradually being depreciated because it has a large attack surface. AFAIK, it is being replaced by doas. It's not quite as versatile, but it handles all common usages with something like 10% of the source code of sudo.

 
george_ferreira profile image
George Ferreira

I would like to add the htop to the list. It is a command (I think it is not installed by default) similar to top but with extra options (and also colors :D).

 
ramashankar_pandey_ profile image
Ramashankar Pandey

use glances command, it is more easier than top and htop. We have to install glances as it does not come by default.

 
kanani_nirav profile image
Kanani Nirav • Edited
 
litlyx profile image
Antonio | CEO at Litlyx.com

So useful to have cheat sheet on useful commands from basic to pro on linux. Keep up the good work man.

Antonio, CEO at Litlyx

 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu

Thanks

 
ookamisensei profile image
Goran Tomasic

Why does it say "Certainly!" as the first thing? Too lazy to remove it from the AI response before copy/pasting it as a post here? 😁

 
martinbaun profile image
Martin Baun

Just saw an article about why AI-generated articles do really well on here. Very interesting.

 
lsgw31 profile image
Lucas Grenier

"Certainly!" Definitely not ChatGPT

Some comments may only be visible to logged-in visitors. Sign in to view all comments.