Command Line Interface

Share Code Snippets Easily From the Command Line

This is a great tip I found at commandlinefu to easily share code snippets write from the command line.

First, you may want to add this to your aliases file:

1
alias share='curl -F "sprunge=<-" http://sprunge.us | xclip'

(If you don’t have the xclip program, you can easily install it from your package manager.)

Now, say that you have a c program named “hello.c”, to share it, type this (after reloading your aliases file of course):

cat hello.c | share

Now, the code is already in the internet, and the URL is in your clipboard. Go to firefox and click the middle mouse button in the URI area. You’ll see a URL similar to this:

http://sprunge.us/BaFS



To view the code with syntax highlighting and line numbers, just append “?c? (or “?lang” where ‘lang’ is the relevant programming language). So the final URL should look like this:

http://sprunge.us/BaFS?c

Enjoy ;)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Saturday, June 13th, 2009 Programming No Comments

Tiny Bash Functions to Convert Between Numeric Representations

I have these functions in my aliases file. They make it easy to convert between hex, binary and decimal representations of numbers. You might find it useful.

Just add these to your aliases file (imported from ~/.bashrc):

1
2
3
4
5
6
function h2d { echo "obase=10; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; }
function h2b { echo "obase=2; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; }
function b2d { echo "obase=10; ibase=2; "$*"" | bc; }
function b2h { echo "0x$(echo "obase=16; ibase=2;"$*"" | bc)"; }
function d2b { echo "obase=2; ibase=10; "$*"" | bc; }
function d2h { echo "0x$(echo "obase=16; ibase=10; "$*"" | bc)"; }

Now you should be able to use it like this:

h2d 0xff

The output will be 255 in this case.

h2b is for “hex to binary”, the others are similar (h: hex, b: binary, d: decimal)

Enjoy ;)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , ,

Friday, June 12th, 2009 Bash No Comments

Send Self Reminders To Your Email From The Command Line

The following will allow you to send self reminders/TODO items to your Email at a specific time.

For example, if you want to remind yourself to submit an assignment at 15:20, you’ll be able to run this command to do it:

tdr “submit assignment” 15:20

This will send an Email to you, with the subject: [TODO] submit assignment. Email will be sent at 15:20.

To be able to do this, you migh need to configure your mail command (see my post about this).

Then, add this function to your ~/.bashrc file (or any file sources in bashrc):

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , , ,

Saturday, March 21st, 2009 Linux No Comments

Send Email from the Command Line using Gmail Account

Sometimes you want to send a quick/short E-mail to somebody, send a TODO item to yourself, or let a script/program Email you when it’s done. For these I found the Linux mail command very useful.

Using it is as easy as typing:

mail -s “Subject” receipt@domain.com

Then enter the message and end it with [ctrl]+[D].

However, if your ISP s!#$% like mine, you’ll discover that no mail was really sent.

To work around this, I wanted to configure my mail program to use Gmail’s SMTP server.

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Saturday, March 21st, 2009 Command Line 4 Comments

Mount ISO Images From the Command Line

To mount an ISO image from the linux command line:

sudo mount -o loop image_file.iso /path/to/mount/folder

Via Tips4Linux

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Saturday, March 21st, 2009 Linux 1 Comment

A Bash Command To Get Your IP

This is a one line bash command to get your IP.

It queries whatismyip.com, processes the output and displays the IP.

You might want to add it to your aliases file.

UPDATE: Don’t use this command, use the one in the end of this post

1
wget -O - whatismyip.com 2> /dev/null | grep "Your IP Address Is" | sed -e 's/^.*Is//' -e 's/<.*$//'

Enjoy ;)

Update: A nice guy – Theodore- has put this along with a script of his own to get a simple and neat bash script which shows both the internal (wired and wifi) and the external IPs. Script posted at his blog. Script in Theodore’s post is for Mac, but can be easily modified to run on Linux. Thanks Theodore.

Update2: Thanks to commenter Paul Dorman, I visited whatismyip’s forum and realized that they don’t allow to visit their home page too many times (they might ban you if you do so). However, they give an alternative: Another page in their website where you can get your IP. So the new command to query your IP is:

1
wget http://www.whatismyip.com/automation/n09230945.asp -O - 2> /dev/null; echo

Please use this and not the previously mentioned command.
Thanks Paul.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: ,

Monday, March 9th, 2009 Bash 10 Comments

Get Examples for Random Bash Commands

Following my post about a script to query bash commands from shell-fu, here is another script, which queries shell-fu for examples of a random bash command:

The script is not bullet-proof and might fail if the guys at shell-fu decide to change the website’s layout, but it works for now, and this is good

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Saturday, February 28th, 2009 Bash No Comments

Get Examples for Bash Commands in Your Terminal

This one is by the great shell-fu, a website with many bash examples.

The following script is a powerful enhancement for the bash experience, and a great addition to the manpages, it allows you to query shell-fu for examples about almost any bash command you might want to use.

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Thursday, February 26th, 2009 Bash 4 Comments

A Bash Script To Decode TinyURLs

This is a simple bash script, intended to decode tinyurl URLs, i.e. to revret a tinyurl into the original URL.

It’s always a good practice checking where a URL will send you to before actually visiting it.

For the implementation, I the “Preview” service supplied by tinyurl themselves.

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Sunday, February 22nd, 2009 Command Line No Comments

A Bash Script To Watch Live TV Streams

Hi,

In this post I’ll introduce a very simple and basic Bash script, which uses VLC and a plain text file to let you watch Live TV streams of your favorite channels.

First of all, make sure you have VLC installed in your system.

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , , ,

Monday, February 9th, 2009 Command Line 3 Comments
my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
February 2012
S M T W T F S
« Sep    
 1234
567891011
12131415161718
19202122232425
26272829  
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.