0% found this document useful (0 votes)
83 views12 pages

Fundamentals, Linux/Unix Commands, Regular Expressions, Variables, VI Editor

This document provides an overview of the key components and features of the Linux operating system. It discusses the kernel, system libraries, system tools, development tools, end user tools, and top 50 commands in Linux. It also explains why Linux is widely used and how it works at a high level.

Uploaded by

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

Fundamentals, Linux/Unix Commands, Regular Expressions, Variables, VI Editor

This document provides an overview of the key components and features of the Linux operating system. It discusses the kernel, system libraries, system tools, development tools, end user tools, and top 50 commands in Linux. It also explains why Linux is widely used and how it works at a high level.

Uploaded by

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

fundamentals,

Linux/Unix commands,
Regular Expressions,
Variables,
VI Editor

What is linux:
1. Open source operating system like Mac, microsoft, apple, iOS,
android,Windows etc
2. Unix is also an operating system like linux; it is an commercial
OS and has three parts kernal,Shell,and programs.
3. What is OS? It helps in enabling communication between
hardware and software. It conveys input to get processes by the
processor and brings output to the hardware to display it.
4. Developed by Linus Torvalds in 1991, idea was to improve the
unix OS. Used in wristwatches to supercomputers, every possible
hardware devices.
5. Its structure:

1. Kernal:
Linux kernal is core part of OS. establishes communication between
devices and software. Has 4 responsibilities:
I) Device management: A system has many devices connected to it lik
CPU, memory chip, graphic card, sounds card etc. A kernal stores all the
data related to all the devices in device driver. Thats why kernal knows
everything about the devices and knows how to manipulate it to bring
the best out of it. Helps in managing communication between devices.
II) Memory management: the kernal keeps track of used and unused
memory and makes sure that processes shouldnt manipulate data of
each other using virtual memory addresses
III) Process management: kernal assigns enough time and gives
proorities to processes before handling CPU to other processes. Deals
with security and ownership info.
IV) Handling system calls: programmer can write a query or ask karnal
to perform the task.

2) System libraries;
I. This helps in accessing the kernel’s features. A kernel has to be
triggered to perform some tsk and this is done by applications.
II. But applications must know how to place a system call because each
kernel has a different set of system calls. Programmers have
developed a standard library of procedures to communicate with the
kernel.
III. Each operating system supports these standards, and then these are
transferred to system calls for that operating system.
IV. The most well-known system library for Linux is Glibc (GNU C
library).

3) System Tools:
I. Linux OS has a set of utility tools, which are usually simple
commands.
II. It is a software which GNU project has written and publish under
their open source license so that software is freely available to
everyone.
III. With the help of commands, you can access your files, edit and
manipulate data in your directories or files, change the location of
files, or anything.

4) Development tools:
I. With the above three components, your OS is running and working.
But to update your system, you have additional tools and libraries.
II. These additional tools and libraries are written by the programmers
and are called toolchain.
III. A toolchain is a vital development tool used by the developers to
produce a working application.
5) End User tools:

I. These end tools make a system unique for a user. End tools are not
required for the operating system but are necessary for a user.

II. Some examples of end tools are graphic design tools, office suites,
browsers, multimedia players, etc.

Why do we use linux;


Linux is perfect OS if we want to get rid of all viruses, malware,
slowdowns, crashes, costly repairs, and many more. Further, it provides.
We don’t have to pay for it.
Open source
Secure
Distributions
Fast performance

For the people, by the people.(On the other hand, open-source is


completely different. The source code is included with the compiled
version and allows modification by anyone having some knowledge. It
gives us the freedom to run the program, freedom to change the code
according to our use, freedom to redistribute its copies, and freedom
to distribute copies, which are modified by us.)

Favorable choice of developers:


Linux I suitable for developers , as it supports almost all the
programming langs.
Developers find that the Linux terminal is much better than the
Windows command line, So, they prefer terminal over the Windows
command line.

How does linux work?


Linux OS includes GNU tools to provide a way to manage the kernel
resources, install software, configure the security setting and
performance, etc.
To run Linux from the terminal, press the "CTRL+ALT+T" keys. And, to
explore its functionality, press the application button given on the
left down corner of your desktop.
Linux System services:
1. Process scheduling
2. Application scheduling
3. Basic peripheral devices
4. File system

Linux features:
1. Multiuser capability
2. Multitasking
3. Portability
4. Security
5. Live CD/USB
6. Graphical user interface
7. Support’s customized keyboards
8. Application support
9. File system
10. Open source
Top 50 commands:
command syntax use
pwd pwd Used to display
location of the current
working directory
mkdir mkdir<directory name> Used to create a new
directory under any
directory
rmdir rmdir<directory name> Used to delete a
directory
ls ls Used to display list of
content of a directory
cd cd<directory name> Change the current
directory
touch touch<file name> Create empty files, we
touch<file1><file2> can create multiple
empty files by
executing it once
cat cat[OPTION]…..[FILE] It is a multi-purpose
cat><file name> utility in the linux
//enter file content system. It can be used
CTRL+D SAVE the keys to create a file,display
content of the file,
copy the content of
one file to another file
and more
rm rm<file name> Remove file
cp cp <existing file name> <new file name>   Copy a file or directory

