Linux Cli
Linux Cli
When hearing about Linux, most people think of a complicated operating system that
is only used by programmers. But it’s not as scary as it seems.
Linux is an entire family of open-source Unix operating systems, that are based on
the Linux Kernel. This includes all of the most popular Linux based systems like
Ubuntu, Fedora, Mint, Debian, and others. More accurately, they’re called
distributions or distros.
Since Linux was first released in 1991, it has continued to gain popularity due to
its open-source nature. People can freely modify and redistribute it under their
own name.
When operating a Linux OS, you need to use a shell — an interface that gives you
access to the operating system’s services. Most Linux distributions use a graphic
user interface (GUI) as their shell, mainly to provide ease of use for their users.
That being said, it’s recommended to use a command-line interface (CLI) because
it’s more powerful and effective. Tasks that require a multi-step process through
GUI can be done in a matter of seconds by typing commands into the CLI.
So if you’re considering using Linux, learning basic command lines will go a long
way. In this article, you’ll learn 35 basic Linux commands that will undoubtedly
help you navigate through Linux as a newbie.
Get up to 77% OFF of Linux VPS hosting. With true virtual servers built for speed.
Start Now
Although the steps may differ depending on the distribution that you’re using, you
can usually find the command line in the Utilities section.
1. pwd command
Use the pwd command to find out the path of the current working directory (folder)
you’re in. The command will return an absolute (full) path, which is basically a
path of all the directories that starts with a forward slash (/). An example of an
absolute path is /home/username.
2. cd command
To navigate through the Linux files and directories, use the cd command. It
requires either the full path or the name of the directory, depending on the
current working directory that you’re in.
3. ls command
The ls command is used to view the contents of a directory. By default, this
command will display the contents of your current working directory.
If you want to see the content of other directories, type ls and then the
directory’s path. For example, enter ls /home/username/Documents to view the
content of Documents.
6. mv command
The primary use of the mv command is to move files, although it can also be used to
rename files.
The arguments in mv are similar to the cp command. You need to type mv, the file’s
name, and the destination’s directory. For example: mv file.txt
/home/username/Documents.
7. mkdir command
Use mkdir command to make a new directory — if you type mkdir Music it will create
a directory called Music.
To generate a new directory inside another directory, use this Linux basic command
mkdir Music/Newfile
use the p (parents) option to create a directory in between two existing
directories. For example, mkdir -p Music/2020/Newfile will create the new “2020”
file.
8. rmdir command
If you need to delete a directory, use the rmdir command. However, rmdir only
allows you to delete empty directories.
9. rm command
The rm command is used to delete directories and the contents within them. If you
only want to delete the directory — as an alternative to rmdir — use rm -r.
Note: Be very careful with this command and double-check which directory you are
in. This will delete everything and there is no undo.
To search for a file that contains two or more words, use an asterisk (*). For
example, locate -i school*note command will search for any file that contains the
word “school” and “note”, whether it is uppercase or lowercase.
As an example, find /home/ -name notes.txt command will search for a file called
notes.txt within the home directory and its subdirectories.
To illustrate, grep blue notepad.txt will search for the word blue in the notepad
file. Lines that contain the searched word will be displayed fully.
15. df command
Use df command to get a report on the system’s disk space usage, shown in
percentage and KBs. If you want to see the report in megabytes, type df -m.
16. du command
If you want to check how much space a file or a directory takes, the du (Disk
Usage) command is the answer. However, the disk usage summary will show disk block
numbers instead of the usual size format. If you want to see it in bytes,
kilobytes, and megabytes, add the -h argument to the command line.
17. head command
The head command is used to view the first lines of any text file. By default, it
will show the first ten lines, but you can change this number to your liking. For
example, if you only want to show the first five lines, type head -n 5
filename.ext.
This command is quite complex with a long list of functions such as adding new
files into an existing archive, listing the content of an archive, extracting the
content from an archive, and many more. Check out some practical examples to know
more about other functions.
There is a total of sixty-four signals that you can use, but people usually only
use two signals:
SIGTERM (15) — requests a program to stop running and gives it some time to save
all of its progress. If you don’t specify the signal when entering the kill
command, this signal will be used.
SIGKILL (9) — forces programs to stop immediately. Unsaved progress will be lost.
Besides knowing the signals, you also need to know the process identification
number (PID) of the program you want to kill. If you don’t know the PID, simply run
the command ps ux.
After knowing what signal you want to use and the PID of the program, enter the
following syntax:
To remove a user is very similar to adding a new user. To delete the users account
type, userdel UserName
Try the TAB button to autofill what you are typing. For example, if you need to
type Documents, begin to type a command (let’s go with cd Docu, then hit the TAB
key) and the terminal will fill in the rest, showing you cd Documents.
Ctrl+C and Ctrl+Z are used to stop any command that is currently working. Ctrl+C
will stop and terminate the command, while Ctrl+Z will simply pause the command.
If you accidental freeze your terminal by using Ctrl+S, simply undo this with the
unfreeze Ctrl+Q.