Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Command 1: pwd

This command refers to the present working directory in which you are
operating; in simpler words, in which your terminal is open. To check PWD,
execute the pwd keyword in your terminal and hit enter; the command of PWD is
written below along with the result of that command.

$ pwd

Command 2: dir
The dir command is used to print (on the terminal) all the available directories in
the present working directory:

$ dir

Command 3: ls
This command is used to list down all the directories and files inside the present
working directory (or you can give the path of a specific directory); the ls
command can be executed as shown below:

$ ls
The ls command supports various flags, and each flag has some specific role in
printing the directories or files of the current working directory.

To print the detailed information of the files/directories; the “-al” flag is used with
the “ls” command:
$ ls -al

The “-R” flag will print subdirectories of a directory as well:


$ ls -R
Moreover, to get the hidden files, “-a” flag is used:
$ ls -a

Command 4: cd
One of the most used commands of Ubuntu; you can change the directories in
the terminal using the “cd” command. For instance, the following command will
change the pwd to desktop.
$ cd Desktop

There are multiple uses of this command: one can change the present directory
to root directory or home directory using this command. When you open a fresh
terminal, you are in the home directory.

To change directory to root. For instance, we are in the Desktop directory and
want to switch to the root directory:

$ cd /

To change the present directory to the home directory:

$ cd

Command 5: touch
This Ubuntu command can be used to create a new file as well one can use it to
change the timestamp of any file; the command given below will create a new
text time in pwd:
$ touch file1.txt

If we execute a touch command to create a file, but the file is already created,
then it would change the timestamp of that file to the current time; for instance,
the command given below will change the timestamp of the file1.txt. you can
check that the timestamp has been changed to the current time:

$ touch file1.txt

Command 6: cat
This command is used to show the content of any file: For instance, the
following command will display the content inside “file1.txt”:
$ cat file1.txt
Or you can use this command to save the content of multiples files to one file:

$ cat file1.txt file2.txt > output.txt

Command 7: mkdir
The above-mentioned command will make a directory in your pwd; for example,
the following command will make the directory “new” in pwd.
$ mkdir new
Command 8: rm
This remove command is used to remove the specific file from a directory; For
instance, below mentioned command would remove the “test.txt” file from the
pwd:
$ rm test.txt

Or you can remove the empty directory, as the command given below will
remove the “test” directory:
$ rmdir test

Command 9: cp
The cp command will help you to copy any file or folder to any directory;
To copy a file to directory1:

$ cp file1.txt directory1

If you want to copy the complete folder, then;

$ cp new -r directory1

Command 10: mv
You can use this command to move files around the computer, and you can also
rename files or directories inside a specific directory: the command given below
will move the “file2.txt” to “directory1”:
$ mv file2.txt directory1

Moreover, the command given below will move the “test1” directory to
“directory1”:
$ mv test1 directory1

Command 11: head


This command helps you to get the first ten lines of a text file; for instance, the
following command will help to get the first ten lines of the “file1.text” file:
$ head file1.txt

Command 12: tail


The tail command is used to get the last ten lines of the text file; the command
below will print the ten lines from the bottom of “file1.txt”:
$ tail file1.txt
Command 13: uname
You can use the command to get the release number, version of Linux, and
much more. The “-a” flag is used to get detailed information.
$ uname -a
Command 14: wget
You can use the wget command to download the content from the internet; for
instance, the following command will download VirtualBox.

$ wget https://download.virtualbox.org/virtualbox/6.1.26/VirtualBox-6.1.26-
145957-Win.exe

Command 15: apt-get or -apt


This is one of the most important and most used commands of Ubuntu that
works with Ubuntu Advanced Packaging Tool (APT); you can use this “-apt-get”
or “-apt” to install or remove packages, or you can perform other maintenance
tasks. The “apt” requires sudo privileges to successfully execute the command.
The syntax stated below will help you to install the required package:

$ sudo apt install [packagename]
For install to install vlc media player package use:
$ sudo apt install vlc

Or you can remove the package by executing the command given below:

$ sudo apt remove [packagename]
And to delete vlc media player package:

Command 16: history


The history command shows the list of commands (with numeric numbers)
executed:

$ history
And you can execute any of the listed commands. For instance, if you want to
execute the 2nd command (which is apt update command), then you have to
write “!2” to get the result of that command:
$ !2

Command 17: grep


With the help of grep, you can search for a pattern in which a specific word lies;
for instance, the command given below will print all the lines that contain “20”
from “file1.txt”:
$ cat file1.txt | grep 20
Command 18: man
The man command will help you to get the complete user manual of any specific
command; for instance, the following command will list down the detailed usage
of the “cat” command:
$ man cat

Command 19: ps
Using the -ps command, you will be able to get the list of processes.
$ ps

Command 20: zip or unzip


To convert your files to zip archive; you can get help by using the “gzip”
command; moreover, a zipped file can be unzipped using the “gunzip”
command:
$ gzip file1.txt

You can unzip the “file1.txt” as shown below:


$ gunzip file1.txt

Command 21: hostname


This command will print your hostname on the terminal:

