Professional Documents
Culture Documents
When you log in to your account using SSH, the first thing you see is the Linux
command line prompt:
username@example.com [~]#
The tilde symbol ~ indicates that you are in your home directory, which is
usually /home/username.
Basic commands:
1. who :
The ‘$ who’ command displays all the users who have logged into
the system currently.
$ who
Output: harssh tty2 2017-07-18 09:32 (:0)
As shown above the only one user currently logged in. The thing
tty2 is terminal line the user is using and the next line gives the current date
and time
2. pwd :
The ‘$pwd’ command stands for ‘print working directory’ and as
the name says it is used to display the location of the current working
$ pwd
directory.
Output: /home/harssh
Output shows we are in harssh directory,which is present inside the home
directory .
3. mkdir :
The ‘$ mkdir’ stands for ‘make directory’ and it creates a new
directory.
$ mkdir newfolder
$ cd newfolder
$ pwd
Output: /home/harssh/newfolder
We have used ‘$ cd’ to get into the newly created directory and again on
giving ‘$ pwd’ command,we are displayed with the new ‘newfolder’
directory.
4. rmdir :
The ‘$ rmdir’ command deletes any directory we want to delete and
it can remembered by its names ‘rmdir’ which stands for ‘remove
directory’.
$ rmdir newfolder
5. cd :
The ‘$ cd’ command stands for ‘change directory’ and it changes
your current directory to the ‘newfolder’ directory..
For example,
Command Description
8. cp :
This ‘$ cp ‘ command stands for ‘copy’ and it simply copy/paste the
file wherever you want to.
Example :1
$ cp /home/harssh/file.txt /home/harssh/new/
Example: 2 – to copy the contents of the red file into the blue file.
$ cp red.txt blue.txt
9. mv :
The ‘$ mv’ command stands for ‘move’ and it simply move a file
from a directory to another directory.
$ mv /home/harssh/file.txt /home/harssh/new
mv old_filename new_filename
10. rm :
Syntax: $ rm <filename>
Example : $ rm file.txt
11.touch command
With the touch command, you can create a new blank file with the
given name.
$ touch <Filename>
Example:
$ touch example
$ ls
Output:
$echo “<String>”
Example
13. grep :
Example:
In the example, this would search for the word ‘picture’ in the file
newsfile and if found,the lines containing it would be displayed on the
screen.
14. Cat Command
cat <filename.extension>
Example:
cat newfile.txt
Option Function
Concatenate contents of
cat [file1, file2,….] > [new file name]
multiple files into one file.
cat –n [File_Name] / cat -b [File_Name] Display line numbers.
15. wc
Example: $ wc –l readme.txt
This command allows users to view the first lines of any text file.
It shows the first ten lines by default.
head command syntax
$ head [Filename]
You can also manually input the number of lines you want to view.
Syntax
$ head [Filename]
The number of output lines is ten by default, however, this can be changed
to any number with the -n (number) option.
Syntax
Example
$ man head
$ man pwd
19. lpr :
20. clear :
Example: $ clear
21. sort :
As the name suggests the ‘$ sort’ sorts the contents of the file
according to the ASCII rules.
$ sort file
22. chmod :
The ‘$ chmod’ command stands for change mode command. As
there are many modes in Unix that can be used to manipulate files in the
Unix environment.
Basically there are 3 modes that we can use with the ‘chmod’
command
Examples:
$ chmod +w file.txt
$ chmod +r file.txt
$ chmod +x file.txt
ls Command
ls is probably the first command every Linux user typed in their terminal.
It list the contents of the directory (the current directory by default), including
files and other nested directories.
ls
The first two parts of the given file system together called a Linux virtual file
system. It provides a single set of commands for the kernel and developers to
access the file system. This virtual file system requires the specific system driver
to give an interface to the file system.
Linux File System Features
o Specifying paths: Linux does not use the backslash (\) to separate the
components; it uses forward slash (/) as an alternative. For example, as in
Windows, the data may be stored in C:\ My Documents\ Work, whereas,
in Linux, it would be stored in /home/ My Document/ Work.
o Partition, Directories, and Drives: Linux does not use drive letters to
organize the drive as Windows does.
o File Extensions: In Linux, a file may have the extension '.txt,' but. If we
use the graphical file manager, it symbolizes the files and folders.
o Hidden files: Linux distinguishes between standard files and hidden files,
mostly the configuration files are hidden in Linux OS. The hidden files in
Linux are represented by a dot (.) before the file name (e.g., .ignore). To
access the files, we need to change the view in the file manager or need to
use a specific command in the shell.
When we install the Linux operating system, Linux offers many file systems such
as Ext, Ext2, Ext3, Ext4, JFS, ReiserFS, XFS, btrfs, and swap.
Ext2 is the first Linux file system that allows managing two terabytes of data.
Ext3 is developed through Ext2; it is an upgraded version of Ext2 and contains
backward compatibility. The major drawback of Ext3 is that it does not support
servers because this file system does not support file recovery and disk snapshot.
Ext4 file system is the faster file system among all the Ext file systems. It is a
very compatible option for the SSD (solid-state drive) disks, and it is the default
file system in Linux distribution.
JFS stands for Journaled File System, and it is developed by IBM for AIX
Unix. It is an alternative to the Ext file system. It can also be used in place of
Ext4, where stability is needed with few resources. It is a handy file system
when CPU power is limited.
Btrfs stands for the B tree file system. It is used for fault tolerance, repair system,
fun administration, extensive storage configuration, and more. It is not a good
suit for the production system.
The swap file system is used for memory paging in Linux operating system during
the system hibernation. A system that never goes in hibernate state is required to
have swap space equal to its RAM size.
3) It is user-friendly. Hence, millions of Linux users use it for their editing needs.
Some of the other ones are Elvis, Nvi, Nano, and Vile.
Modes of Operation in vi editor
Command Mode:
The vi editor opens in this mode, and it only understands
commands
In this mode, you can, move the cursor and cut, copy, paste
the text
This mode also saves the changes you have made to the file
Control Commands(Scrolling):
There are following useful commands which can used along with Control Key:
To edit the file, we need to be in the insert mode. There are many ways to enter
insert mode from the command mode.
Deleting Characters:
List of commands which can be used to delete characters and lines in an opened
file.
Copy lines or words from one place and paste them on another place by using
the following commands.
Need to press [Esc] key followed by the colon (:) before typing the following
commands:
q : Quit
q! : Quit without saving changes i.e. discard changes.
r fileName : Read data from file called fileName.
wq : Write and quit (save and exit).
w fileName : Write to file called fileName (save as).
w! fileName : Overwrite to file called fileName (save as
forcefully).
!cmd : Runs shell commands and returns to Command mode.
syntax
:s/string
For example, to search some text for the string “geeksforgeeks” Type the
following and press ENTER:
:s/geeksforgeeks
Output:
finding the first match for “geeksforgeeks” in text will then be highlighted.
The syntax for replacing one string with another string in the current line is:
:s/pattern/replace/
Here “pattern” represents the old string and “replace” represents the new string.
For example, to replace each occurrence of the word “geeks” in a line with
“geeksforgeeks” type:
:s/geeksforgeeks/gfg/
output
The syntax for replacing every occurrence of a string in the entire text is
similar. The only difference is the addition of a “%” in front of the “s”:
:%s/pattern/replace/
Thus repeating the previous example for the entire text instead of just for a single
line would be:
:%s/gfg/geeksforgeeks/
4.Partitions creation :
Creating disk partitions enables you to split your hard drive into multiple
sections that act independently. Partitioning is particularly useful if you run
multiple operating systems.
Steps to create a partition using the Linux fdisk command.
sudo fdisk –l
Select the storage disk where to create partitions on by running the following
command:
(/dev/sda is the hard disk of the computer we are using. sd[a-z] is the currently used
naming format for disks in Linux. And lastly, /dev/sda[1-15] shows the partitions within hard
disk)
3. After that, you are asked for the starting and ending sector of your hard drive.
It is best to type the default number in this section (3622912).
4. The last prompt is related to the size of the partition. one can choose to have
several sectors or to set the size in megabytes or gigabytes.
The system created the partition, but the changes are not written on the disk.
sudo fdisk -l
Now output will be, the partition /dev/sdb2 has been created.
Once a partition has been created with the parted of fdisk command, format it
before using it.
5.What is Shell?
Shell Prompt
The prompt, $, which is called the command prompt, is issued by the shell.
While the prompt is displayed, you can type a command.
Example :the date command, which displays the current date and time −
$date
C shell − If you are using a C-type shell, the % character is the default
prompt.
Shell Scripts
Shells are interactive, they accept command as input from users and
execute them.
Some times to execute a bunch of commands routinely, instead of typing
in all commands each time in terminal..
we can write these commands in a file and can execute them in shell to
avoid this repetitive work. These files are called Shell Scripts or Shell
Programs.
Shell scripts are similar to the batch file in MS-DOS. Each shell script is
saved with .sh file extension eg. myscript.sh
To create a script containing commands, u put the shebang line first and
then add the commands − ( It's called a shebang because the # symbol is called
a hash, and the ! symbol is called a bang.) to alert the system that shell script is start….
#!/bin/bash
pwd
ls
$chmod +x test.sh
$./test.sh
/home/amrood
Example2
The following script uses the read command which takes the input from the
keyboard and assigns it as the value of the variable PERSON and finally prints it
on STDOUT.
#!/bin/sh
read PERSON
O/P:
$./test.sh
Zara Ali
6.What is a process?
ListingProcess:
# ps (displays the following)
PID TTY TIME CMD
Finding Process:
# pgrep -u username
(to see PID related to specific user)
#pidof crond
(to see PID of specific process)
Signals:
Signals are messages that are sent to processes with a command like kill.
The advantage of signals is that they can be sent to a process even if it is
not attached to a terminal.
So if a web server or a graphical program whose interface has “frozen”
can still be shut down by sending appropriate signal.
Sending signals to processes:
Process normally terminate on their own when they have completed.
Interactive application may need the user to issue a quit command.
CTRL + C also terminate the process, which send an interrupt (INT) signal
to a process.
If a process doesn’t terminate using above method, you can
use KILL signal.
Scheduling Priority:
Every running process has a scheduling priority, Whoever has got higher
priority, gets more attention of the CPU.
The priority of process is set by altering niceness value.
The niceness value defaults to zero(0) but can be set from -20 (least value,
highest piority) to 19 (highest value, least priority)
Job Control:
[1]+ stopped