1. Kill program using one port
    sudo fuser -k 8000/tcp
  2. Supervise command (run every 2s)
    watch "ls -larth"
  3. Limit memory usage for following commands
    ulimit -Sv 1000       # 1000 KBs = 1 MB
    ulimit -Sv unlimited  # Remove limit
  4. Rename selected files using a regular expression
    rename 's/\.bak$/.txt/' *.bak
  5. Get full path of file
    readlink -f file.txt
  6. List files by size
    ls -lS
  7. Nice trace route
    mtr google.com
  8. Get full path of file
    find . -size 20c             # By file size (20 bytes)
    find . -name "*.gz" -delete  # Delete files
    find . -exec echo {} \;      # One file by line
    ./file1
    ./file2
    ./file3
    find . -exec echo {} \+      # All in the same line
    ./file1 ./file2 ./file3
  9. Prepend line number
    ls | nl
  10. Randomize lines in file
    cat file.txt | sort -R
    cat file.txt | sort -R | head  # Pick a random sambple
    or
    shuf file.txt

Posted in Frameworks, Tutorials on Sep 21, 2017