ABN 25 173 915 011 markomedia - web development

markomedia - web development

  • Home
  • Contact
  • Blog

November 30, 2011

bash script useful tips

  • markomedia
    • Linux
      • bash script useful tips
Share |
  • Author
    Marko Tomic
    Category
    Linux, Shell
    Tags
    bash
    Comments
    0

    At Learnosity I’ve spent last 2 days scripting virtual server deployment on Amazon cloud. For my reference, these are some useful commands I had to use to get the job done.
    1. Hash “Hello World” string using SHA256 algorithm

    echo -n "Hello World" | shasum -a 256

    You can also hash a file

    shasum -a 256 myfile.ext

    2. Display server IP address by stripping out all other network information, including the local 127.0.0.1 IP

    ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

    3. Read out first 64 characters from a long string

    ${mystring:0:64}

    4. While loop with 10 iterations

    i=0;
    while [ $i -lt 10 ]
    do
        echo $i
        i=$[$i+1]
    done

    5. Replace contents of a file. For example search for string1, replace with string2 in myfile.txt

    sed -e "s/string1/string2/g" myfile.txt > myfile.txt_temp
    mv myfile.txt_temp myfile.txt

    6. Display number of CPU processors on Linux
    The command simply pulls out all instances of the word ‘processor’ from /proc/cpuinfo and returns the word count of it.

    cat /proc/cpuinfo | grep processor | wc -l

    Marko

  • Previous post
  • Next post
Top

Related posts

  • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine
  • opendiff and FileMerge on OS X
  • Bandwidth throttling on OS X
  • apr_sockaddr_info_get() failed for mydomain.com
  • AES-128 padded encryption/decryption with Railo, Java and AS3

Share this post

Author Marko Tomic

Gravatar

Leave a comment

No comments yet.

Search

QR Code

Recent Posts

  • IE 8 and IE6 on OS X VirtualBox

    IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

  • FileMerge

    opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

Popular

  • Verizon Activates 2.2 Million iPhones in First Quarter

  • Amazon Server Trouble, Obama’s Facebook Visit.

  • Best Practices for Android Developers

Comments

  • Marko Tomic on Zen Cart to VirtueMart csv export
  • snake on Zen Cart to VirtueMart csv export
  • Marko Tomic on Flash to Flex ComponentEvent coercion error solved
  • Thomas on Flash to Flex ComponentEvent coercion error solved
  • Increase PHP file upload limit – markomedia – Web Development | Files U, Apache on Increase PHP file upload limit

Tags

  • Apache6
  • AS36
  • bash2
  • ColdFusion2
  • command1
  • difftool1
  • DVD1
  • filemerge1
  • Flash3
  • Flex6
  • general2
  • Handbreak1
  • HOWTO8
  • IE61
  • IE71
  • IE81
  • IE91
  • iPhone1
  • iTunes1
  • Jaber1
  • java5
  • Linux3
  • MySQL3
  • networking1
  • opendiff1
  • OS X8
  • PHP3
  • Railo4
  • Red52
  • S31
  • shell3
  • SQL1
  • SSH2
  • SSL1
  • SVN1
  • tar1
  • Terminal3
  • Tigase1
  • Tomcat2
  • Ubuntu2
  • utilities1
  • VirtueMart1
  • XMPP1
  • ZenCart2
  • zip1

Contact us

  • Call us

Archive

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

Navigation

  • Home
  • Contact
  • Blog

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

From the blog

  • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

  • opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

  • bash script useful tips

  • apr_sockaddr_info_get() failed for mydomain.com

About us

Marko Tomic - Web professional and an Adobe Certified Expert with over 10 years of commercial experience using variety of technologies.

Connect

Facebook icon Twitter icon Email icon RSS icon