$ hostname

Command 22: ping


You can use the ping command to check the connectivity to your server; for
example, the command below will ping to YouTube and also prints the response
time:
$ ping youtube.com

Command 23: w
This command will display the user details that are currently logged into the
system:

$ w

Command 24: useradd


Ubuntu supports multiuser access; if you want to add another user to your
system, execute the following command to do so:

$ sudo useradd MIKE
Or you can delete the user also;

$ sudo userdel MIKE

Command 25: passwd


With the help of the passwd command, you can change the password of your
Ubuntu user:

You must pass “username” to “passwd” to change the password of that; for
example, the command given below will change the password of user “adnan”.
$ passwd adnan

Conclusion
Command-line interface (CLI) is the basic utility of any machine; you can use it
to perform multiple tasks and can perform all those operations that can be
performed using GUI. It is not just a simple app; it is key to every operating
system as there are terminal commands behind GUI operations. All in all, CLI
can be used to operate the entire operating system without GUI. Like other OS,
Ubuntu also contains a terminal that supports hundreds of commands to perform
different operations. This article lists down the most used Ubuntu commands
and their usage. Every command can perform a specific task and can help you
to automate the requested action.

What is a shell in Ubuntu?


Contents

A shell is a program that provides the traditional, text-only user interface for
Unix-like operating systems.

What is a shell in Linux?

The shell is an interactive interface that allows users to execute other


commands and utilities in Linux and other UNIX-based operating systems.
When you login to the operating system, the standard shell is displayed and
allows you to perform common operations such as copy files or restart the
system.

What is difference between Shell and terminal?

Shell is a program which processes commands and returns output , like bash in
Linux . Terminal is a program that run a shell , in the past it was a physical
device (Before terminals were monitors with keyboards, they were teletypes)
and then its concept was transferred into software , like Gnome-Terminal .

What is a shell command?

A shell is a computer program that presents a command line interface which


allows you to control your computer using commands entered with a keyboard
instead of controlling graphical user interfaces (GUIs) with a mouse/keyboard
combination. … The shell makes your work less error-prone.
What is difference between Bash and Shell?

Bash (bash) is one of many available (yet the most commonly used) Unix shells.
… Shell scripting is scripting in any shell, whereas Bash scripting is scripting
specifically for Bash. In practice, however, “shell script” and “bash script” are
often used interchangeably, unless the shell in question is not Bash.

Which shell is best?

In this article, we shall take a look at some of the top most used open source
shells on Unix/GNU Linux.

Bash Shell. Bash stands for Bourne Again Shell and it is the default shell on
many Linux distributions today. …

Tcsh/Csh Shell. …

Ksh Shell. …

Zsh Shell. …

Fish.

18 мар. 2016 г.

How do I open a shell in Linux?


You can open a shell prompt by selecting Applications (the main menu on the
panel) => System Tools => Terminal. You can also start a shell prompt by right-
clicking on the desktop and choosing Open Terminal from the menu.

Is Shell a terminal?

A shell is a user interface for access to an operating system’s services. Most


often the user interacts with the shell using a command-line interface (CLI). The
terminal is a program that opens a graphical window and lets you interact with
the shell.

Is CMD a terminal?

So, cmd.exe is not a terminal emulator because it is a Windows application


running on a Windows machine. … cmd.exe is a console program, and there are
lots of those. For example telnet and python are both console programs. It
means they have a console window, that’s the monochrome rectangle you see.

Why is it called a shell?

It is named a shell because it is the outermost layer around the operating


system. Command-line shells require the user to be familiar with commands and
their calling syntax, and to understand concepts about the shell-specific scripting
language (for example, bash).

How does a Shell work?


In general terms, a shell corresponds in the computer world to a command
interpreter where the user has an available interface (CLI, Command-Line
Interface), through which he has the possibility of accessing services of the
operating system as well as executing or invoking programs.

How do I run a shell script?

Steps to write and execute a script

Open the terminal. Go to the directory where you want to create your script.

Create a file with . sh extension.

Write the script in the file using an editor.

Make the script executable with command chmod +x <fileName>.

Run the script using ./<fileName>.

Source: https://frameboxxindore.com/linux/what-is-a-shell-in-ubuntu.html

Run Levels in Linux


A run level is a state of init and the whole system that defines what system services are
operating. Run levels are identified by numbers. Some system administrators use run levels
to define which subsystems are working, e.g., whether X is running, whether the network is
operational, and so on.
 Whenever a LINUX system boots, firstly the init process is started which is actually
responsible for running other start scripts which mainly involves initialization of you
hardware, bringing up the network, starting the graphical interface.
 Now, the init first finds the default runlevel of the system so that it could run the start
scripts corresponding to the default run level.
 A runlevel can simply be thought of as the state your system enters like if a system is in
a single-user mode it will have a runlevel 1 while if the system is in a multi-user mode it
will have a runlevel 5.
 A runlevel in other words can be defined as a preset single digit integer for defining
