Useful Linux Commands

Here is a list of Linux commands that I frequently use, it’s easier to keep them in one place.

  1. Fix files and folders permission
    1
    2
    find . -type d -print0 | xargs -0 chmod 0775 # For directories
    find . -type f -print0 | xargs -0 chmod 0664 # For files
  2. Alternative to rm when there are too many files to be deleted
    1
    find . -name "*"| xargs rm -rf
  3. Alternative to mv when there are too many files to be moved
    1
    find . -name "your_wildcard" -exec mv {} /path/to/destination/dir \;
  4. Remove all .svn folders to prevent vulnerability
    1
    find ./ -name ".svn" | xargs rm -Rf
  5. Transferring files from the current server to a remote server
    1
    rsync -avhe 'ssh -p {SSH Port}' {Source} {user}@{Destination  Host}:{Destination} --exclude-from '{exclude}'
  6. Check server memory resources every second
    1
    watch -n 1 -d free -m
  7. Check server CPU usage every second
    1
    watch -n 1 mpstat -P ALL
  8. Check server process usage
    1
    ps -eo pid,%cpu,vsz,args,wchan
  9. Total network stats
    1
    netstat -a -n|grep -E "^(tcp)"| cut -c 68-|sort|uniq -c|sort -n
  10. List of processes of a user displayed in a hierarchical manner
    1
    ps f -u [username]
  11. Watch over MySQL process (130 is terminal width)
    1
    watch 'mysqladmin proc | grep -v Sleep | cut -b0-130'
  12. Viewing mysql Import Process
    1
    bar -if=data.sql | mysql

These commands have been found around the internet, but I have forgotten their origins. Most were found within forums and I appreciate the original posters!

Comments Closed

Go to Top