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.
- 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 ErrorModule 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: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 :3. less Command
Used to read large files page by page.
less filename.txtControls:
Enter→ next line
Space→ next page
q→ quit
Below is Link :
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?
lsgenerated the list of files.
- Normally, that output goes to the terminal (stdout).
>changed the destination from the terminal tooutput.txt.
output.txtnow contains exactly whatlswould have displayed on the screen.
Flow:
Loading... Below is Link:
In depth:2. Error Redirection (2>)
Redirect errors into a file.
Example:
ls -z 2> e.txtExplanation:
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 -zuses an invalid option (z).
- Instead of normal output,
lsgenerates an error message.
- Errors are sent to stderr (File Descriptor 2).
2>redirects stderr from the terminal intoe.txt.
- The file
e.txtnow contains the error message.
Flow:
Loading...3. Append Output (>>)
echo "Hello" >> file.txtExample :
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"writesHelloto stdout.
>>redirects stdout tofile.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 | command2Example:
ls | grep txt Below is Link :
Detailed explanation of Pipe (|) operator:2. grep Command
Used to search text/pattern.
grep "word" filenameExample:
grep "hello" data.txt 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.txt2. file Command
Identifies file type.
file filename Example:
file image.pngModule 7: Shell Operators
1. Subshell ()
Loading...Runs commands in separate shell.
2. && Operator
Second command runs only if first command succeeds.
mkdir test && cd test3. ; Operator
Runs commands one after another regardless of success.
pwd ; ls4. || 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 usingrmdo 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
.jpg?table=block&id=29d76b1d-f1a8-8072-a9bf-cc78d1c7d881&cache=v2)
