Essential Unix/Linux Command-Line Tips for Increased Productivity
This guide presents a collection of practical Unix/Linux command-line techniques—including safe file deletion, terminal session recording, directory restoration, permission management, output formatting, user information retrieval, and efficient navigation—to help users boost productivity and manage systems more effectively.
Learn how to safely delete a massive 200 GB log file without overloading I/O by truncating it with : > /path/to/file.log and then removing it with rm /path/to/file.log.
Record terminal output using the script utility, e.g., script my.terminal.session, and later view the log with more, less, or cat.
Restore an accidentally removed /tmp directory by recreating it and resetting permissions: mkdir /tmp, chmod 1777 /tmp, chown root:root /tmp, then verify with ls -ld /tmp.
Lock a folder such as /downloads by setting permissions to chmod 0000 /downloads; root can still access it, and you can unlock it later with chmod 0755 /downloads.
Protect a file in Vim with a password using vim +X filename or the :X command before exiting, which prompts for a passphrase.
Clear a garbled terminal screen instantly with reset.
Display command output in human‑readable form by adding -h or -H to GNU/BSD tools, e.g., ls -lh, df -h, free -m, du -h, stat -c %A /boot, sort -h -a file, lscpu, and tree -h.
Show known user information on Linux with lslogins (or logins on BSD) and review the formatted output.
Remove files unintentionally extracted by a tarball in /var/www/html with cd /var/www/html/ followed by /bin/rm -f "$(tar ztf /path/to/file.tar.gz)".
Replace top with the more user‑friendly htop by running sudo htop.
Rerun the most recent command using !!, repeat a command that starts with a specific prefix using !foo, or reuse the last argument with !$ (e.g., sudo vi !$().
Set a reminder to leave the terminal at a specific time with leave +hhmm, where hhmm denotes the hour and minute.
Quickly return to the previous directory with cd -, go to the home directory with cd, and define a search path for cd using export CDPATH=/var/www:/nas10.
Edit a file while viewing it with less by pressing v, which launches the editor defined by $EDITOR.
List all directories or files on the system using find / -type d | less and find / -type f | less, or limit the search to $HOME with appropriate options.
Create an entire directory tree in one command with mkdir -p /jail/{dev,bin,sbin,etc,usr,lib,lib64} and verify with ls -l /jail/.
Copy a single file to multiple destinations efficiently using
echo /usr/dir1 /var/dir2 /nas/dir3 | xargs -n 1 cp -v /path/to/file.
Compare two directories quickly with diff /tmp/r/ /tmp/s/ after listing their contents.
Reformat text files for better readability with fmt file.txt (or fmt -s file.txt to split long lines without re‑flowing).
Use tee to display command output on the screen while simultaneously writing it to a log file, e.g., mycoolapp arg1 arg2 input.file | tee my.log.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
