Hello there. My name is Dasha. I am an iOS developer—I create mobile applications for iPhones. I have been doing this for four years now and have avoided the command line as fire all this time. Yeah, sometimes I did something in the terminal with mysterious PATH
and sudo
. But I did so only when StackOverflow told me to. And I never really understood what was going on, and I just prayed not to break everything with these spells, which I thoughtlessly copied and pasted on the dark surface of the terminal.
If you also favor graphics interfaces and UX-friendly solutions, you might like to create your chatbot. I've detailed how to do it here with pictures.
However, over time, it became clear that I must overcome my fears: I need to dive into some basics to be on the same page as my laptop and DevOps colleagues. So, I enrolled in an expanded DevOps course with Linux Foundation.
I am still far from a proper command-line specialist; however, I have gained some knowledge about this topic and am eager to share it with you, tell you what most popular commands mean and how to use them (or not use them), and clarify common terms. And I will also try to answer the question: do people use terminals for genuine reasons, or do they just want to show off?
This article is not only a collection of basic information about Command Line. But it is also a frank confession of my ignorance. So, please be condescending.
Let’s get started with understanding basic concepts. There are two related but not the same things: shell and CLI (command line interface).
Shell: It is an interface that works with the operation system. In other words, sell is a layer/translator of your commands to the computer. Or, one more time, in other words, the Shell is kind of an unskilled barista at your unfavored coffee shop. You can’t say just “pumpkin latte with oat milk.” You need to provide specific instructions:
- take the cup
- pour milk in it
- beat the milk
- end, etc.
But you don’t have access to the coffee machine without this barista. The same goes for shell - you need it to get your tasks done.
By the way, here is a decent pumpkin latte recipe.
In Linux and MacOS, Bash is used as a shell. It is essential to understand that although commands look like hacker-style code, bash is not a programming language. It is a Command Interpreter. Bash processes commands one at a time, executing them immediately.
And when I am saying “mysterious names” regarding commands, I am not joking. Because we are dealing with text input, it is rational that commands have been done in a short amount of time. Printing cp
instead of “copy” is quicker. And for many commands, abbreviations are intuitive:
ls
- list
rm
- remove
man
- manual
But… for many others, abbreviations are not intuitive at all.
grep
- Global Regular Expression Print
awk
- Named after its creators (Aho, Weinberger, Kernighan), used for text processing
nohup
: "no hang up," which refers to running commands without them being terminated when the session ends.
chown
- This one is probably easy for native English speakers. “Change owner”. In general, it allows you to change access rights.
dd
- something about disks, you can think. But no. It is “data-description”.
So, what’s the point? Why do people still use command lines and cast abbreviation spells?
Long story short, there are cases when CLI is your only one or the first option.
1) Remote management.
By the way, this is especially true for DevOps when managing CI/CD. The scenario is pretty simple—you don’t have physical access to the device. Some remote desktop applications exist but can be slow and require significant bandwidth.
2) Batch processing.
Although Finder on Mac allows you to find all .jpeg images, it doesn’t allow you to find all .jpeg AND .png images AND delete them in one operation. So, for scenarios like this, a terminal can come in handy. rm *.jpeg *.jpg *.png
3) Automation and Scripting.
As for me, the most important one is what can be better when you need to perform repetitive tasks involving different actions. For example, tests launch, linter checks, and stats logging when a new commit is done. With a graphical interface for each action, you must open a separate application and press some buttons.
But if your colleague for a simple commit in GIT opens the terminal and pulls up a hood… I wouldn’t trust him.
Now, I want to share a list of commands you may use someday so that the next time you see them, you will be at least prepared for potential circumstances.
Command |
Purpose |
---|---|
ls |
List the contents of the directory |
pwd |
Displays the path of the working directory |
cd |
Changes the directory (moves to another folder) |
cp |
Copies files and directories |
rm |
Deletes files and directories |
mv |
Moves/renames files or directories in the file system |
mkdir |
Creates (makes) directories |
man |
Manual for any command |
chmod |
Changes file access permissions |
touch |
Updates the time of file access (A quick way to create a new file) |
exit |
Ends the shell session and closes the terminal |
sudo |
Acts as a superuser (Super User DO) |
shutdown |
Shuts down, stops, or reboots the computer (Yeah, I know about the button…) |
echo |
Displays information on the screen (like print) |
cat |
Creates, views, and combines files (Useful to have a glance at file content) |
ps |
Monitors running processes |
kill |
Kills processes (Can be handy if something stuck) |
ping |
Checks connectivity |
grep |
Powerful search tool for regular expressions |
whoami |
Answers the question: "Who am I, the current user?" |
wc |
Returns the count of lines, words, bytes, and filename (Unexpected, right?) |
find |
Searches for files in directories |
Danger!
Pay attention to the fact that some commands can be very dangerous. They are like Djinns; solving your exact problem can break everything else. So, even if you found it on StackOverflow, don’t rush to use them:
rm -rf /
or rm -rf *
Forcefully remove all files and directories from the root directory/subdirectories, effectively deleting everything on the system. It can lead to complete data loss and make the operating system unusable.
mkfs.ext4 /dev/sda
will erase all data on the specified disk (in this case,/dev/sda). My general advice is to avoid file system commands.
chmod -R 777 /
Changes the permissions of all files and directories to be fully accessible by everyone, making it vulnerable to unauthorized access and attacks.
I personally encountered PATH
many times. When you have a weird problem, try to install Ruby (find examples with get), google it, and then find a solution at StackOverflow that says something about PATH
. You are lucky if the specific code for the console was provided, but sometimes, people just say, “Add this to the path.”
So, what is this PATH
, and how to add things?
There are built-in commands in the shell, like cd
or read
. But if you use a command that's not built-in, Bash will look for the executable file in the directories listed in the PATH
environment variable. You can look at a list of these directories with the echo command. The list is separated by a colon :
, and the shell will search through them in that order. The first executable file found “wins”.
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
To add a directory to your PATH
temporarily (for the current session), you can use:
export PATH=$PATH:/path/to/your/directory
These days, terminals are getting super friendly. I am using Warp; it helps with auto-completion and even provides an AI feature: you can print the commands in a human-friendly way, and the app will convert them into the Bash command.
In general, AI helps me a lot in my learning of Linux. I can not only ask, “What command do I need if I want to connect this SSH?” but also share errors that I received to update the command and eventually connect the SSH successfully.
Honestly, I wouldn’t have made it without AI - I would have given up and quit the course. It is unclear why many sources about Linux, CLI, and Bash are so, well, arrogant. Finding simple explanations for the basics feels like hunting for a unicorn. Most documentation and articles seem to assume you’ve already spent years holed up in your mom’s basement, poring over Linux.
I really hope that this article turned out to be valuable and friendly to you <3
I don’t want to take any more of your precious time. So, very briefly,
rm -rf /
, rm -rf *
or chmod -R 777 /