mv mv<file name><directory path> Used to move a file or


directory from one
location to another
location
rename rename 's/old-name/new-name/' files   Rename files, it is useful
rename 's/\.txt$/\.pdf/' *.txt   for renaming large group
of files
head head<file name> Display content of a
file,displays the first 10
lines of a file
tail Tail<file name> Displays last ten lines
tac Tac<file name> Reverse of cat
command,displays file
content in reverse order
more More<file name> it is used to display the
In more command, the following keys are used to file content in the same
scroll the page: way that the cat
ENTER key: To scroll down page by line. command does. The
Space bar: To move to the next page. only difference
b key: To move to the previous page. between both
/ key: To search the string. commands is that, in
case of larger files, the
more command
displays screenful
output at a time.
less Less<file name> It also includes some
extra features such as
'adjustment in width
and height of the
terminal.'
Comparatively, the
more command cuts
the output in the width
of the terminal.
su Su<user name> Provides administrative
access to another user.
It allows access of the
linux shell to another
user.
id id Command is used to
display the user ID(UID)
and group ID(GID)
useradd Useradd username used to add or remove
a user on a Linux
server.
passwd Passwd<username> Used to create and
change the password for
a user
groupadd Groupad<group name> Create group
cat Cat<fileName>| cat or tac | cat or tac |. . .    Used as a filter, to filter a
file, it is used inside
pipes
cut cut -d(delimiter) -f(columnNumber) <fileName>   Select specific column of
a file (-d) used as a
delimiter it can be a
space (' '), a slash (/), a
hyphen (-), or anything
else. And, the '-f' option
is used to specify a
column number.
grep Command | grep <searchWord> Global regular
expression print useful
for searching the content
from a file
Comm Comm <file1><file2> Compare two files or
streams.By default, it
displays three columns,
first displays non-
matching items of the
first file, second indicates
the non-matching item
of the second file, and
the third column displays
the matching items of
both files
sed stream command | sed 's/<oldWord>/<newWord>/'   Used to edit files using
editor regular expression. It dos
not permanently eidt
files; insead, the edit
content remains only on
display. Does not afect
the acutal file
tee cat <fileName> | tee <newFile> |  cat or tac |..... The only difference
between both filters is
that it puts standard
input on standard output
and also write them into
a file.
tr command | tr <'old'> <'new'>   used to translate the file
content like from lower
case to upper case.
uniq command <fileName> | uniq used to form a sorted list
in which every word will
occur only once.
wc Wc<filename> Used to count the lines, words
and characters in a file
od od -b <fileName>      // Octal format   used to display the content of
od -t x1 <fileName>   // Hexa decimal format   a file in different s, such as
od -c <fileName>     // ASCII character format   hexadecimal, octal, and ASCII
characters.
sort Sort<file name> Sort files in alphabetical order
gzip Gzip<file1><file2><file3>….. Used to trucate the file size.
Compressing tool. It replaces
the original file by the
compressed file having '.gz'
extension.
gunzip Gunzip<file1>….. Decompress a file
find find . -name "*.pdf"  Used to find a particular file
The following symbols are used after the find within a directory
command:
(.) : For current directory name
(/) : For root
 
locate Locate<file name> used to search a file by file
name. It is quite similar to find
command; the difference is
that it is a background
process. It searches the file in
the database, whereas the
find command searches in the
file system. It is faster than
the find command.
date date Display date time zone and
more
cal Cal< Display current months’s
calender and with surrent
date highlighted
sleep Sleep<time> used to hold the terminal by
the specified amount of time.
By default, it takes time in
seconds.
time time Display the time to execute a
command
zcat Zcat<file name> Displays the compressed files
df df display the disk space used in
the file system. It displays the
output as in the number of
used blocks, available blocks,
and the mounted directory.
mount mount -t type <device> <direc to connect an external device
tory>   file system to the system's file
system.
exit exit exit from the current shell. It
takes a parameter as a
number and exits the shell
with a return of status
number.
clear clear To clear terminal screen
ip Ip a or ip addr an updated version of the
ipconfig command. It is used
to assign an IP address,
initialize an interface, disable
an interface.
ssh ssh user_name@host(IP/Dom is used to create a remote
ain_name)</p>   connection through the ssh
protocol.
mail mail -s "Subject" <recipient ad used to send emails from the
dress>   command line.

ping Ping<destination> used to check the connectivity


between two nodes, that is
whether the server is
connected. It is a short form
of "Packet Internet Groper."
host host <domain name> or <ip ad used to display the IP address
dress>   for a given domain name and
vice versa. It performs the
DNS lookups for the DNS
Query.

expr --help option will display its expr 15 + 12


