• buying powerpoint software cheap windows 7 oem software price of adobe photoshop cheap microsoft office 2008 mac best price guitar pro 6 cheap norton ghost 15 uk best price sage act best price naturally speaking 9 purchase microsoft office 2010 student discount adobe audition
  • Various Sys Admin one line Bash commands, one-liners (CLI wisdom)

    Posted by HostsVault | Posted in Tips-And-Tricks, Tutorials | Posted on 26-07-2009-05-2008

    2

    This are a set of commands that a sys admin could use to perform various tasks on a server , varying from listing server Ips to optimizing MySQL tables , hope it helps you managing different tasks fast :

    !!:gs/foo/bar

    Runs previous command replacing foo by bar every time that foo appears
    Very useful for rerunning a long command changing some arguments globally.

    ping -i 60 -a IP

    Set audible alarm when an IP address comes online
    Waiting for your server to finish rebooting? Issue the command above and you will hear a beep when it comes online. The -i 60 flag tells ping to wait for 60 seconds between ping, putting less strain on your system. Vary it according to your need. The -a flag tells ping to include an audible bell in the output when a package is received (that is, when your server comes online).

    du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'

    Sort the size usage of current directory tree by gigabytes, kilobytes, megabytes, then bytes.

    tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16;echo

    useful for generating passwords,
    Find random strings within /dev/urandom. Using tr to use only Alphanumeric characters, and then print the first 16.

    mkdir -p a/long/directory/path

    This will create the intermediate directories that do not exist.

    ctrl-t

    Switch 2 characters on a command line.
    If you typed ‘sl’, put the cursor on the ‘l’ and hit ctrl-t to get ‘ls’.

    grep -i --color=auto

    Highlights the search pattern in red.

    !!

    Repeat last executed command

    DD=`cat /etc/my.cnf | sed "s/#.*//g;" | grep datadir | tr '=' ' ' | gawk '{print $2;}'` && ( cd $DD ; find . -mindepth 2 | grep -v db\.opt | sed 's/\.\///g; s/\....$//g; s/\//./;' | sort | uniq | tr '/' '.' | gawk '{print "CHECK TABLE","`"$1"`",";";}' )

    Generate CHECK TABLE statements for all MySQL database tables on a server

    export dbname=DB;for i in `mysql --batch --column-names=false -e "show tables" $dbname`;do  mysql -e "ALTER TABLE $i DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci" $dbname;done

    Change all tables inside a database to UTF8 character set.

    ifconfig | grep "inet [[:alpha:]]\+" | cut -d: -f2 | cut -d' ' -f1

    Get the IP address of all your network cards.

    VN:F [1.9.20_1166]
    Rating: 5.3/10 (407 votes cast)
    VN:F [1.9.20_1166]
    Rating: -10 (from 86 votes)