Linux

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 ;)

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

Tags: ,

Saturday, May 30th, 2009 Bash 1 Comment

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

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

Tags: ,

Saturday, May 30th, 2009 Bash 5 Comments

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

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

Tags: , , ,

Saturday, May 9th, 2009 Bash No Comments

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

› Continue reading

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

Tags: , ,

Saturday, March 28th, 2009 Bash 1 Comment

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).

› Continue reading

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

Tags: , ,

Tuesday, March 24th, 2009 Bash 1 Comment

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

› Continue reading

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

Tags: ,

Sunday, March 22nd, 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

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

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

Tags: , ,

Saturday, March 21st, 2009 Bash No 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.
June 2012
S M T W T F S
« Sep    
 12
3456789
10111213141516
17181920212223
24252627282930
SEO Powered by Platinum SEO from Techblissonline

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