0% found this document useful (0 votes)
33 views27 pages

Linux Os

The document discusses several basic Linux commands including ls, pwd, mkdir, cd, rmdir, rm, cp, mv, uname, touch, cat, clear, ps, man, grep, echo, cal, wc, and cmp. It provides descriptions and examples of how to use each command.

Uploaded by

Apeksha Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views27 pages

Linux Os

The document discusses several basic Linux commands including ls, pwd, mkdir, cd, rmdir, rm, cp, mv, uname, touch, cat, clear, ps, man, grep, echo, cal, wc, and cmp. It provides descriptions and examples of how to use each command.

Uploaded by

Apeksha Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

LINUX OS

Linux provides a powerful command-line interface compared to other operating systems such as Windows and
MacOS.

What is Linux?
Linux is free and open-source software, with an operating system of its own. Linux stands for GNU + Linux. It is
developed along with the source code of Unix and was first developed by Linus Torvalds. Although it is widely
used for various purposes, no one does not know about its uses.
We can do some basic tasks such as creating a file, deleting a file, moving a file, and more.

In addition, we can also perform advanced tasks such as administrative tasks (including package installation, user
management), networking tasks (ssh connection), security tasks, and many more.

Linux terminal is a user-friendly terminal as it provides various support options.

To open the Linux terminal, press "CTRL + ALT + T" keys together, and execute a command by pressing the
'ENTER' key.
Basic Linux Commands
Linux commands are a type of Unix command or shell procedure. They are the basic tools used to interact with Linux
on an individual level. Linux operating system is used on servers, desktops, and maybe even your smartphone.

Is – Displays information about files in the current directory.


pwd – Displays the current working directory.
mkdir – Creates a directory.
cd – To navigate between different folders.
rmdir – Removes empty directories from the directory lists.
rm –r Removes non empty directories from the directory lists.
cp – Moves files from one directory to another.
mv – Rename and Replace the files
rm – Delete files
uname – Command to get basic information about the OS
locate– Find a file in the database.
touch – Create empty files
cat – Display file contents on terminal
clear – Clear terminal
Basic Linux Commands

ps- Display the processes in terminal


man – Access manual for all Linux commands
grep- Search for a specific string in an output
echo- Display active processes on the terminal
wget – download files from the internet
whoami- Create or update passwords for existing users
sort- sort the file content
cal- View Calendar in terminal
whereis – View the exact location of any command types after
this command
df – Check the details of the file system
wc – Check the lines, word count, and characters in a file using
different options
Is command
Is command
The ls command is commonly used to identify the files and directories in the working directory. This
command is one of the many often-used Linux commands that you should know.

This command can be used by itself without any arguments and it will provide us the output with all the
details about the files and the directories in the current working directory.

There is a lot of flexibility offered by this command in terms of displaying data in the output. Check the below
image for the output.
Is command
Options Description
-l known as a long format that displays detailed information about files and directories.
-a Represent all files Include hidden files and directories in the listing.

-t Sort files and directories by their last modification time, displaying the most recently modified ones first.
-r known as reverse order which is used to reverse the default order of listing.

-S Sort files and directories by their sizes, listing the largest ones first.
-R List files and directories recursively, including subdirectories.

-i known as inode which displays the index number (inode) of each file and directory.
-g known as group which displays the group ownership of files and directories instead of the owner.

-h Print file sizes in human-readable format (e.g., 1K, 234M, 2G).


-d List directories themselves, rather than their contents.
pwd command

pwd command

The pwd command is mostly used to print the current working


directory on your terminal. It is also one of the most commonly
used commands.

Now, your terminal prompt should usually include the entire


directory. If it doesn’t, this is a quick command to see which
directory you’re in.

Command: pwd
mkdir command

mkdir command Meaning?


Is
This mkdir command allows you to create fresh directories in mkdir operatingsystem
the terminal itself. The default syntax is mkdir <directory name> ls
and the new directory will be created.

For example, if you want to create a directory as


“operatingsystem” then the basic syntax would be:

mkdir operatingsystem

In case you want to create another directory inside the main directory operatingsystem to
store projects, you can use the following command to do so. mkdir operatingsystem /projects
cd command
The cd command is used to navigate between directories.

It requires either the full path or the directory name, depending on your current working directory.

If you run this command without any options, it will take you to your home folder. Practical

This command is used to move inside a directory from a directory.


cp & mv command

The cp command of Linux is equivalent to copy-paste and cut-


paste in Windows.

