Fundamentals 10 min read

20 Essential Unix Command-Line Tricks Every Sysadmin Should Know

A concise collection of practical Unix/Linux command-line tips—including file deletion, output logging, terminal recording, permission handling, and more—designed to boost productivity and simplify common system administration tasks.

ITPUB
ITPUB
ITPUB
20 Essential Unix Command-Line Tricks Every Sysadmin Should Know

1. Quickly delete a large file

Truncate the file without reading its contents, then remove it:

: > /path/to/file.log
rm /path/to/file.log

2. Record a terminal session

Use script to capture all input and output. script my.terminal.session Run commands, then end the recording with exit or Ctrl‑D. View the log with more, less or cat.

3. Recreate a deleted /tmp directory

mkdir /tmp
chmod 1777 /tmp
chown root:root /tmp
ls -ld /tmp

4. Temporarily lock a directory

Set restrictive permissions and later restore them:

chmod 0000 /downloads   # lock
chmod 0755 /downloads   # unlock

5. Password‑protect a file in Vim

vim +X filename   # prompt for password on exit
# or, inside Vim: :X

6. Clear a garbled terminal screen

reset

7. Produce human‑readable output

Add -h (or -H) to GNU/BSD utilities:

ls -lh
df -h

(or df -k)

du -h
free -b

, -k, -m,

-g
stat -c %A /boot

8. List known user accounts

Linux: lslogins BSD:

logins

9. Remove files accidentally extracted from a tarball

cd /var/www/html/
/bin/rm -f "$(tar ztf /path/to/file.tar.gz)"

10. Better interactive process viewer

sudo htop

11. Repeat the last command

!!

– repeat entire command sudo !! – repeat as root !foo – repeat most recent command starting with

foo
!$

– reuse last argument

12. Schedule a terminal reminder

leave +hhmm

Replace hhmm with the desired time (12‑hour clock, interpreted as the next occurrence within 12 hours).

13. Return to the previous or home directory

cd -

– go back to the last directory cd – go to $HOME Define shortcut search paths with CDPATH:

export CDPATH=/var/www:/nas10
cd html   # jumps to /var/www/html

14. Edit a file while viewing it with less

Press v inside less to open the file in the editor defined by $EDITOR.

15. List all directories or files

# List all directories
find / -type d | less
# List directories under $HOME with details
find $HOME -type d -ls | less
# List all files
find / -type f | less
# List files under $HOME with details
find $HOME -type f -ls | less

16. Create a full directory tree

mkdir -p /jail/{dev,bin,sbin,etc,usr,lib,lib64}
ls -l /jail/

17. Copy a file to multiple destinations

echo /usr/dir1 /var/dir2 /nas/dir3 | xargs -n 1 cp -v /path/to/file

18. Compare two directories

diff /tmp/r/ /tmp/s/

Use diff to show line‑by‑line differences between the contents of the two directories.

19. Reformat text

fmt file.txt          # reflow paragraphs
fmt -s file.txt      # split long lines without re‑justifying

20. View output while saving to a file

mycoolapp arg1 arg2 input.file | tee my.log
tee

displays the command’s output on the terminal and writes the same data to my.log simultaneously.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxProductivityCommand-lineUnixSystem AdministrationShell Tips
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.