Advance Shell Commands
Advance Shell Commands
-----------------------------------------------------------------------------------
---------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
## 2. `xargs` — Execute Commands on Output
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
---
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
---
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
## What is it?
`grep` searches for patterns (strings or regex) in a file or output.
## When to use?
- Searching error logs.
- Filtering specific info from big outputs.
- Debugging configs.
## Why is it important?
Linux generates lots of logs/text — manual search is slow.
`grep` is fast & customizable with options.
## How to use?
Syntax:
grep [options] "pattern" filename
## Example 1 — Search for "ERROR" in logs
grep "ERROR" /var/log/syslog
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
## What is it?
`tar` creates or extracts archive files (.tar, .gz, .bz2).
## When to use?
- Backup files/directories.
- Move data between servers.
- Packaging multiple files.
## Why is it needed?
Multiple files → Single archive → Easy to move/backup.
## How to use?
### Syntax:
tar [options] [archive_name] [files]
Options:
- `c` = create
- `z` = gzip compression
- `v` = verbose (show progress)
- `f` = filename
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
## What is it?
`nc` (netcat) is a versatile tool for network communication & debugging.
---
## When to use?
- Check if port is open.
- Test network connectivity.
- Transfer files.
- Create simple chat between systems.
---
## Why is it powerful?
It's like a "Swiss Army Knife" for network troubleshooting.
---
## How to use?
### Syntax:
```bash
nc [options] [target_ip] [port]
```
---
---
#### On Sender:
```bash
nc target_ip 1234 < file_to_send.txt
```
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
## What is it?
`rsync` synchronizes files/directories between local & remote systems.
---
## When to use?
- Backup servers.
- Sync data to remote machine.
- Transfer big files efficiently.
---
---
## How to use?
Syntax:
rsync [options] source destination
```
---
---
---
## Summary Table: