Sitemap
Azizou GNANKPE

Azizou GNANKPE

Microsoft MVP & MIE Expert | Cloud & Systems Engineer | Azure Security & Solutions

ADVANCED LINUX COMMANDS

3 min readJun 7, 2024

Sed: Stream Editor for Filtering and Transforming Text

The `sed` command is a powerful stream editor used for parsing and transforming text. It can perform basic text transformations on an input stream (a file or input from a pipeline).

Replace all occurrences of "apple" with "orange" on fruits.txt file.

sed 's/apple/orange/g' fruits.txt

Press enter or click to view image in full size

- 's': Substitute command.
- 'apple': The search pattern.
- 'orange': The replacement string.
- 'g' : Global replacement (replaces all occurrences in each line).

Find: Searches for Files in a Directory Hierarchy**

The `find` command searches for files and directories in a directory hierarchy based on various criteria.

Find all `.mp4` files in the current directory and its subdirectories.
find . -name "*.mp4"

Press enter or click to view image in full size

- '.': Start searching in the current directory.
- -name "*.mp4": Search for files with a `.txt` extension.

Tar: Archives Multiple Files into a Single File

The `tar` command is used to create, maintain, modify, and extract files from a tar archive file.

Create a tar archive of the bigfolderdirectory.

tar -cvf bigfolder.tar bigfolder

Press enter or click to view image in full size
Command executed
Press enter or click to view image in full size
Archive created

- `-c`: Create a new archive.
- `-v`: Verbose mode (lists files being processed).
- `-f`: Specifies the archive file name (`bigfolder.tar`).

Get Azizou GNANKPE’s stories in your inbox

Join Medium for free to get updates from this writer.

Extract a tar archive.

tar -xvf bigfolder.tar > nonarchive

Press enter or click to view image in full size

- `-x`: Extract files from an archive.
- `-v`: Verbose mode.
- `-f`: Specifies the archive file name (bigfolder.tar).

- `> nonarchive`: store the upout on nonarchive file

xargs

The xargs command builds and executes command lines from standard input. It is useful for passing arguments to commands that do not accept standard input directly.

  • Example: find . -name "*.mp4" | xargs rm deletes all .mp4 files found by find.
Press enter or click to view image in full size

Piping

  • Piping (|): Connects the output of one command to the input of another. For example, ps aux | grep antispam filters the output of ps aux to show only lines containing "antispam".
Press enter or click to view image in full size

Chaining Commands

  • Chaining Commands (&&, ||): Executes multiple commands in sequence.

For example, command1 && command2 runs command2 only if command1 succeeds.

Press enter or click to view image in full size

For example, try to remove a file, or print a message if it doesn’t exist.

Press enter or click to view image in full size

These advanced commands are essential tools for text processing, file searching, and archiving in Linux.

By mastering these commands, you can efficiently manage and manipulate data on a Linux system.

Congrats!! You have learned some of the advanced command in Linux.

--

--

Azizou GNANKPE
Azizou GNANKPE

Written by Azizou GNANKPE

Microsoft MVP & MIE Expert | Cloud & Systems Engineer | Azure Security & Solutions