Ubuntu Debian Linux useful commands

Updated: 2015-09-08

  1. Change keyboard layout to support both English (US) and Greek (GR)
  2. setxkbmap -option grp:alt_shift_toggle us,gr
    
  3. Audjust monitor brightness and gamma
  4. # make it darker
    xrandr --output LVDS1 --brightness 0.4 --gamma 1.6:1.6:1.6
    
    # restore to default brightness and gamma
    xrandr --output LVDS1 --brightness 1 --gamma 1:1:1
    
  5. Find top 10 largest files in /
  6. sudo du -a / | sort -n -r | head -n 10
    
    # or in human readable format
    cd / ; sudo du -hsx * | sort -rh | head -10
    

    Source: cybercity

  7. Find IP without using ifconfig
  8. netstat -n -t | awk '{print $4}' | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" |grep -v "127.0.0.1" | sort -u
    
  9. Run logrotate
  10. logrotate -f /etc/logrotate.conf
    
  11. Curl get http code and store it to Bash variable
  12. bob=`curl -L -s -f -w "%{http_code}" --output /dev/null "http://www.google.gr"`
    
  13. Curl GET with url encode in BASH
  14. curl -G "$urlGet" --data-urlencode "date=$datos" --data-urlencode "diskdata=$diskuse"
    
  15. Curl basic authentication
  16. curl -u "myusername:mypass" "http://www.google.com"
    
  17. Url Encode String with Perl from Bash
  18. adaUrlEncoded=`perl -e ' use URI::Escape; print uri_escape("$row");'`
    
  19. Cron Job every five minutes with sterr redirection
  20. 0,5,10,15,20,25,30,35,40,45,50,50,55 * * * * /home/bob/sendServerData.py >/dev/null 2>&1
    

    More examples in Cyberciti tutorial

  21. Add a GPG key to apt manually
  22. Lets say we want to add MongoDB GPG key to apt in order to install MongoDB in Debian Linux. We download the key from here or copy it to a file, lets say 10gen-gpg-key.asc. Then run:

    cat 10gen-gpg-key.asc | sudo apt-key add -
    
  23. Change your default locale
  24. Edit your locale variable values using:

    sudo vi /etc/default/locale
    
  25. Merge PDF files
  26. Append multiple pdf files (source*.pdf) to one (alltogether.pdf) using the following command. NOTE: The last document is the generated destination pdf document where the rest will be appended.

    pdfunite source1.pdf source2.pdf source3.pdf alltogether.pdf
    
  27. Sort Nginx access log by Response Codes
  28. sudo awk '{print $9}' /var/log/nginx/ssl.access.log | sort | uniq -c | sort -r
    

    Source: rtcamp

  29. Count IP requests from Nginx access log
  30. sudo awk '{print $1}' /var/log/nginx/ssl.access.log | sort | uniq -c | sort -nr
    

    Source: Mkyong

  31. Fast Delete files modified before 10 minutes
  32. time find $i/*.tmp -mmin +10 -type f -delete
    

    Source: slashroot

  33. Remove newline character (‘\n’) from a file
  34. tr '\n' ' ' < input_filename
    

    or more hackish

    sed ':a;N;$!ba;s/\n/ /g'
    

    Source: StackOverflow

  35. View Apache requests per minute (from logs)
  36. grep "23/Jan/2013:06" example.com | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'
    

    Source: inmotionhost

  37. Redirect script output to syslog (while it is in crontab)
  38. 0 1,9,17 * * * myscript.sh &2>1 | /usr/bin/logger -t myscript
    
Advertisements

About cmanios

programming
This entry was posted in Linux and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s