Thursday, July 17, 2014

My Most Used Linux Commands


Here are a few LINUX commands that i very often refer to:

  • Find files modified in last 7 days:  
    find . -type f -mtime -7
  • Count number of files in a directory:
    ls -f | wc -l
  • Create a soft link:  (ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT])
    ln -s /mnt/san/mywebsite /var/www/mywebsite
  • Organize folders by size:
    du -h --max-depth=1 /home | sort -n -r | grep M | more
    grep M to show only MBs.
  • Check MISS ot HIT state in Squid access.log file:
    cat /var/log/squid/access.log.* | grep HIT | wc -l
  • Stream Editor to find and replace a string:
    find . -type f -exec sed -i 's/oldstring/newstring/g' {} \;
  • To print a selected column from a text file on screen:
    awk '{print $1}' file.txtawk '{print $1}' file.txt > output.txt
  • Sort a text file basing on a particular column:
    sort -t, -n -K4 FileToBeSorted.txt > SortedFile.txt
  • Change default editor in RHEL to nano:
    export EDITOR=/usr/bin/nano
  • To be continued .....

No comments:

Post a Comment