Linux

Linux Tutorial for Beginners in Hindi πŸ”₯| Full Linux Course With Commands | PART 13



The nohup command is used to run a process in the background and keep it running even if the terminal is closed. Additionally, redirecting the output to /dev/null ensures that the process doesn’t get interrupted by hangups (SIGHUP signals) and that its output is discarded.

Here are the two commonly used forms:

1. Using nohup process &:
bash
Copy code
nohup command &
This runs the specified command in the background, and the nohup ensures that the command ignores the SIGHUP signal. The output is redirected to a file named nohup.out in the current directory.

Example:
bash
Copy code
nohup ./my_script.sh &
2. Using nohup process &gt /dev/null 2&gt&1 &:
bash
Copy code
nohup command &gt /dev/null 2&gt&1 &
This form not only runs the command in the background and ignores the SIGHUP signal but also redirects both standard output (stdout) and standard error (stderr) to /dev/null. This ensures that no output is written to any file.

Example:
bash
Copy code
nohup ./my_script.sh &gt /dev/null 2&gt&1 &
These commands are often used when you want to start a long-running process, and you don’t want it to be terminated if the terminal is closed. The nohup command is particularly useful for running background processes in the context of system administration or remote sessions.
The lsblk command in Linux is used to list information about block devices, including details about partitions and their file systems. When used with the -f option, lsblk displays information about the file system of each block device.

Basic Syntax:
bash
Copy code
lsblk -f
Example Output:
The output of lsblk -f provides information about block devices, their partitions, and the associated file systems. Here is an example:

plaintext
Copy code
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
β”œβ”€sda1 ext4 12345678-1234-1234-1234-123456789abc /boot
β”œβ”€sda2 swap 87654321-4321-4321-4321-987654321cba [SWAP]
└─sda3 ext4 root abcdef01-2345-2345-2345-0123456789ab /
sdb
└─sdb1 ntfs Data 5A94F16C94F14D13
Explanation of Columns:
NAME: The block device name.
FSTYPE: The file system type.
LABEL: The volume label of the file system.
UUID: The universally unique identifier of the file system.
MOUNTPOINT: The mount point where the file system is mounted.
Interpretation of Output:
sda, sdb: These are block devices. In the example, sda and sdb are two different physical disks.
sda1, sda2, sda3: These are partitions on the sda disk.
ext4, swap, ntfs: These are the file system types of the partitions.
/boot, [SWAP], /: These are the mount points of the file systems.
Common Options:
-a or –all: Display all block devices, including those without mounted file systems.
-l or –list: Display additional details, including size, model, and serial number.
-o or –output: Specify the columns to be displayed.
Examples:
Display All Block Devices:

bash
Copy code
lsblk -fa
Display Additional Details:

bash
Copy code
lsblk -fl
Customize Output Columns:

bash
Copy code
lsblk -fo NAME,FSTYPE,LABEL,MOUNTPOINT

The grep command in Unix/Linux is a powerful utility for searching through text using regular expressions. It is commonly used to filter and display lines in a file that match a specified pattern or regular expression.

Basic Syntax:
bash
Copy code
grep [options] pattern [file(s)]
pattern: The regular expression or string to search for.
file(s): The file or files to search. If not specified, grep reads from standard input.
Examples:
Search for a String in a File:

bash
Copy code
grep “search_string” filename.txt
Case-Insensitive Search:

bash
Copy code
grep -i “pattern” filename.txt
Display Line Numbers:

bash
Copy code
grep -n “pattern” filename.txt
Recursive Search in Directories:

bash
Copy code
grep -r “pattern” directory/
Difference Between grep and egrep:
Both grep and egrep (extended grep) are used for pattern matching, but egrep supports extended regular expressions without needing to escape certain characters. In modern versions of grep, the -E option can be used to enable extended regular expressions, making grep and egrep essentially equivalent.

[ad_2]

source

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button