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
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
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):
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.
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
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.
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
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.
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.
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.
About Me
Tags
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Calendar
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Sep | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | |||
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)
