Back to DevOps Series
Some Advance Commands :

Some Advance Commands :

Module 1: Standard Input, Output, and Error

Standard Input (stdin), Standard Output (stdout), and Standard Error (stderr) are the three standard streams automatically created and provided by the operating system to every program when it starts executing.
These streams provide a standard way for a program to communicate with the outside world:
  • receive input,
  • display normal output,
  • and report errors.
 
  1. Standard Input, Output, and Error
      • Standard Input (stdin)
      • Standard Output (stdout)
      • Standard Error (stderr)
  • Below is Important Explanation :
 

Below is Link:
Standard Input, Standard Output, and Standard Error
Standard Input, Standard Output, and Standard Error

Module 2: File Viewing Commands

  • All Code related to this concept is present below :

1. head Command

Used to display first few lines of a file.
head filename.txt
  • Example: head data.txt
Below is Link:
How to use Head Full explain:
How to use Head Full explain:
 

2. tail Command

Used to display last few lines of a file.
tail filename.txt
  • Example: tail log.txt
Below is Link:
How to use Tail Command in detail :
How to use Tail Command in detail :

3. less Command

Used to read large files page by page.
less filename.txt
Controls:
  • Enter → next line
  • Space → next page
  • q → quit
Below is Link :
How to use less Command :
How to use less Command :

Module 3: Redirection

1. Output Redirection (>)

Redirect output into a file.
ls > output.txt
This above command just put the output of ls into output.txt as it is.
Example :
Suppose your current directory contains these files:
Loading...
Now run:
Loading...
Nothing is printed on the terminal because the output is redirected to the file.
If you now view the file:
Loading...
Output:
Loading...

What happened?

  • ls generated the list of files.
  • Normally, that output goes to the terminal (stdout).
  • > changed the destination from the terminal to output.txt.
  • output.txt now contains exactly what ls would have displayed on the screen.
Flow:
Loading...

Below is Link:
In depth:
In depth:

2. Error Redirection (2>)

Redirect errors into a file.
Example: ls -z 2> e.txt
Explanation:
  • ls -z → invalid option generates error
  • 2> → redirects error
  • e.txt → stores error message
Example :
Redirect the error output (stderr) of a command into a file.
Example:
Loading...
Nothing is printed on the terminal because the error is redirected to e.txt.
Now view the file:
Loading...
Output:
Loading...

What happened?

  • ls -z uses an invalid option (z).
  • Instead of normal output, ls generates an error message.
  • Errors are sent to stderr (File Descriptor 2).
  • 2> redirects stderr from the terminal into e.txt.
  • The file e.txt now contains the error message.
Flow:
Loading...

3. Append Output (>>)

echo "Hello" >> file.txt
Example :
Append the standard output (stdout) of a command to the end of a file without removing its existing content.
Example:
Suppose file.txt already contains:
Loading...
Now run:
Loading...
View the file:
Loading...
Output:
Loading...
Run the command again:
Loading...
Now check the file:
Loading...
Output:
Loading...

What happened?

  • echo "Hello" writes Hello to stdout.
  • >> redirects stdout to file.txt.
  • If the file already exists, its existing content is preserved.
  • The new output is added (appended) to the end of the file.
Flow:
Loading...

Module 4: Pipe & Grep

1. Pipe (|)

Used to send output of one command to another command.
command1 | command2
Example:
ls | grep txt
Below is Link :
Detailed explanation of Pipe (|) operator:
Detailed explanation of Pipe (|) operator:

2. grep Command

Used to search text/pattern.
grep "word" filename
Example: grep "hello" data.txt
 
grep Command full explanation :
grep Command full explanation :

Module 5: Arithmetic in Linux

Arithmetic Operations

Loading...

Module 6: File Information Commands

1. stat Command

Displays detailed file information.
stat filename
  • Shows:
    • File size
    • Permissions
    • Access time
    • Modify time
Example: stat data.txt

2. file Command

Identifies file type.
file filename
Example: file image.png

Module 7: Shell Operators

1. Subshell ()

Loading...
Runs commands in separate shell.

2. && Operator

Second command runs only if first command succeeds.
mkdir test && cd test

3. ; Operator

Runs commands one after another regardless of success.
pwd ; ls

4. || Operator

Second command runs only if first command fails.
mkdir test || echo "Failed"

Module 8: Dollar ($) Sign Usage

1. Variable Access

Loading...

2. Command Substitution

Loading...

3. Arithmetic

Loading...

Module 9: Remove (rm) Command

Important: Files deleted using rm do NOT go to recycle bin.

1. Remove Empty Directory

Loading...

2. Recursive Delete

Loading...
Deletes directory and all files inside it.

3. Delete Multiple Files

Loading...
Deletes files:
  • a
  • b
  • c