Useful Command Line One-Liners for Developers | DevTools

Discover and use essential command line one-liners for developers. Enhance your workflow with quick, powerful shell commands for file management, data manipulation, and system tasks.

Command Line One-Liners

Essential Command Line One-Liners for Developers

Mastering the command line is crucial for efficient development. Here are some powerful one-liners that can significantly boost your productivity by simplifying common tasks. These commands are designed for Unix-like systems (Linux, macOS) and can be used in your terminal or shell scripts.

File and Directory Management

  • Print files and directories in a tree structure:
    find . | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
  • Print only directories in a tree structure:
    find . -type d | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/| - \1/"
  • Recursively remove directories that contain no files:
    find . -depth -type d -exec rmdir {} \;
  • Display all files/directories sorted by size (human-readable):
    du -ah . 2>/dev/null | sort -hr | less
  • Make multiple copies of a file:
    tee filecopy{1..10}.txt < file.txt

Data and Text Manipulation

  • Find common lines present in two files:
    cat file1 file2 | uniq -d
  • Find lines in file1 that are not present in file2:
    comm -23 file1 file2
  • Find the most frequently used commands in history:
    history | cut -c8- | sort | uniq -c | sort -rn | head

System and Network Information

  • Quick access to the ASCII table:
    man ascii
  • Count the number of total active network interfaces (excluding loopback):
    wc -w <<<$(netstat -i | cut -d" " -f1 | egrep -v "^Kernel|Iface|lo")

These one-liners are invaluable for quick tasks and can be combined to create more complex operations. Experiment with them to see how they can streamline your daily command-line usage.

Further Learning Resources