Did you know that there are literally hundreds of Linux commands? Even on a bare-bones Linux server install there are easily over 1,000 different commands.
The interesting thing is that most people only need to use a very small subset of those commands. Below you’ll find a Linux “cheat sheet” that breaks down some of the most commonly used commands by category.
To get your own PDF and printable copy, scroll to the bottom of the page. Enjoy!
An Introduction to the Linux Terminal and CLI
This guide is streamlined
for complete beginners in the Linux community to get on their feet and get
started with the terminal, use the Linux command line (LCI), and execute
commands. To become a hacker at all, especially if you intend to maximize on
the tools that the Linux Kali offers, you must be good with the Linux command
line. The standard way to interact with the Linux service is via the command
line.
Learning the LCI may seem
like a daunting task, but it is pretty easy if you master the basics and begin
developing the skill on your own from there. This is why this guide, rather
than present you a list of ready commands to enter into the terminal and get
instant results, focuses more on describing the different elements of the
terminal, how and why they work, and what you will use them for. Let’s start.
1.1 The Terminal Emulator
A terminal emulator is
essentially a program that enables you to use the terminal in a graphical user
environment. Most people who are introduced to Linux are already familiar with
other operating systems, mainly Microsoft Windows and Apple’s Mac OSX which use
a full graphical user interface to interact with the user in the day-to-day
computer operations.
They, too, however, have
terminal emulators you may have heard of: Terminal (default) and iTerm 2 in Mac
OSX; and PuTTY in Windows. In Linux, it is necessary that you use the terminal
emulator such as the default Terminal, XTerm, or KDE Konsole.
Each of these
terminal emulators has its set of unique and shared features, and they are all
great to work with and easy to use as you will learn.
1.2 The Shell
The shell in the Linux
system is a command-line interface that interprets the commands and scripts
that the user enters, then tells the operating system what to do with them.
There are many shells that you will get acquainted with such as the Bourne
shell (sh) and the C shell (csh). Each shell in Linux has its sets of features
and intricacies when it comes to how they interpret commands, but they all
share certain features: they all have input and output redirection, condition
and variable testing, etc.
The default shell for most
Linux distros including CentOS, Ubuntu, and RedHat is the Bourne shell, also
known as bash, which is also what is used in this e-book. I should point out
that this is also the default shell for
1.3 The Command Prompt
When you start the Terminal
application on Linux, you will be taken to the command prompt or shell prompt,
which is where you can enter the commands to issue to the computer. The
information presented by the command prompt can differ depending on the version
and distribution of Linux or how the user chooses to customize it. Typically,
Ubuntu-based distributions have a command prompt in this format:
username@hostname~$
The tilde symbol (~)
represents the current directory in bash, the default Ubuntu shell. This special
character expands to the entire path of the current user’s directory which in
this case would be /home/username.
The prompt symbol ($)
denotes the end of the command prompt after which the user’s keyboard input
cursor will appear. However, when you log into the command prompt as a
superuser, the $ symbol will be replaced by #. Try entering this in your
command prompt after the $ symbol then presses enter:
username@hostname~$ su
You will be prompted to
enter your root password because you entered a command to switch to a superuser
with root access. Once your enter your password, the command prompt will change
to something like this:
hostname username #
The symbol (#) is the
standard symbol for root. The root is a superuser account in Linux, which means
it is a special account that can perform system-wide administrative functions
and must be used with caution. This is a free user account with privileges to
perform any task. It is recommended that you do not switch to a superuser
account unless it is necessary. Instead, you can use the sudo command that we
will learn in a short while.
1.4 Executing Commands
Commands are executed by
the Shell when you specify the name of an executable file in the form of a
binary program or a script file. There are thousands of standard Linux commands
and utilities that come with the operating system that you can use to navigate
the file system, install and configure software packages, and run the system
and third-party applications.
A running instance of an
executed command is called a process. When you execute a command in the
foreground, which is the default state in which commands are executed, you must
wait for the process to complete before you can revert to the command prompt to
issue a new command.
It is important to
understand that almost all commands in Linux, including file and directory
names, arguments, and options are case sensitive. If you enter a command you
know right, and it does now cause the effect you expected, the first thing you
should do is double check the spelling and the letters case.
1.1.1 Execute commands
without arguments or options
You can run a command
without any arguments or options by simply typing the name of the command then
hitting return. Running a command like this causes it to exhibit its default
behavior, which is dependent on the command. e.g.
Cd
will bring your back to the current user’s home directory.
ls
will print a list of the directories and files in the current working
directory.
Ip
will print how to use the ip command.
1.2.2 Execute commands with
arguments
Many commands in Linux accept arguments, also
called parameters, which have a direct impact on the behavior of the command.
e.g.
cd /usr/bin Argument specifies which directory
to change to, in this case, bin directory inside usr directory.
ls /usr/bin
Prints a list of directories and files in the directory /usr/bin.
Most commands accept
options, also referred to as switches or flags. These options modify the
behavior of the command. Options follow a command and are indicated by one -
character preceding one or more options represented by single uppercase or
lowercase letters. Note, however, that some options start with -- followed by
one character or a multi-character word that is typically descriptive of what
the option does e.g.
ls -a Prints a listing of directories and files including any hidden ones.
ls -l Prints a long listing of files and directories including extra details.
ls -l -a Prints a long listing of files and directories including hidden ones.
As you can see in the last
example above, options can be grouped together. An alternative way to run the
last command above is to combine options like this:
ls -la
1.4.4 Execute commands with
options and arguments
As you get familiar with
Linux, one thing you will quickly notice is that you can almost always combine
options and arguments when running commands on the terminal. For instance, it
is easy for you to check the contents of a directory regardless of the present
working directory by just running this command
ls -la /home
In this ls
command, -la are the options while the /home is the argument that points to the
file or directory that the command can refer to.
1.5 More commands
This chapter introduces the
basics of the Linux terminal and is in no way exhaustive. However, the
foundation laid in this hour should help you expand your knowledge of Linux
commands, how to navigate view, and edit files and their permissions - and to become a formidable hacker.
Here is a summary of some
of the most popular commands you can practice to reinforce the idea of how
commands work in Linux:
cd
Change to the home directory. Also used to navigate the Linux file
system.
pwd
(print working directory) Shows the path of the current working folder.
No comments:
Post a Comment