# 8 Shell Commands for Homelab Users

**URL:** <https://forum.hhf.technology/t/8-shell-commands-for-homelab-users/337>\
**Category:** General\
**Tags:** self-managed, ssh, ubuntu\
**Created:** [November 2, 2024, 1:24pm UTC](https://forum.hhf.technology/t/8-shell-commands-for-homelab-users/337 "2024-11-02T13:24:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhf.technoloy](https://forum.hhf.technology/user_avatar/forum.hhf.technology/hhf.technoloy/32/68_2.png) [@hhf.technoloy](https://forum.hhf.technology/u/hhf.technoloy)\
**Post date:** [November 2, 2024, 1:24pm UTC](https://forum.hhf.technology/t/8-shell-commands-for-homelab-users/337/1 "2024-11-02T13:24:18Z")

</div>

Here are my top 8 advanced shell commands, with practical examples to up your terminal game, I hope they’re as useful to you as they are to me.

**1.**  **`grep`** – **Search for patterns in files or output**

Example: Search for the word “error” in log files.

 ![image](https://forum-cdn.hhf.technology/original/1X/cf97ab47d3847d06ea754bd2a5f6905d6bdc8049.png)

```bash
grep "error" /var/log/syslog

```

Search recursively for a pattern in all files within a directory:

 ![image](https://forum-cdn.hhf.technology/original/1X/a0d891fd5bfff634869306bb551fe57d7f9d1512.png)

```bash
grep -r "TODO" /path/to/codebase/

```

**2.**  **`awk`** – **Process and analyze text data**

Example: Print the second column from a file with space-separated values:

 ![image](https://forum-cdn.hhf.technology/original/1X/e7b86facffb60f5670aaa36cc07f5e3a7aaf4895.png)

 ![image](https://forum-cdn.hhf.technology/original/1X/327212e9d8c7970316c7b2a46a820c8a1c47cdb6.png)

```bash
awk '{print $2}' data.txt

```

Extract and summarize disk usage from the `df` command:

 ![image](https://forum-cdn.hhf.technology/original/1X/d186f64aa7e9ff359bc4abaaf5a5fd7adaec34ff.png)

```bash
df -h | awk '{print $5 " " $1}'

```

**3.**  **`sed`** – **Stream editor for modifying files or input**

Example: Replace the word “cat” with “dog” in a file called _ **animals.txt** _:

 ![image](https://forum-cdn.hhf.technology/original/1X/e5c7567cae61ef04569da511253451f7ec09f5d8.png)

```bash
sed 's/cat/dog/g' animals.txt

```

Delete lines containing a specific word, in this case “error”:

 ![image](https://forum-cdn.hhf.technology/original/1X/fec4b8d8b3055c370ca60d729b0e47f1a14c1b76.png)

```bash
sed '/error/d' logfile.txt

```

**4.**  **`xargs`** – **Pass output as arguments to another command**

Example: Delete all files that has extension `.log` in the current directory ( **Use this very carefully** )!:

```bash
find . -name "*.log" | xargs rm

```

Or, if filenames contain spaces:

```bash
find . -name "*.log" -print0 | xargs -0 rm

```

**5.**  **`find`** – **Search for files based on criteria**

Example: Find all `.txt` files modified in the last 7 days:

 ![image](https://forum-cdn.hhf.technology/original/1X/7309e00762b938e2b7ab570e60e6e40bce83c707.png)

```bash
find /path/to/dir -name "*.txt" -mtime -7

```

Find files larger than 100MB:

```bash
find /path/to/dir -type f -size +100M

```

**6.**  **`rsync`** – **Efficient file synchronization**

Example: Sync a local directory to a remote server:

```bash
rsync -avz /local/dir/ user@remote:/remote/dir/

```

Sync while excluding specific files:

```bash
rsync -avz --exclude '*.tmp' /local/dir/ user@remote:/remote/dir/

```

**7.**  **`tmux`** – **Terminal multiplexer for managing multiple sessions**

Example: Start a new `tmux` session:

```bash
tmux new -s mysession

```

Detach from the session without killing it:

```bash
Ctrl + b, then d

```

Reattach to the session later:

```bash
tmux attach -t mysession

```

**8.**  **`lsof`** – **List open files and processes using them**

Example: List all open files on the system:

 ![image](https://forum-cdn.hhf.technology/original/1X/c99e54bdd71419305a015162defcc37a45e878ff.png)

```bash
lsof

```

Find out which process is using a specific port (e.g., port 8080):

```bash
lsof -i :8080

```

Identify files opened by a specific user:

```bash
lsof -u username

```

### In Conclusion

Think of it as a journey rather than a destination.

I started small (and you should too), experimenting with just a couple of commands that seemed useful for my projects. Before long, I was stringing commands together, automating processes I never thought possible. It was like having a superpower! I can’t stress enough how important it is to practice and find what works best for you.

If you find these commands helpful. I will keep adding more

---

<div class="post-metadata">

**Author:** ![gyrene2083](https://forum.hhf.technology/user_avatar/forum.hhf.technology/gyrene2083/32/67_2.png) [@gyrene2083](https://forum.hhf.technology/u/gyrene2083)\
**Post date:** [November 3, 2024, 3:39am UTC](https://forum.hhf.technology/t/8-shell-commands-for-homelab-users/337/2 "2024-11-03T03:39:41Z")

</div>

These little nuggets are awesome and should be in everyones toolbox. Thank you.
