u/Expensive-Rice-2052

Quick Linux Tip #13
Question: I deleted a log file but the app is still writing to it. Can I recover it?

Quick Linux Tip #13 Question: I deleted a log file but the app is still writing to it. Can I recover it?

Try: sudo ls -la /proc/1234/fd/

Info: Linux keeps deleted files on disk while any process has them open. /proc/PID/fd/ shows file descriptors with (deleted) marker for such files. Copy from there to recover.

Examples:

$ sudo lsof +L1 # Find all deleted-but-open files

$ sudo ls -la /proc/$(pgrep nginx)/fd/

$ sudo cp /proc/1234/fd/1 recovered.log

Note: Two steps: identify FD number, then copy. Works only while process runs. Restarting the process = data lost forever.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 3 hours ago

Quick Linux Tip #12 Question: How do I find which process is slowly eating my RAM?

Try: watch -n 5 'ps -eo pid,user,vsz,rss,comm --sort=-rss | head -20'

Info: watch runs the command repeatedly showing memory trends. RSS shows physical memory in KB. If a process's RSS keeps growing, you have a leak.

Examples:

$ watch -n 1 'free -m'

$ smem -tk -s rss # More accurate memory reporting

$ sudo pmap -x 1234 | tail -1 # Detailed memory map

Note: smem is more accurate than ps for shared memory. Install: apt install smem. Monitor over hours to detect slow leaks.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 1 day ago

Quick Linux Tip #11 Question: How do I debug a running process without stopping it?

Try: sudo gdb -p 1234 -batch -ex 'thread apply all bt' -ex 'quit'

Info: gdb can attach to running processes and dump stack traces without stopping them. Essential for debugging production issues where you cannot restart the service.

Examples:

$ sudo gdb -p $(pgrep nginx) -batch -ex 'bt'

$ sudo strace -p 1234 -f -e trace=network

$ sudo perf record -p 1234 -g sleep 30

Note: gdb briefly pauses the process. For production, use 'perf' or 'strace' for less impact. Requires debug symbols for best results.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 2 days ago

Quick Linux Tip #10 Question: How do I capture only specific HTTP traffic to a specific host?

Try: sudo tcpdump -i eth0 -w capture.pcap 'host 192.168.1.100 and port 80 and tcp[13] & 2 != 0'

Info: tcpdump captures network packets with BPF filters. This example captures only SYN packets (TCP handshake start) to a specific host on port 80. Perfect for debugging network issues.

Examples:

$ sudo tcpdump -i any -n 'port 443 and host github.com'

$ sudo tcpdump -i eth0 -A 'tcp port 80' # Show ASCII payload

$ sudo tcpdump -r capture.pcap 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn'

Note: Use -w to save, -r to read pcap files. BPF filters: 'tcp[13] & 2' checks SYN flag. Open .pcap files in Wireshark for GUI analysis.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 3 days ago

Quick Linux Tip #9 Question: How do I see all processes with their container and resource limits?

Try: systemd-cgls --unit=docker.service

Info: systemd-cgls shows the cgroup tree with all processes organized by their control groups. Perfect for understanding container isolation and resource allocation.

Examples:

$ systemd-cgls --unit=user.slice

$ systemd-cgtop # Real-time cgroup resource usage

$ cat /proc/1234/cgroup # Show cgroups for specific PID

Note: Understand container resource isolation. Combine with 'systemd-cgtop' for real-time CPU/memory per cgroup. Essential for container troubleshooting.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 4 days ago

Quick Linux Tip #8 Question: How do I who modified a critical file and when?

Try: sudo auditctl -w /etc/passwd -p wa -k passwd_changes

Info: auditd is Linux's audit framework. auditctl sets up a real-time watch on a file silently. You then use ausearch later to query those logs.

Examples:

$ sudo auditctl -w /etc/shadow -p rwxa -k shadow_access

$ sudo ausearch -k passwd_changes -ts today

$ sudo aureport --file --summary

Note: Requires auditd service. auditctl commands run silently and log events in the background. Use ausearch -k <key> later to inspect the generated logs when a file is changed.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 5 days ago

Quick Linux Tip #7 Question: How do I speed up processing many files using all CPU cores?

Try: find /images -name '*.jpg' | parallel -j+0 'convert {} -resize 800x600 {}.resized'

Info: GNU parallel executes commands in parallel across all CPU cores. Dramatically speeds up batch processing of files, downloads, or any repeatable task.

Examples:

$ parallel -j 4 gzip ::: *.log

$ cat urls.txt | parallel -j 10 wget {}

$ find . -name '*.mp4' | parallel ffmpeg -i {} -vcodec h264 {.}.mp4

Note:Install: apt install parallel. -j+0 uses all cores, -j N uses N processes. ::: passes arguments directly. Perfect for CPU-intensive tasks.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 6 days ago

Quick Linux Tip #6 Question: What files is a specific process using?

Try: lsof -p 3456

Info: lsof shows all files, sockets, and connections used by a process. Great for troubleshooting.

Examples:

$ lsof -p 3456

$ lsof -i :8080

$ lsof -u username

Note:Use -i for network connections. -i :PORT shows process using that port.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 7 days ago

Quick Linux Tip #4 Question:How long does my script take and how much CPU does it use?

Try:time ./backup.sh

Info:time command shows execution time. real=wall clock, user=CPU for program, sys=CPU for system calls.

Examples:

$ time ./deploy.sh

$ /usr/bin/time -v ./process.py

$ time tar -czf backup.tar.gz /home/data

Note:Use /usr/bin/time -v for detailed resource usage including memory.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 9 days ago

Quick Linux Tip #3 Question:How do I backup files fast, only copying changes?

Try: rsync -avz --delete /source/ /destination/

Info: rsync only transfers changed files, making backups much faster. -a archive, -v verbose, -z compress.

Examples:

$ rsync -avz /home/user/ /mnt/backup/

$ rsync -avz --delete remote:/data/ /local/backup/

$ rsync -avz --exclude='*.tmp' /src/ /dst/

Note: Use --dry-run first. A trailing slash (/source/) copies contents; omitting it (/source) copies the folder itself.

Follow r/LinuxTeck for more #LinuxTips

u/Expensive-Rice-2052 — 10 days ago