DEV Community

Nnamdi Kenneth Nwosu
Nnamdi Kenneth Nwosu

Posted on • Edited 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 (33)

Collapse
 
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'

Collapse
 
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

Collapse
 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu

Touch : to create a file without any content

Collapse
 
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 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.

Collapse
 
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.

Collapse
 
davidgfriedman profile image
David G Friedman

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

Collapse
 
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

Collapse
 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu

Thank so much

Collapse
 
alex_mondale_dbb58b28000a profile image
Alex Mondale

du and df are daily drivers for me.

Collapse
 
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

Collapse
 
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.

Collapse
 
dpacuszka profile image
dpacuszka

sudo su is redundant, just use sudo -i

Collapse
 
tienttm profile image
Quang Tien Tran

Line 22 and 48 are the same

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Generative AI often does stuff like that 😉

Collapse
 
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 Thread
 
jonrandy profile image
Jon Randy 🎖️

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

Collapse
 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu • Edited

No, was a mistake, fixed it

Collapse
 
peter-fencer profile image
Peter Vivo

With my weak memory. may favorite is:

history | grep <search>
# or with ripgrep
history | rg <search>
Enter fullscreen mode Exit fullscreen mode

~/.bashrc

HISTSIZE=100000
HISTFILESIZE=200000

alias h="history | rg"
Enter fullscreen mode Exit fullscreen mode

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.

Collapse
 
ricegf2 profile image
George F Rice

Control-r begins a "live" reverse search through bash history, updated as you type, and additional control-r presses will find the next matching command. When you find the command you want, edit it if needed and then Enter to execute.

Both control-r and "h" are useful in different ways. Control-r searches only from the beginning of the command, while "h" finds a match anywhere on the command line. And control-r is live and can repeat the search, and execute the result, while "h" statically lists all matching commands.

Collapse
 
a5537 profile image
A5537

Thank you for bringing up bash incremental searching! It is a handy tool, but there are a few things worth mentioning, so let me expand on your comment.

Both reverse-i-search Ctrl-R and forward i-search Ctrl-S (use with caution, this combination can send SIGSTOP and freeze your terminal; press Ctrl-Q to unfreeze) are not just searching, but also navigating in bash history like up/down arrows do.

If the current search line (original or edited) is executed with Enter or the search is aborted with Ctrl-G, then your position in bash history corresponds to the latest entry as expected. But if you start editing your search result or terminate the search with Ctrl-J or Esc, keep in mind that your position in history was moved back/forward to that line. That shifted position can be hundreds of entries away from your recent commands, so if up/down navigation or further searches are useless, you can Ctrl-C your way back or execute an empty line.

Also, at least in my experience, incremental searches are looking for a match in the whole string and not just in the beginning of it. However, this matching behavior may be different in your specific environment.

Collapse
 
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).

Collapse
 
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.

Collapse
 
george_ferreira profile image
George Ferreira

I did not know this. It looks like pretty nice, I will try it.

Collapse
 
angelomandato profile image
Angelo Mandato

Add "locate", and it's update tool "updatedb". Combining with grep you can find files.

"cat" and others have a z variation, e.g. "zcat". You can open gz files now days with vim/vi.

It may be good to know ,"bash", "ln", "gcc", "perl", "php", "node", python, etc.. sometimes the easiest script you can make is in a language like PHP.

Collapse
 
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.

Collapse
 
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

Collapse
 
dev-nnamdi profile image
Nnamdi Kenneth Nwosu

Thanks

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