Bash
Edit The Command Line With Vim
This is a quick (and great) tip I found at Daily Vim:
Open a linux terminal, and type some (long) command.
Now type [ctrl]+[x] and then [ctrl]+[e]
The command should be moved now to a vim window.
Edit the command (fix typos, change parameters, etc..) and save.
The command will now be executed.
Enjoy
Renaming Files In Linux
In a previous post, I wrote about converting strings from camelCase to undescore delimited format.
In this post, we’ll do the same but for file names. We’ll use the command line program “rename” for this purpose.
Here we go:
1. Convert all file names in current directory which are of the form “myFileName” or “MyFileName” into the form of “my_file_name”:
1 | rename 's/(.)([A-Z])/$1_\l$2/g' * && rename 's/([A-Z])/\l$1/g' * |
2. Convert all file names in current directory which are of the form “my_file_name” into the form “myFileName”:
1 | rename 's/([a-z])_([a-z])/$1\u$2/g' * |
3. Convert all file names in current directory which are of the form “my_file_name” into the form “MyFileName”:
1 | rename 's/([a-z])_([a-z])/$1\u$2/g' * && rename 's/^([a-z])/\u$1/g' * |
Enjoy
Convert camelCase to Underscores Using sed
This short post deals with converting strings of the form camelCase or CamelCase into camel_case, and vice versa. These are three different popular naming conventions for variable/function/class names.
Convert CamelCase or camelCase to camel_case:
1 | sed -e 's/\([A-Z]\)/_\l\1/g' -e 's/^_\([a-z]\)/\1/g' file.txt |
Convert camel_case to camelCase
1 | sed -e 's/_\([a-z]\)/\u\1/g' file.txt |
Convert camel_case to CamelCase:
1 | sed -e 's/_\([a-z]\)/\u\1/g' -e 's/^\([a-z]\)/\u\1/g' file.txt |
Sed and AWK – A quick reference
Sed (Stream Editor) and AWK (First letters of the surnames of its authors) are very powerful *nix tools for manipulating strings and text files. They combine the power of regular expressions with the power of a programming language for this aim.
Here are two quick references for doing many operations with a one-line code of sed and AWK. (Both are by the same author – Eric Perment):
› Continue reading
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
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
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)
