The command line is a text-based interface that can be used to take input from a
user as an instruction to the computer system. In the Linux, the command line
is provided by a program called the “shell”. There are so many shell program
have been developed but “GNU Bourne-Again shell (bash)” is the default shell in
some Linux distribution such as Centos and RHEL. Bash is an improved version of
one of the most successful shells used on UNIX like the system the Bourne Shell
(sh).
Using
“bash” to execute command can be powerful. The “bash” shell provides a
scripting language that can support the automation of tasks. The shell has
additional capabilities that can simplify or can make some operation possible
that are hard to accomplish with graphical tools.
Note: The “bash” shell is similar in
concept to “cmd.exe” the command line interpreter of Microsoft Windows,
although bash is a more sophisticated scripting language and it is also similar
to “PowerShell”.
To
access the terminal in a graphical mode of Centos and RHEL you just need to
select Application > Utilities > Terminal or Just right click on an empty
desktop > Open Terminal.
From
the Activities Overview, select Terminal from the dash (either from the
favorite’s area or by finding it with the grid button (inside utility grouping)
or the search field at the top of the window overview).
Before starting to learn some commands
let understand the difference between $ and #.
When
a shell is used interactively. The shell displays a string when it is waiting
for a command from the user. This is called the shell prompt. When a regular
user starts a shell, it shows $ character to the end of the prompt by default.
The
$ character gets replaced by a # if the shell is running as the superuser,
root. This # character makes it more obvious that it is a superuser shell,
which helps to avoid accidents and mistakes in the privileged account.
Linux Basic Commands
Let’s
starts with simple Linux commands.
1. pwd command: “pwd” stands for
present working directories that print the absolute path of the current working
directories.
2. cal command: “cal” command display calendar of current month but by specifying month and year it will display a calendar of that specific month and year for example: “cal 5 2000”.
From
the above example 5 stands for the month “may” and 2000 is the “year”. You can
practice by specifying only a month after the “cal” command.
4. whoami command: “whoami” command
displays the name of a current user who is logged-in into a particular
terminal.
5. who am i command: There is a
difference between “whoami” and “who am i” the command “who am i” display not
only current user who is logged-in but also pseudo-terminal (pts), time and
comment.
8. ls command: “ls” command
display list of files and directories from current working directories, for
example, if you are in the root directory and you type ‘ls” command then it
will display all the files and directories under the root directory.
10. touch command: with “touch”
command you can create a file without any content. It extension can be .txt,
.file, .zip, or etc.
If
you try to remove directory by just “rm “command it will give throw a message
“cannot remove “dir”: Is a directory”. But if you want to remove directories you have to use –r (recursive) option.
12. mkdir command: when you want to
make a directory then use “mkdir” to create directory and ‘mkdir” stands for
make directory.
If
you want to make subdirectory under a directory from
a single command then use –p, this means parent
option creates parent directories for the requesting destination.
13. rmdir command: To remove any
directory you can use the “rmdir” command and “rmdir” stands for remove
directory.
14. mv command: “mv” command is
used to move files or directories from source to destination. The example for
the command is “mv source destination”.
Useful command line-editing shortcuts
Shortcut
|
Description
|
Ctrl+l
|
Clear the current
terminal.
|
Ctrl+a
|
Jump to the start
of the command line.
|
Ctrl+e
|
Jump to the last line
of the command.
|
Ctrl+u
|
Clear from the
cursor to the start of the command line.
|
Ctrl+k
|
Clear from the
cursor to the last line of the command.
|
Ctrl+left arrow
|
Jump to the
beginning of the previous world on the command line.
|
Ctrl+right arrow
|
Jump to the end of
the next word on the command line.
|
Ctrl+r
|
Search the history
list of commands for a pattern.
|