the operating state of your LINUX or UNIX-based operating system. Each runlevel
designates a different system configuration and allows access to different combination
of processes.
The important thing to note here is that there are differences in the runlevels according to
the operating system. The standard LINUX kernel supports these seven different runlevels :
 0 – System halt i.e the system can be safely powered off with no activity.
 1 – Single user mode.
 2 – Multiple user mode with no NFS(network file system).
 3 – Multiple user mode under the command line interface and not under the graphical
user interface.
 4 – User-definable.
 5 – Multiple user mode under GUI (graphical user interface) and this is the standard
runlevel for most of the LINUX based systems.
 6 – Reboot which is used to restart the system.
By default most of the LINUX based system boots to runlevel 3 or runlevel 5.
In addition to the standard runlevels, users can modify the preset runlevels or even create
new ones according to the requirement. Runlevels 2 and 4 are used for user defined
runlevels and runlevel 0 and 6 are used for halting and rebooting the system.
Obviously the start scripts for each run level will be different performing different tasks.
These start scripts corresponding to each run level can be found in special files present
under rc sub directories.
At /etc/rc.d directory there will be either a set of files named rc.0, rc.1, rc.2, rc.3, rc.4,
rc.5 and rc.6, or a set of directories named rc0.d, rc1.d, rc2.d, rc3.d, rc4.d,
rc5.d and rc6.d.
For example, run level 1 will have its start script either in file /etc/rc.d/rc.1 or any files in
the directory /etc/rc.d/rc1.d.
Changing runlevel
init is the program responsible for altering the run level which can be called
using telinit command.
For example, to change a runlevel from 3 to runlevel 5 which will actually allow the GUI to
be started in multi-user mode the telinit command can be used as :
/*using telinit to change
runlevel from 3 to 5*/

telinit 5
NOTE : The changing of runlevels is a task for the super user and not the normal user that’s
why it is necessary to be logged in as super user for the successful execution of the above
telinit command or you can use sudo command as :
// using sudo to execute telinit
sudo telinit 5
The default runlevel for a system is specified in /etc/initab file which will have an entry id :
5 : initdefault if the default runlevel is set to 5 or will have an entry id : 3 : initdefault if
the default runlevel is set to 3.
Need for changing the runlevel
 There can be a situation when you may find trouble in logging in in case you don’t
remember the password or because of the corrupted /etc/passwd file (have all the user
names and passwords), in this case the problem can be solved by booting into a single
user mode i.e runlevel 1.
 You can easily halt the system by changing the runlevel to 0 by using telinit 0.

What is the Linux kernel?


JUMP TO SECTION
Overview
The Linux® kernel is the main component of a Linux operating system (OS) and
is the core interface between a computer’s hardware and its processes. It
communicates between the 2, managing resources as efficiently as possible.

The kernel is so named because—like a seed inside a hard shell—it exists


within the OS and controls all the major functions of the hardware, whether it’s a
phone, laptop, server, or any other kind of computer.

What the kernel does


The kernel has 4 jobs:

1. Memory management: Keep track of how much memory is used to store


what, and where

2. Process management: Determine which processes can use the central


processing unit (CPU), when, and for how long
3. Device drivers: Act as mediator/interpreter between the hardware and
processes
4. System calls and security: Receive requests for service from the
processes
The kernel, if implemented properly, is invisible to the user, working in its own
little world known as kernel space, where it allocates memory and keeps track of
where everything is stored. What the user sees—like web browsers and files—
are known as the user space. These applications interact with the kernel through
a system call interface (SCI).

Think about it like this: The kernel is a busy personal assistant for a powerful
executive (the hardware). It’s the assistant’s job to relay messages and requests
(processes) from employees and the public (users) to the executive, to
remember what is stored where (memory), and to determine who has access to
the executive at any given time and for how long.

Where the kernel fits within the OS


To put the kernel in context, you can think of a Linux machine as having 3
layers:

1. The hardware: The physical machine—the bottom or base of the system,


made up of memory (RAM) and the processor or central processing unit
(CPU), as well as input/output (I/O) devices such as storage, networking,
and graphics. The CPU performs computations and reads from, and writes
to, memory.
2. The Linux kernel: The core of the OS. (See? It’s right in the middle.) It’s
software residing in memory that tells the CPU what to do.
3. User processes: These are the running programs that the
kernel manages. User processes are what collectively make up user
space. User processes are also known as just processes. The kernel also
allows these processes and servers to communicate with each other
(known as inter-process communication, or IPC).

Code executed by the system runs on CPUs in 1 of 2 modes: kernel mode or


user mode. Code running in the kernel mode has unrestricted access to the
hardware, while user mode restricts access to the CPU and memory to the SCI.
A similar separation exists for memory (kernel space and user space). These 2
small details form the base for some complicated operations like privilege
separation for security, building containers, and virtual machines.

This also means that if a process fails in user mode, the damage is limited and
can be recovered by the kernel. However, because of its access to memory and
the processor, a kernel process crash can crash the entire system. Since there
are safeguards in place and permissions required to cross boundaries, user
process crashes usually can’t cause too many problems.
Also, because the Linux kernel can continue to work during live patching, there's
no downtime while patches are applied for security fixes. 

You might also like