Here are 50 basic Linux commands that are useful for navigating and managing your system:
-
pwd
- Print working directory. -
ls
- List directory contents. -
cd
- Change directory. -
touch
- To create a file without any content. -
cat
- Concatenate and display file content. -
cp
- Copy files or directories. -
mv
- Move or rename files or directories. -
rm
- Remove files or directories. -
mkdir
- Create a new directory. -
rmdir
- Remove an empty directory. -
echo
- Display a line of text or a variable value. -
nano
- A simple text editor. -
vi
- A powerful text editor. -
chmod
- Change file or directory permissions. -
chown
- Change file or directory owner and group. -
find
- Search for files in a directory hierarchy. -
grep
- Search text using patterns. -
man
- Display the manual for a command. -
ps
- Display information about running processes. -
kill
- Terminate processes by PID. -
top
- Display and update sorted information about processes. -
df
- Report file system disk space usage. -
du
- Estimate file space usage. -
free
- Display memory usage. -
uname
- Print system information. -
uptime
- Tell how long the system has been running. -
whoami
- Display the current user. -
sudo
- Execute a command as another user, typically the superuser. -
apt-get
- Package handling utility for Debian-based distributions. -
yum
- Package manager for RPM-based distributions. -
tar
- Archive files. -
zip
- Package and compress (archive) files. -
unzip
- Extract compressed files. -
wget
- Retrieve files from the web. -
curl
- Transfer data from or to a server. -
ssh
- OpenSSH client (remote login program). -
scp
- Secure copy (remote file copy program). -
rsync
- Remote file and directory synchronization. -
hostname
- Show or set the system's host name. -
ping
- Send ICMP ECHO_REQUEST to network hosts. -
netstat
- Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. -
ifconfig
- Configure a network interface. -
ip
- Show/manipulate routing, devices, policy routing, and tunnels. -
iptables
- Administration tool for IPv4 packet filtering and NAT. -
systemctl
- Control the systemd system and service manager. -
journalctl
- Query and display messages from the journal. -
crontab
- Schedule periodic background jobs. -
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 -
mount
- Mount a file system. -
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)
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'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. 🤷♂️
Touch : to create a file without any content
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.
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.
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.
Use "touch" to backdate a file's timestamp. There are legitimate uses for that btw.
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
Thank so much
du and df are daily drivers for me.
If you have
iproute2
installed, then you can usess
(Socker Statistics) to see the status of the ports. This is cleaner thannetstat
ss
is also the preferred tool sincenetstat
is deprecated.ifconfig
androute
are also deprecated, useip address
(can be shortened toip addr
orip a
) andip route
for those.Also,
dnf
instead ofyum
on newer RPM-based distros.sudo su
is redundant, just usesudo -i
Line 22 and 48 are the same
Generative AI often does stuff like that 😉
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. 😊
If indeed this is the case, there are guidelines that should be followed for such content.
No, was a mistake, fixed it
With my weak memory. may favorite is:
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.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.
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.
I would like to add the
htop
to the list. It is a command (I think it is not installed by default) similar totop
but with extra options (and also colors :D).use glances command, it is more easier than top and htop. We have to install glances as it does not come by default.
I did not know this. It looks like pretty nice, I will try it.
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.
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.
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
Thanks
Some comments may only be visible to logged-in visitors. Sign in to view all comments.