documentation that contains its expr 10 - 5
description and other useful expr 10 \* 5  
information. If we get stuck Expr 10/2   
while using the expr command,
it will be useful.
Expr --version It is used to display the version
information. It will display the
information, such as it is open-
sourced, warranty info, its
specific version, and the author's
name.
Find length of a string a=hello<br>   First variable stores the
b=`expr length $a`<br>   value of the given string,
echo $b   second stores length of
the sting.echo command
will display the value of
b
Position of character in a string a=ALPHABET<br>  
b=`expr index $a P`<br>  
echo $b  

Find the substring from a string. a=ALPHABET  


b=`expr substr $a 3 6`  
echo $b  

Perform an operation on echo "Enter two numbers"  


variables using a shell script   
read a  
  
read b  
  
sum=`expr $a + $b`  
  
echo "Sum = $sum"  

Compare two expressions a=50   c=`expr $a \< $b`  


b=70 $c  
c=`expr $a = $b`  
$c  
  c=`expr $a \!= $b`  
$c  

Match the numbers of characters expr javatpoint : javatpoint  


in two strings: expr alphabet : alpha  
expr string1 : string2   expr alphabet : alphabet  
Increment a variable: A=20
B=’expr $a +1’
$b
Or
B=’expr $a +5’
Echo $b
Modulus value Expr 10%5
Display the true condition between the two · a=20  
conditions · b=30  
· c=`expr $a \< $b`  
· d=`expr $a \= $b`  
· e=`expr c \| d`  
· echo $e 

Linux regular expression called regex or regexp. Regular expression is a pattern fir matching
string that follows some pattern.
Metacharacter Description
. Replaces any character.
^ Matches start of string and represents characters not in the string.
$ Matches end of string.
* Matches zero or more times the preceding character.
\ Represents the group of characters.
() Groups regular expressions.
? Matches exactly one character.
+ Matches one or more times the preceding character.
{N} Preceding character is matched exactly N times.
{N,} Preceding character is matched exactly N times or more.
{N,M} Preceding character is matched exactly N times, but not more than N times.
- Represents the range.
\b Matches empty string at the edge of a word.
\B Matches empty string if it is not at the edge of a word.
\< Matches empty string at the beginning of a word.
\> Matches empty string at the end of a word.

Regex Versions
There are three versions of regular expressions syntax:
BRE : Basic Regular Expressions
ERE : Extended Regular Expressions
PRCE: Perl Regular Expressions
Depending on tool or programs, one or more of these versions can be used.

Linux grep regular expressions:


The grep tool has the following options to use regular expressions;
-E : String is read as ERE (Extended Regular Expressions)
-G : String is read as BRE (Basic Regular Expressions)
-P : String is read as PRCE (Perl Regular Expressions)
-F : String is read literally.
Print lines matching a grep <pattern> <fileName>   The grep command
pattern grep t msg.txt   will search for line
grep l msg.txt   that matches the
grep v msg.txt   specified pattern.

Concatenating grep tp msg.txt   If a pattern is of


characters grep in msg.txt   concatenating
grep is msg.txt   characters then it has
to be matched as it is,
for the line to be
displayed.
One or the other grep <option> <'pattern|pattern> <fileName>   Here pipe (|) symbol
grep -E 'j|g' msg.txt   is used as OR to
grep -P 'j|g' msg.txt   signify one or the
grep -G 'j\|g' msg.txt   other. All the three
versions are shown.
Options -E and -P
syntax are same but
-G syntax uses (\).
One or more/zero or grep <option> <'pattern*'> <fileName>   The * signifies zero or
more grep -E '1*' list   more times occurence
grep -E '1+' list   of a pattern and +
signifies one or more
times occurence.
Match the end of a grep <pattern>$ <fileName>   To match the end of a
string grep r$ dupli.txt   string we use $ sign
grep e$ dupli.txt  

Match the start of a grep ^<pattern> <fileName>   To match the start or


string grep ^o dupli.txt   beginning of a file we
use caret sign (^).
Separating words grep '\b<pattern>\b' <fileName>  
grep '\bsome\b' file  

Linux rename regular expressions;


Rename command used mostly used to search string and replace it with
another string

Rename ‘s/string/other string/’

E. g. rename ‘s/text/txt/’* all text are converted to txt.

A global replacement:
In the above example only first 'txt' was replaced in 'atxt.txt'. To replace both the 'txt' we can use
a global replacement 'g'.

rename 's/string/other string/g'  
Example;
Rename ‘s/txt/TXT/g’ atxt.txt

Case insensitive replacement:


A string can be replaced with a case insensitive string.
Rename ‘s/.text/.txt/i’*
Linux sed regular expression:
Stream editor: the sed command is used for stream editing
Example;· echo interactive | sed 's/inte/dist/'  
· echo interactive | sed 's:inte:dist:'  
· echo interactive | sed 's_inte_dist_'  
· echo interactive | sed 's|inte|dist|' 
string 'interactive' is changed to 'distractive' with sed command.
Inspite of forward slash (/), colon (:), underscore (_) and pipe (|)
will also work.

Interactive editor: the sed commands is meant o be stream editor


while it can be used as interactive ediotr on a file for interactive
editor option ‘i’ is used
sed -i 's/today/tomorrow/' file  

You might also like