mv command
The mv command is generally used for renaming the
files in Linux.

Command:
rmdir command
The rmdir command is used to delete permanently an empty
directory. To perform this command the user running this
command must be having sudo privileges in the parent
directory.

Command:
ls
rmdir operatingsystem
Ls

rm command

rm command in Linux is generally used to delete the files


created in the directory.

Command: rm file1.txt
uname command
The uname command is used to check the complete OS
information of the system. Check out the command and the
output below

Command: uname

Options and Examples


1. -a option: It prints all the system information in the following order: Kernel name, network node hostname, kernel
release date, kernel version, machine hardware name, hardware platform, operating system

Command: uname -a
uname

s option: It prints the kernel name.

Syntax: uname -s

-r option: It prints the kernel release date.


Syntax: uname -r

-v option: -v option: It prints the version of the current kernel.


Syntax: uname -v
Basic Commands
touch command
The touch command creates an empty file when put in the terminal in this format as

cat command

The cat command is the simplest command to use when you want to see the
contents of a particular file.

The only issue is that it simply unloads the entire file to your terminal. If you
want to navigate around a huge file, should use less command alternatively.

clear command
The clear command is a standard command to clear the terminal screen.

ps command
ps command in Linux is used to check the active processes in the terminal.
ps command
 Linux provides us a utility called ps
for viewing information related with
the processes on a system which
stands as abbreviation for “Process
Status”.
Result contains four columns of information.
Where,  ps command is used to list the
PID – the unique process ID currently running processes and
TTY – terminal type that the user is logged into their PIDs along with some other
TIME – amount of CPU in minutes and seconds that the process information depends on different
has been running
CMD – name of the command that launched the process. options.
Basic Commands:

The man command displays a user manual for any commands or utilities available in the Terminal,
including their name, description, and options.

Command to view the full manual: man <command name>

The grep command is used to find a specific string in a series of outputs.

For example, if you want to find a string in a file, you can use the syntax: <Any command with output> | grep
“<string to find> “

For Example: cat Files.txt | grep “new”


echo command
echo command in Linux is specially used to print something in the terminal
Basic Commands

cal command
The cal command is not the most famous command in the terminal but it functions to view the calendar for a
particular month in the terminal. Let’s see how this works.

Command: cal August 2023

wc command
wc command in Linux indicates the number of words, characters, lines, etc using a set of options.

wc -w shows the number of words


wc -l shows the number of lines
wc -m shows the number of characters present in a file

Let’s see one example of these options


cmp command NOTE:

cmp - Compare two files, and if they differ, tells 'cmp' reports the differences between two files character by
the first byte and line number where they differ. character, instead of line by line.

As a result, it is more useful than 'diff' for comparing binary


cat sample.txt files.
This is a sample text file
For text files, 'cmp' is useful mainly when you want to know only
$ cat sample1.txt whether two files are identical. For files that are identical, 'cmp'
This is another sample file produces no output.

$ cmp sample.txt sample1.txt When the files differ, by default, 'cmp' outputs the byte offset
sample.txt sample1.txt differ: byte 10, and line number where the first difference occurs.
line 1
Unlike 'diff', 'cmp' cannot compare directories; it can only
compare two files.
comm command
Comm compare two sorted files line by line and As using comm, we are trying to compare two files
write to standard output; the lines that are common therefore the syntax of comm command needs two
and the lines that are unique. filenames as arguments.

Eg. Suppose you have two lists of people and you With no OPTION used, comm produces three-column
are asked to find out the names available in one and output where
not in the other, or even those common to both.
first column contains lines unique to FILE1 ,
comm is the command that will help you to achieve
this. second column contains lines unique to FILE2 and

It requires two sorted files which it compares line by third and last column contains lines common to both the
line. files.
comm command only works right if you are comparing
Syntax :$comm [OPTION]... FILE1 FILE2 two files which are already sorted.
// using comm command for comparing two files //

// displaying contents of file1 // $comm file1.txt file2.txt


$cat file1.txt Apaar
Apaar Ayush
Ayush Deepak
Deepak Hemant
Hemant Lucky
Pranjal
// displaying contents of file2 //
$cat file2.txt
Apaar  The above output contains of three columns where first column is separated
Hemant by zero tab and contains names only present in file1.txt ,
Lucky
Pranjal  Second column contains names only present in file2.txt and separated by one
tab

 Third column contains names common to both the files and is separated by
two tabs from the beginning of the line.
diff command
diff stands for difference. This command is used to display the differences in the files
by comparing the files line by line.

