← Back to list

2 Linux Commands That Saved Me a Lot of Time

As a Linux user, I often find myself caught up in the minutiae of system management, trying to track down processes, directories, and…

Shayan Nazar · 2024-10-26 13:42 · 0 claps · 2.3 min read
#linux #devops #lsof #grep #cloud
Open on Medium ↗
Wiki topics: BIZ · Business Strategy ☁️ · DevOps & Cloud 🔓 · Open Source 🎬 · Film & Television 🥊 · Combat Sports

2 Linux Commands That Saved Me a Lot of Time

As a Linux user, I often find myself caught up in the minutiae of system management, trying to track down processes, directories, and everything in between. However, two commands have truly transformed my workflow and saved me heaps of time: lsof and pgrep. Let me share how they have made my life easier!

lsof – A Lifesaver for Directory Insights

Before I discovered lsof, checking which processes were using a specific directory felt like searching for a needle in a haystack. I would usually resort to using top to see active processes and their IDs, which was not only time-consuming but also a bit frustrating. I’d scroll through the list, hunting for the process I needed and often had to go through several steps to correlate the IDs to the directory I was interested in.

Then came lsof (short for "list open files"). With just a simple command like:

lsof /path/to/dir

I could immediately see all the processes that had files open in that directory. This single command has saved me tons of time and has allowed me to be far more efficient. No more tedious scrolling through process lists or playing detective! Instead, I get a clear snapshot of everything accessing that directory. It’s like having a magical window into my system’s activity!

More Use Cases for lsof

  1. Network Connections: I often need to troubleshoot network issues. Running lsof -i helps me see which processes are using network ports, allowing me to quickly identify any rogue applications.
  2. File Access Issues: If I need to delete or move a file, but it’s in use, I can run lsof to find out what’s holding it up. This way, I can make informed decisions about stopping processes or closing applications before proceeding.

pgrep – The Streamlined Process Finder

Next up is pgrep. Previously, if I wanted to check if a specific process was running, I would execute:

ps -ef | grep <process name>

While this works, it felt a bit clunky, and I always had to deal with the extra lines from the grep command itself. Enter pgrep, which simplifies the process. With just

pgrep <process name>

I get a clean output of all the matching process IDs without any extra noise. This little command has sped up my troubleshooting times significantly.

More Use Cases for pgrep

  1. Killing Processes: If I want to kill a process, I can combine pgrep with pkill like this:
  • pkill -f <process name>

This command allows me to terminate processes with ease, saving me from the hassle of finding specific PIDs manually.

2. Batch Monitoring: I sometimes have to monitor multiple instances of a service. Instead of checking each one with ps, I can use pgrep -c <service name> to count how many instances are running. This gives me a quick overview without digging deep into the details.

Final Thoughts

Both lsof and pgrep have dramatically improved my efficiency while working with Linux. They cut down the time I spend searching for information and troubleshooting issues, allowing me to focus on what really matters—getting things done! If you haven’t tried these commands yet, I highly recommend giving them a shot. You’ll wonder how you ever lived without them! Happy Linuxing!


메타데이터
post_id
1a5cd8d2bfd9
slug
2-linux-commands-that-saved-me-a-lot-of-time-1a5cd8d2bfd9
url
https://medium.com/@shyrradev/2-linux-commands-that-saved-me-a-lot-of-time-1a5cd8d2bfd9
canonical_url
https://medium.com/@shyrradev/2-linux-commands-that-saved-me-a-lot-of-time-1a5cd8d2bfd9
author_url
https://medium.com/@shyrradev
status
ok
fetched_at
2026-06-20 20:29:01