ADVANCED LINUX COMMANDS
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
- '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"
- '.': 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
- `-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
- `-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 rmdeletes all.mp4files found byfind.
Piping
- Piping (
|): Connects the output of one command to the input of another. For example,ps aux | grep antispamfilters the output ofps auxto show only lines containing "antispam".
Chaining Commands
- Chaining Commands (
&&,||): Executes multiple commands in sequence.
For example, command1 && command2 runs command2 only if command1 succeeds.
For example, try to remove a file, or print a message if it doesn’t exist.
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.