Unlike its fellow members, cmp and comm, it tells us which lines in one file have is
to be changed to make the two files identical.

The important thing to remember is that diff uses certain special symbols and
instructions that are required to make two files identical.

It tells you the instructions on how to change the first file to make it match the second
file.

a : add
c : change
d : delete
Example of diff command
cat a.txt
Gujarat
Andhra Pradesh
Telangana
Bihar
Uttar pradesh

$ cat b.txt
Gujarat
Andhra Pradesh Here above output 3d2 means delete line 3rd of first file i.e. Telangana so
Bihar that both the files sync up at line 2.
Uttar pradesh

$ diff a.txt b.txt


3d2
< Telangana
diff Command:
The first line of the diff output will contain:

 Line numbers corresponding to the first file,


 A special symbol and
 Line numbers corresponding to the second file.

Like in our case, 0a1 which means after lines 0(at the very
beginning of file) you have to add Tamil Nadu to match the
second file line number 1. It then tells us what those lines are
in each file preceded by the symbol:

Lines preceded by a < are lines from the first file.

Lines preceded by > are lines from the second file.

Next line contains 2,3c3 which means from line 2 to


line 3 in the first file needs to be changed to match line
number 3 in the second file. It then tells us those lines
with the above symbols.
Awk command
AWK Operations:
(a) Scans a file line by line
Awk is a scripting language used for manipulating (b) Splits each input line into fields
data and generating reports. (c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines
The awk command programming language
requires no compiling and allows the user to use 2. Useful For:
variables, numeric functions, string functions, and (a) Transform data files
logical operators. (b) Produce formatted reports

3. Programming Constructs:
(a) Format output lines
(b) Arithmetic and string operations
(c) Conditionals and loops
Syntax:
awk options 'selection _criteria {action }' input-file > output-file
Awk command
Example:

Consider the following text file as the input file for all cases below:
$cat > employee.txt 1. Default behavior of Awk: By default Awk prints every line of data from the
specified file.
ajay manager account 45000
sunil clerk account 25000 $ awk '{print}' employee.txt.
varun manager sales 50000
amit manager account 47000 In the above example, no pattern is given. So the actions are applicable to all the
tarun peon sales 15000 lines.
deepak clerk sales 23000
sunil peon sales 13000 Action print without any argument prints the whole line by default, so it prints all
satvik director purchase 80000 the lines of the file without failure.
Awk command
3. Splitting a Line Into Fields : For each record i.e line, the awk
2. Print the lines which match the given pattern
command splits the record delimited by whitespace character
by default and stores it in the $n variables.
$ awk '/manager/ {print}' employee.txt .
If the line has 4 words, it will be stored in $1, $2, $3 and $4
Output:
respectively. Also, $0 represents the whole line.
ajay manager account 45000
$ awk '{print $1,$4}' employee.txt
varun manager sales 50000
amit manager account 47000
ajay 45000
sunil 25000
In the above example, the awk command prints all the
varun 50000
line which matches with the ‘manager’.
amit 47000
tarun 15000
deepak 23000
sunil 13000
satvik 80000
Built-In Variables In Awk

Awk’s built-in variables include the field variables $ awk '{print NR,$0}' employee.txt
—$1, $2, $3, and so on ($0 is the entire line) —
that break a line of text into individual words or Output:
pieces called fields.
1 ajay manager account 45000
NR: NR command keeps a current count of the 2 sunil clerk account 25000
number of input records. Remember that records 3 varun manager sales 50000
are usually lines. Awk command performs the 4 amit manager account 47000
pattern/action statements once for each record in 5 tarun peon sales 15000
a file. 6 deepak clerk sales 23000
7 sunil peon sales 13000
NF: NF command keeps a count of the number of 8 satvik director purchase 80000
fields within the current input record.
Built-In Variables In Awk
Use of NR built-in variables (Display Line Use of NF built-in variables (Display Last Field)
Number

$ awk '{print NR,$0}' employee.txt ) $ awk '{print $1,$NF}' employee.txt

1 ajay manager account 45000 $ awk '{print $1,$NF}' employee.txt


2 sunil clerk account 25000
3 varun manager sales 50000 ajay 45000
4 amit manager account 47000 sunil 25000
5 tarun peon sales 15000 varun 50000
6 deepak clerk sales 23000 amit 47000
7 sunil peon sales 13000 tarun 15000
8 satvik director purchase 80000 deepak 23000
sunil 13000
satvik 80000 t

You might also like