Thursday, 30 November 2023   |

Blog - Linux Shortcut

How to Use ‘tee’ Command in Linux


The `tee` command in Linux is used to read from standard input and write to standard output and files simultaneously. It allows you to redirect the output of a command to both the screen and one or more files. Here's how you can use the `tee` command:

1. Basic usage:
   ```
   command | tee file.txt
   ```

   This command takes the output of `command` and writes it to both the screen and the `file.txt`. You can replace `command` with any command or pipeline.

2. Appending to a file:
   ```
   command | tee -a file.txt


Date: 20 June 2023    Comments: 0

How to Cut Sections of Line in File in linux


To cut sections of a line in a file in Linux, you can use the `cut` command. The `cut` command is primarily used to extract specific columns or sections from lines of input.

Here's the basic syntax of the `cut` command:

```
cut -c start-end file
```

where:
- `-c` specifies that you want to cut based on characters.
- `start-end` represents the range of characters you want to extract. Replace `start` with the starting position and `end` with the ending position of the section you want to cut.
- `file` is the name of the file you want to perform the operation on.

For example, let's say you have a file named ...


Date: 20 June 2023    Comments: 0

How to Print Last 10 Lines of Files in Linux


To print the last 10 lines of a file in Linux, you can use the `tail` command with the `-n` option. Here's how you can do it:

```
tail -n 10 filename
```

Replace `filename` with the actual name of the file you want to display the last 10 lines of. The `tail` command outputs the last part of a file by default, and the `-n` option specifies the number of lines to display (in this case, 10).

If you want to continuously monitor a file and display the last 10 lines as new lines are added to it, you can use the `-f` option along with `tail`. This is useful, for example, when monitoring log files:

```
tail -f -n 10 filename


Date: 20 June 2023    Comments: 0

How to Print First 10 Lines of Files in Linux


To print the first 10 lines of a file in Linux, you can use the `head` command. The `head` command displays the beginning of a file or input.

Here's how you can use it to print the first 10 lines of a file:

```shell
head -n 10 filename
```

Replace `filename` with the actual name or path to the file you want to print the lines from.

For example, if you have a file called `example.txt` and you want to print the first 10 lines, you would use the following command:

```shell
head -n 10 example.txt
```

This will display the first 10 lines of the `example.txt` file on your terminal.


Date: 20 June 2023    Comments: 0

How to Search Text or String in Files on Linux


To search for text or strings within files on Linux, you can use the `grep` command. `grep` stands for "global regular expression print" and is a powerful tool for searching patterns in files.

Here's the basic syntax to search for text in files using `grep`:

```
grep [options] pattern [file...]
```

Let's break it down:

- `[options]`: You can use various options with `grep` to modify its behavior. Some commonly used options include:
  - `-i` or `--ignore-case`: Ignore case distinctions in both the pattern and input files.
  - `-r` or `-R` or `--recursive`: Search files recursively in ...


Date: 20 June 2023    Comments: 0

How to Use the Gzip Command in Linux


The `gzip` command is a popular tool used in Linux for file compression. It allows you to compress and decompress files using the gzip compression algorithm. Here's how you can use the `gzip` command:

1. **Compression**: To compress a file, use the following syntax:
   ```
   gzip [options] [filename]
   ```
   For example, to compress a file named "example.txt," you would run:
   ```
   gzip example.txt
   ```
   This command will create a compressed file named ...


Date: 20 June 2023    Comments: 0

1 2 3 4 Next Last