From 8265ca4d21f622a6218dc6652dd5a494182bae01 Mon Sep 17 00:00:00 2001 From: itspatkar <94187044+itspatkar@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:49:28 +0530 Subject: [PATCH] Updated Linux --- linux.html | 1098 ++++++++++++++++++++++++++-------------------------- 1 file changed, 547 insertions(+), 551 deletions(-) diff --git a/linux.html b/linux.html index 0030e7f..ceb779c 100644 --- a/linux.html +++ b/linux.html @@ -56,7 +56,7 @@

LINUX & BASH

# Linux Basics

-
+
• Shell :
@@ -122,8 +122,7 @@
• Shell :
-
-
+
• System and User :
@@ -134,14 +133,14 @@
• System and User :
- - - - - - - - + + + + + + + + @@ -190,10 +189,10 @@
• System and User :
- - - - + + + + @@ -249,8 +248,7 @@
• System and User :
suswitch user - allow switch to another user
sudosuperuser do - allow executing commands with elevated/root privileges
suswitch user - allow switch to another user
sudosuperuser do - allow executing commands with elevated/root privileges
df filesystem disk space usage uptime show uptime (how long the system has been running)
halthalts system by stopping all processes but does not power off
halthalts system by stopping all processes but does not power off
poweroff poweroff system
-
-
+
• Networking :
@@ -305,7 +303,7 @@
• Networking :
- ` + @@ -316,8 +314,7 @@
• Networking :
netstat print network connections, routing tables, interface statistics, masquerade connections, multicast memberships, etc. (deprecated)
route show / manipulate the IP routing table (deprecated)
-
-
+
• File Management :
@@ -488,115 +485,127 @@
• File Management :

# Bash Scripts

-

A Bash script is a plain text file that contains a series of commands that are executed in sequence. Scripts have .sh extension (for example: script.sh). Shell scripts begin with the shebang (#!/bin/sh), which tells the system which shell interpreter to use to run the script.

-
Ex :
-
#!/bin/bash
+                
+

A Bash script is a plain text file that contains a series of commands that are executed in sequence. Scripts have .sh extension (for example: script.sh). Shell scripts begin with the shebang (#!/bin/sh), which tells the system which shell interpreter to use to run the script.

+
Ex :
+
#!/bin/bash
 
 mkdir Docs
 cp doc1.txt Docs/
 rm doc1.txt
 clear
-
Executing Scripts :
-

Note : The script must have executable permission.

-
./[script]
+                    
Executing Scripts :
+

Note : The script must have executable permission.

+
./[script]
 sh [script]
 bash [script]
 
 # Output each command execution :
 bash -x [script]
-
Ex :
-
./script.sh
+                    
Ex :
+
./script.sh
 bash script.sh
+

# Variables

-
Declaring :
-
greet="Hello World"
+                
+
Declaring :
+
greet="Hello World"
 num=17
-
Access :
-
echo $greet
+                    
Access :
+
echo $greet
 echo "Number is ${num}"
-
Read-Only Variable :
-
readonly COUNT=1
-
Declare Integer :
-
declare -i num=10
-
Remove Variable :
-
unset num
+
Read-Only Variable :
+
readonly COUNT=1
+
Declare Integer :
+
declare -i num=10
+
Remove Variable :
+
unset num
+

# Strings

-
Declaring :
-
greet="Hello World"
-
Access :
-
echo $greet
-
Length of string :
-
echo ${#greet}
-
String Replace :
-
greet="Hello World"
+                
+
Declaring :
+
greet="Hello World"
+
Access :
+
echo $greet
+
Length of string :
+
echo ${#greet}
+
String Replace :
+
greet="Hello World"
 echo "Before: $greet"
 greet=${greet/World/Universe}
 echo "After: $greet"
+

# Arrays

-
Declaring Indexed Array :
-
declare -a fruits=("apple" "mango" "banana" "orange")
-
Declaring Associative Array :
-
declare -A india["capital"]="New Delhi"
+                
+
Declaring Indexed Array :
+
declare -a fruits=("apple" "mango" "banana" "orange")
+
Declaring Associative Array :
+
declare -A india["capital"]="New Delhi"
 
 declare -A capital=(["India"]="New Delhi", ["Nepal"]="Kathmandu", ["Bhutan"]="Thimphu")
-
Indexing :
-
fruits[0]="grapes"
-
Access Element :
-
echo ${fruits[0]}
-
Print All Elements :
-
echo ${fruits[@]}
-
Print Key of Associative Array :
-
echo ${!india[@]}
-
Length of Array :
-
echo ${#fruits[@]}
-
Input :
-
read -a fruits
+
Indexing :
+
fruits[0]="grapes"
+
Access Element :
+
echo ${fruits[0]}
+
Print All Elements :
+
echo ${fruits[@]}
+
Print Key of Associative Array :
+
echo ${!india[@]}
+
Length of Array :
+
echo ${#fruits[@]}
+
Input :
+
read -a fruits
+

# Input

-
Input (STDIN) :
-
read [var]
-
Prompt Input :
-
read -p "Username : " [var]
-
Secure Prompt Input :
-
read -sp "Password : " [var]
-
Input NChar :
-
read -n [x] [var]
-
Array Input :
-
read -a [array]
+
+
Input (STDIN) :
+
read [var]
+
Prompt Input :
+
read -p "Username : " [var]
+
Secure Prompt Input :
+
read -sp "Password : " [var]
+
Input NChar :
+
read -n [x] [var]
+
Array Input :
+
read -a [array]
+

# Output

-
Print (STDOUT) :
-

The echo prints output followed by a new line character.

-
echo "Hello World"
+                
+
Print (STDOUT) :
+

The echo prints output followed by a new line character.

+
echo "Hello World"
 
 msg="Hello World"
 echo $msg
 echo "Hii, ${msg}"
-
Enable Backslash Escapes :
-
echo -e "\n Hello World"
-
Special Char in Output :
-
echo '$Hello World'
-
Print (STDOUT) :
-

The printf prints output in the specified format; it does not append an implied newline.

-
printf "\n%s\n\n" "Hello World"
+
Enable Backslash Escapes :
+
echo -e "\n Hello World"
+
Special Char in Output :
+
echo '$Hello World'
+
Print (STDOUT) :
+

The printf prints output in the specified format; it does not append an implied newline.

+
printf "\n%s\n\n" "Hello World"
+

# Operators

-
+
• Arithmetic Operator :
@@ -639,9 +648,7 @@
• Arithmetic Operator :

Note : Arithmetic operations should be in double braces: count=$((count+1))

-
-
• Logical Operator :
@@ -667,9 +674,7 @@
• Logical Operator :
-
-
• Relational Operator :

(Numerical Comparison)

@@ -707,15 +712,13 @@
• Relational Operator :
-
Ex : +
+
Ex :
if [ 80 -gt 40 ]
 then
     echo "Greater"
 fi
-
-
• Relational Operator :

(String Comparison)

@@ -757,9 +760,7 @@
Ex :
else echo "Not Matched" fi
-
-
• Lexicographic Comparison :
@@ -781,9 +782,7 @@
• Lexicographic Comparison :
-
-
• File Testing Operator :
@@ -851,100 +850,103 @@
Ex :

# Escape Sequence

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EscapeDescription
\\backslash
\aalert (BEL)
\bbackspace
\csuppress trailing newline
\fform feed
\nnew line
\rcarriage return
\thorizontal tab
\vvertical tab
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EscapeDescription
\\backslash
\aalert (BEL)
\bbackspace
\csuppress trailing newline
\fform feed
\nnew line
\rcarriage return
\thorizontal tab
\vvertical tab
+

# Variable Substitution

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VarDescription
${x}substitute value of variable x
${x:+y}if x is set, y is substituted for x. (value of x does not change)
${x:-y}if x is null or unset, y is substituted for x. (value of x does not change)
${x:=y}if x is null or unset, x is set to value of y.
${x:?y}if x is null or unset, y is printed to standard error.
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VarDescription
${x}substitute value of variable x
${x:+y}if x is set, y is substituted for x. (value of x does not change)
${x:-y}if x is null or unset, y is substituted for x. (value of x does not change)
${x:=y}if x is null or unset, x is set to value of y.
${x:?y}if x is null or unset, y is printed to standard error.
+

# Command Substitution

-

Command substitution allows the output of a command to replace the command itself. Using a backquote is old-style; instead, the second form is recommended.

-
+
+

Command substitution allows the output of a command to replace the command itself. Using a backquote is old-style; instead, the second form is recommended.

• Back-Quote :
Syntax :
`[command]`
-
Ex :
# Example 1:
 DATE=`date`
@@ -953,9 +955,7 @@ 
Ex :
# Example 2: USERS=`who | wc -l` echo "Logged in user are $USERS"
-
-
• Dollor Sign & Parenthesis :
Syntax :
$([command])
@@ -973,7 +973,7 @@
Ex :

# Decision Making

-
+
• If Statement :
Syntax :
if [ condition ]
@@ -992,16 +992,13 @@ 
Syntax :
then #Statement fi
-
Ex :
x="Y"
 if [ "$x" = "y" ] || [ "$x" = "Y" ]
 then
     echo "YES"
 fi
-
-
• If-Else Statement :
Syntax :
if [ condition ]
@@ -1010,7 +1007,6 @@ 
Syntax :
else #Statement fi
-
Ex :
name="admin"
 if [ $name = "admin" ]
@@ -1019,9 +1015,7 @@ 
Ex :
else echo "Who Are You?" fi
-
-
• Elif Statements :
Syntax :
If [ condition ]
@@ -1033,7 +1027,6 @@ 
Syntax :
else #Statement fi
-
Ex :
# Example 1:
 x=10
@@ -1062,9 +1055,7 @@ 
Ex :
else echo "Scalene" fi
-
-
• Switch Statement :
Syntax :
case [var] in
@@ -1102,14 +1093,13 @@ 
Ex :

# Loops

-
+
• While Loop :
Syntax :
while [ condition ]
 do
     #Statement
 done
-
Ex :
# Example 1: print "hello" 5 times
 count=0
@@ -1160,9 +1150,7 @@ 
Ex :
counter=$(( $counter - 1 )) done echo $factorial
-
-
• For Loop :
Syntax :
for [var] in [expression]
@@ -1174,7 +1162,6 @@ 
2nd Syntax :
do #Statement done
-
Ex :
# Example 1: input array & print
 read -a array
@@ -1239,9 +1226,7 @@ 
Ex :
for key in ${!array[@]}; do echo "$key : ${array[$key]}" done
-
-
• Until Loop :

Executes until the condition is false.

Syntax :
@@ -1249,7 +1234,6 @@
Syntax :
do #Statement done
-
Ex :
count=5
 until [ $count -le 0 ]
@@ -1258,16 +1242,13 @@ 
Ex :
count=$((count-1)) sleep 1 done
-
-
• Select Loop :
Syntax :
select [var] in [expressions]
 do
     #Statements
 done
-
Ex :
select drink in tea cofee water orange apple none
 do
@@ -1286,13 +1267,10 @@ 
Ex :
;; esac done
-
-
• Loop Controls :
-
-
1. Break Statement -
-
a=1
+                    
1. Break Statement -
+
a=1
 while [ $a -lt 10 ]
 do
     echo $a
@@ -1302,10 +1280,8 @@ 
1. Break Statement -
fi a=$(expr $a + 1) done
-
-
-
2. Continue Statement -
-
nums="1 2 3 4 5 6 7"
+                    
2. Continue Statement -
+
nums="1 2 3 4 5 6 7"
 for num in $nums
 do
     q=$(expr $num % 2)
@@ -1316,38 +1292,38 @@ 
2. Continue Statement -
fi echo $num done
-

# Functions

-
Syntax :
-
function(){
+                
+
Syntax :
+
function(){
     #Statements
 }
-
Calling Function :
-
greet(){
+                    
Calling Function :
+
greet(){
     echo "Hello World"
 }
 
 greet
-
Function with Parameter :
-
greet(){
+                    
Function with Parameter :
+
greet(){
     echo "Hello $1"
 }
 
 greet World
-
Call within statement :
-
capital(){
+                    
Call within statement :
+
capital(){
     echo $1 | tr 'a-z' 'A-Z'
 }
 
 name="admin"
 echo "Capital: $(capital $name)"
-
Local Variables :
-

Local variables are defined within a function and have local scope. They are only accessible within the function where they are defined, not outside of it. It is declared with the local keyword.

-
swap(){
+                    
Local Variables :
+

Local variables are defined within a function and have local scope. They are only accessible within the function where they are defined, not outside of it. It is declared with the local keyword.

+
swap(){
     local t=$a
     a=$b
     b=$t
@@ -1358,129 +1334,132 @@ 
Local Variables :
printf "\nA = $a\nb = $b" swap printf "\nA = $a\nb = $b"
+

# Command Line Arguments

-

Also called shell script parameters.

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ArgumentsDescription
$0returns file name of script
basename $0filename of script without leading path
$[x]arguments pass to script/function
$#total number of arguments passed
$$PID of current shell
$!PID of last executed background process
$?exit status of last command/script executed (0 for success and 1 for failure)
$_command which is being executed previously
$∗returns all the arguments (in single string)
$@same as $∗, but differ when enclosed in (") (in array)
$-print the current options flags
+
+

Also called shell script parameters.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ArgumentsDescription
$0returns file name of script
basename $0filename of script without leading path
$[x]arguments pass to script/function
$#total number of arguments passed
$$PID of current shell
$!PID of last executed background process
$?exit status of last command/script executed (0 for success and 1 for failure)
$_command which is being executed previously
$∗returns all the arguments (in single string)
$@same as $∗, but differ when enclosed in (") (in array)
$-print the current options flags
+

# Output Redirection

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CommandsDescription
[command] > [file]redirect STDOUT to file
[command] 1> [file]redirect STDOUT to file (default file descriptor)
[command] 2> [file]redirect STDERR (standard error) to file
[command] &> [file]redirect STDOUT and STDERR to file
[command] > [file] 2>&1redirect STDOUT and STDERR to file
[command] >> [file]redirect and append STDOUT to file
[command] > /dev/nullredirect STDOUT to null (discard STDOUT)
[command] &> /dev/nullredirect STDOUT and STDERR to null
echo > [file]create empty file
> [file]create empty file
cat > [file]create file (CTRL+C to exit)
-
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CommandsDescription
[command] > [file]redirect STDOUT to file
[command] 1> [file]redirect STDOUT to file (default file descriptor)
[command] 2> [file]redirect STDERR (standard error) to file
[command] &> [file]redirect STDOUT and STDERR to file
[command] > [file] 2>&1redirect STDOUT and STDERR to file
[command] >> [file]redirect and append STDOUT to file
[command] > /dev/nullredirect STDOUT to null (discard STDOUT)
[command] &> /dev/nullredirect STDOUT and STDERR to null
echo > [file]create empty file
> [file]create empty file
cat > [file]create file (CTRL+C to exit)
+
-

NOTE : 0,1,2 are global file descriptors.

@@ -1506,9 +1485,7 @@

# Output Redirection

-
-
• Custom File Descriptor :

Define own file descriptor and redirect to it.

    @@ -1529,12 +1506,13 @@
    Ex :

    # Piping

    -

    Pipelines or pipes (|) are used as a funnel to pass the output of one command to another command as an input or parameter.

    -
    Syntax :
    -
    [command] | [command]
    +
    +

    Pipelines or pipes (|) are used as a funnel to pass the output of one command to another command as an input or parameter.

    +
    Syntax :
    +
    [command] | [command]
    -
    Ex :
    -
    # Output 1 page at time:
    +                    
    Ex :
    +
    # Output 1 page at time:
     ls -iR | less
     
     # Display 10 rows:
    @@ -1545,204 +1523,219 @@ 
    Ex :
    # Sort output file having word "index": grep -l index * | sort
    +

    # Bash Aliases

    -

    Redefine aliases by assigning commands to words or short-names as substitutions.

    -
    Synatx :
    -
    alias name='[command]'
    -

    Save aliases in the file .bashrc (in home directory) and execute the file with -

    -
    source .bashrc
    - -
    Ex :
    -
    alias cpp='g++ $1 && ./a.out && rm a.out'
    +
    +

    Redefine aliases by assigning commands to words or short-names as substitutions.

    +
    Synatx :
    +
    alias name='[command]'
    +

    Save aliases in the file .bashrc (in home directory) and execute the file with -

    +
    source .bashrc
    + +
    Ex :
    +
    alias cpp='g++ $1 && ./a.out && rm a.out'
    +

    # Brace Expansion

    -
      -
    • echo {1,2,3} : 1 2 3
    • -
    • echo {1..5} : 1 2 3 4 5
    • -
    • echo {5..1} : 5 4 3 2 1
    • -
    • echo {1..-3} : 1 0 -1 -2 -3
    • -
    • echo {1..10..2} : 1 3 5 7 9
    • -
    • echo {A..E} : A B C D E
    • -
    • echo {A..H..2} : A C E G
    • -
    • echo a{2..5}b : a2b a3b a4b a5b
    • -
    • echo a, b, c, d{1..3}, e : a, b, c, d1, d2, d3, e
    • -
    • echo {code1,code2,code3}.c : code1.c code2.c code3.c
    • -
    • echo code{.c,.cpp,.py,.sh} : code.c code.cpp code.py code.sh
    • -
    +
    +
      +
    • echo {1,2,3} : 1 2 3
    • +
    • echo {1..5} : 1 2 3 4 5
    • +
    • echo {5..1} : 5 4 3 2 1
    • +
    • echo {1..-3} : 1 0 -1 -2 -3
    • +
    • echo {1..10..2} : 1 3 5 7 9
    • +
    • echo {A..E} : A B C D E
    • +
    • echo {A..H..2} : A C E G
    • +
    • echo a{2..5}b : a2b a3b a4b a5b
    • +
    • echo a, b, c, d{1..3}, e : a, b, c, d1, d2, d3, e
    • +
    • echo {code1,code2,code3}.c : code1.c code2.c code3.c
    • +
    • echo code{.c,.cpp,.py,.sh} : code.c code.cpp code.py code.sh
    • +
    +

    # RegEx

    -

    A regular expression (shortened as regex) is a sequence of characters that defines a search pattern for use in pattern matching to find, match, or replace text.

    -
      -
    • grep ^The file.txt : print line start with "The"
    • -
    • grep The^ file.txt : print line end with "The"
    • -
    • grep [Hh]ello file.txt : print line with word "Hello" or "hello"
    • -
    • grep hello|HELLO file.txt : print line with word "hello" or "HELLO"
    • -
    • ls file[1-9] : print files with name file1 to file9
    • -
    • grep '[0-9][0-9][0-9][0-9]' file.txt : match for 4 digit number from file.txt with range 0-9
    • -
    • ls *[0-9]* : print files containing numbers 0 to 9 (file1.txt test2.sh note5.pdf test_20)
    • -
    • ls test.* : print files start with "test" (test.txt test.pdf)
    • -
    • ls ab* : print files start with "ab" (ab.txt abcd abort.sh)
    • -
    • ls {*.pdf,*.doc,*.exe} : print files end with .pdf/.doc/.exe (file.txt project.doc run.exe)
    • -
    • ls a[a-d]b : print files with name bet a[a to d]b (abd acd)
    • -
    • ls test_[!3] : print files with number except 3 (test_1 test_2 test_4)
    • -
    +
    +

    A regular expression (shortened as regex) is a sequence of characters that defines a search pattern for use in pattern matching to find, match, or replace text.

    +
      +
    • grep ^The file.txt : print line start with "The"
    • +
    • grep The^ file.txt : print line end with "The"
    • +
    • grep [Hh]ello file.txt : print line with word "Hello" or "hello"
    • +
    • grep hello|HELLO file.txt : print line with word "hello" or "HELLO"
    • +
    • ls file[1-9] : print files with name file1 to file9
    • +
    • grep '[0-9][0-9][0-9][0-9]' file.txt : match for 4 digit number from file.txt with range 0-9
    • +
    • ls *[0-9]* : print files containing numbers 0 to 9 (file1.txt test2.sh note5.pdf test_20)
    • +
    • ls test.* : print files start with "test" (test.txt test.pdf)
    • +
    • ls ab* : print files start with "ab" (ab.txt abcd abort.sh)
    • +
    • ls {*.pdf,*.doc,*.exe} : print files end with .pdf/.doc/.exe (file.txt project.doc run.exe)
    • +
    • ls a[a-d]b : print files with name bet a[a to d]b (abd acd)
    • +
    • ls test_[!3] : print files with number except 3 (test_1 test_2 test_4)
    • +
    +

    # Grep

    -

    Global regular expression print (grep) prints lines that match patterns from text or files.

    -
    Syntax :
    -
    grep -option [pattern] [file]
    -
      -
    • grep hello file.txt : match for word "hello" in file.txt and print matched line
    • -
    • grep -i hello file.txt : case insensitive match for "hello" in file.txt
    • -
    • grep -r hello file.txt : recursively match for "hello" in file.txt
    • -
    • grep -v hello * : match for all files & folders which doesn`t have word "hello"
    • -
    • grep -c hello file.txt : count occurance of "hello" in file.txt
    • -
    • grep -w hello file.txt : match for whole word "hello" in file.txt
    • -
    • grep -n hello file.txt : match for "hello" in file.txt and print line number with matched lines
    • -
    • grep -l hello * : match for "hello" in all files and print name of each matched files instead of matched line
    • -
    • grep -B 2 -A 3 hello file.txt : print before 2 lines and after 3 lines of matched case
    • -
    +
    +

    Global regular expression print (grep) prints lines that match patterns from text or files.

    +
    Syntax :
    +
    grep -option [pattern] [file]
    +
      +
    • grep hello file.txt : match for word "hello" in file.txt and print matched line
    • +
    • grep -i hello file.txt : case insensitive match for "hello" in file.txt
    • +
    • grep -r hello file.txt : recursively match for "hello" in file.txt
    • +
    • grep -v hello * : match for all files & folders which doesn`t have word "hello"
    • +
    • grep -c hello file.txt : count occurance of "hello" in file.txt
    • +
    • grep -w hello file.txt : match for whole word "hello" in file.txt
    • +
    • grep -n hello file.txt : match for "hello" in file.txt and print line number with matched lines
    • +
    • grep -l hello * : match for "hello" in all files and print name of each matched files instead of matched line
    • +
    • grep -B 2 -A 3 hello file.txt : print before 2 lines and after 3 lines of matched case
    • +
    +

    # Tr

    -

    Translate, squeeze, and/or delete characters from standard input and write them to standard output.

    -
    Syntax :
    -
    tr -option [string1] [string2]
    -
      -
    • tr "ab" "xy" <<< "abcd" : replace occurrence of "a" with "x" and "c" with "z"
    • -
    • tr [a-z] [A-Z] <<< "abcd" : convert lower case characters to upper case
    • -
    • tr [:lower:] [:upper:] <<< "abcd" : convert lower case characters to upper case
    • -
    • tr [:space:] "\t" <<< "Hello World" : translate white-space characters to tabs
    • -
    • tr -s [a-z] <<< "Hellooo Worrld" : squeeze sequence of repetitive characters using -s option and replaces with single occurrence of character
    • -
    • tr -d "l" <<< "Hello World" : delete specified characters using -d option
    • -
    • tr -d [:digit:] <<< "Hello 123 World6789" : remove all the digits from the string
    • -
    • tr -c "a" "x" <<< "ababc" : invert the selection by using -c option (complement)
    • -
    • tr -cd [:digit:] <<< "abc123def456" : delete everything except digits
    • -
    -
    Tokens :
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    TokenDescription
    CHAR1-CHAR2all characters from CHAR1 to CHAR2 in ascending order
    [CHAR*]in ARRAY2, copies of CHAR until length of ARRAY1
    [CHAR*REPEAT]REPEAT copies of CHAR, REPEAT octal if starting with 0
    [:alnum:]all letters and digits
    [:alpha:]all letters
    [:blank:]all horizontal whitespace
    [:cntrl:]all control characters
    [:digit:]all digits
    [:graph:]all printable characters, not including space
    [:lower:]all lower case letters
    [:print:]all printable characters, including space
    [:punct:]all punctuation characters
    [:space:]all horizontal or vertical whitespace
    [:upper:]all upper case letters
    [:xdigit:]all hexadecimal digits
    [=CHAR=]all characters which are equivalent to CHAR
    +
    +

    Translate, squeeze, and/or delete characters from standard input and write them to standard output.

    +
    Syntax :
    +
    tr -option [string1] [string2]
    +
      +
    • tr "ab" "xy" <<< "abcd" : replace occurrence of "a" with "x" and "c" with "z"
    • +
    • tr [a-z] [A-Z] <<< "abcd" : convert lower case characters to upper case
    • +
    • tr [:lower:] [:upper:] <<< "abcd" : convert lower case characters to upper case
    • +
    • tr [:space:] "\t" <<< "Hello World" : translate white-space characters to tabs
    • +
    • tr -s [a-z] <<< "Hellooo Worrld" : squeeze sequence of repetitive characters using -s option and replaces with single occurrence of character
    • +
    • tr -d "l" <<< "Hello World" : delete specified characters using -d option
    • +
    • tr -d [:digit:] <<< "Hello 123 World6789" : remove all the digits from the string
    • +
    • tr -c "a" "x" <<< "ababc" : invert the selection by using -c option (complement)
    • +
    • tr -cd [:digit:] <<< "abc123def456" : delete everything except digits
    • +
    +
    Tokens :
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TokenDescription
    CHAR1-CHAR2all characters from CHAR1 to CHAR2 in ascending order
    [CHAR*]in ARRAY2, copies of CHAR until length of ARRAY1
    [CHAR*REPEAT]REPEAT copies of CHAR, REPEAT octal if starting with 0
    [:alnum:]all letters and digits
    [:alpha:]all letters
    [:blank:]all horizontal whitespace
    [:cntrl:]all control characters
    [:digit:]all digits
    [:graph:]all printable characters, not including space
    [:lower:]all lower case letters
    [:print:]all printable characters, including space
    [:punct:]all punctuation characters
    [:space:]all horizontal or vertical whitespace
    [:upper:]all upper case letters
    [:xdigit:]all hexadecimal digits
    [=CHAR=]all characters which are equivalent to CHAR
    +

    # Find

    -

    It searches for files and directories in the directory hierarchy.

    -
    Syntax :
    -
    find [path] -option [file]
    -
      -
    • find . -name file.txt : find "file.txt" and is case sensitive
    • -
    • find . -iname file.txt : find "file.txt" and is case insensitive
    • -
    • find . -name "*.html" : find files end with ".html" and is case sensitive
    • -
    • find . -maxdepth 2 "*.cpp" : find files end with ".html" in 2 level depth only
    • -
    • find . -not "*.cpp" : find all files except those end with ".cpp"
    • -
    • find / -mtime 10 : find files that modified in last 10 days
    • -
    • find / -atime 10 : find files whose access time is within last 10 days
    • -
    • find / -cmin 10 : find files that created within last 10 days
    • -
    +
    +

    It searches for files and directories in the directory hierarchy.

    +
    Syntax :
    +
    find [path] -option [file]
    +
      +
    • find . -name file.txt : find "file.txt" and is case sensitive
    • +
    • find . -iname file.txt : find "file.txt" and is case insensitive
    • +
    • find . -name "*.html" : find files end with ".html" and is case sensitive
    • +
    • find . -maxdepth 2 "*.cpp" : find files end with ".html" in 2 level depth only
    • +
    • find . -not "*.cpp" : find all files except those end with ".cpp"
    • +
    • find / -mtime 10 : find files that modified in last 10 days
    • +
    • find / -atime 10 : find files whose access time is within last 10 days
    • +
    • find / -cmin 10 : find files that created within last 10 days
    • +
    +

    # Eval

    -

    Eval evaluates the specified parameters as a command.

    -
    Syntax :
    -
    eval [arg...]
    -
    Ex :
    -
    list="ls | more"
    -eval $list
    +
    +

    Eval evaluates the specified parameters as a command.

    +
    Syntax :
    +
    eval [arg...]
    +
    Ex :
    +
    list="ls | more"
    +    eval $list
    +

    # Expr

    -

    Expr evaluates a given expression and prints it to standard output.

    -
    Syntax :
    -
    expr [OPTION] [EXPRESSION]
    - -
    Ex :
    -
    # Example 1:
    +                
    +

    Expr evaluates a given expression and prints it to standard output.

    +
    Syntax :
    +
    expr [OPTION] [EXPRESSION]
    +
    Ex :
    +
    # Example 1:
     expr 1 + 2
     expr 5 - 3
     expr 2 \* 3
    @@ -1775,56 +1768,57 @@ 
    Ex :
    x="Hello World" c=$(expr index $x) echo $c
    +

    # File Permissions

    -

    Modifies file permissions.

    -
    Syntax :
    -
    chmod user+permission [file]
    -
    Change Permission Recursively :
    -
    chmod -R user+permission [file]
    -
    Format of Permission :
    -
    -rwx r-- r--
    -
      -
    • 1st bit is file type
    • -
    • 2nd 3 bits are user permission
    • -
    • 3rd 3 bits are group permission
    • -
    • 4th 3 bits are others permission
    • -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - -
    OptionsDescription
    File Type- (regular file), d (dir), c (block device), l (symbolic link)
    Setting Permission+ (add), - (remove), = (assign)
    Permissionr (read), w (write), x (execute), - (no permission)
    Owneru (user), g (group), o (other), a (all three)
    -
    -
    Ex :
    -
    chmod u+wr-r text.txt
    -chmod o+wrx script.sh
    +
    +

    Modifies file permissions.

    +
    Syntax :
    +
    chmod user+permission [file]
    +
    Change Permission Recursively :
    +
    chmod -R user+permission [file]
    +
    Format of Permission :
    +
    -rwx r-- r--
    +
      +
    • 1st bit is file type
    • +
    • 2nd 3 bits are user permission
    • +
    • 3rd 3 bits are group permission
    • +
    • 4th 3 bits are others permission
    • +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    OptionsDescription
    File Type- (regular file), d (dir), c (block device), l (symbolic link)
    Setting Permission+ (add), - (remove), = (assign)
    Permissionr (read), w (write), x (execute), - (no permission)
    Owneru (user), g (group), o (other), a (all three)
    +
    +
    Ex :
    +
    chmod u+wr-r text.txt
    +    chmod o+wrx script.sh
    -
    • Permission using Integers :
    @@ -1919,7 +1913,9 @@
    Ex :

    # Linux Filesystem Hierarchy

    -
    linux filesystem
    +
    + linux filesystem +