Bash
Linux Fork Bomb Explained
One famous way to crash your Linux system is to run a “fork bomb” in the terminal. A variant of it looks like this:
WARNING: Malicious code. Don’t run it!
1 | :(){:|:&};: |
This code looks strange, but it’s actually a conventional code in Bash. To make it a little more obvious, let’s replace the : (colon) with the word bomb. So, our code now looks like this:
1 | bomb(){bomb|bomb&}; bomb |
Navigate Efficiently To Your Most Used Directories With Autojump
Autojump is “a cd command that learns”.
I use to visit a small number of directories on daily basis. For example, every time I want to visit my studies directory I used to type:
cd ~/Studies/Winter2009/
With autojump, I just need to type:
j Win
And hit the [tab] key (It supports auto-completion).
Copy a Directory Along With Its Relative Path
Today, a friend of mine wanted to do this:
Copy a directory from path A to path B, preserving its relative path.
For example, if the directory is found at:
./old/path/of/dir
and we want to copy it to
./new/place/
We want the result look like this:
./new/place/old/path/to/dir
Create a Directory Tree With One Command
This one is via command-line-fu.
1 | mkdir -p doc/{text/,img/{wallpaper/,photos/}} |
Will create the following directory tree inside current directory:
-doc
—–text
—–img
———-wallpaper
———-photos
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.
Using Find Command to Find & Manipulate Files
The “find” command is a powerful command, which lets one search for files according to many criteria.
Below are a few examples. I found them here. In this post I just trimmed some of the text of the original post in order to have a quick reference without much explanations.
Go Up As Much Directory Levels As You Need – Easily
This neat and brilliant script by shell-fu allows you to go up as many directory levels as you want.
For example, instead of typing
cd ../../../..
You’ll be able to type the following and get the same functionality:
cd .. 4
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.
Enhanced Bash
The first thing I do when I install a new Linux on my machine is updating .inputrc and .bashrc files to support “Enhanced Bash”. These improves might look minor at first glance, but they had improved my experience with the shell very much.
The main features you achieve by enabling “Enhanced Bash” are:
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 | 30 |
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)
