Browsing articles in "Linux"
Feb 9, 2013

Linux/Magento: Daily useful development commands

These are the daily commands I use at work. This will definately help someone who is not familiar with all these commands in Linux and Magento.

Linux: Search / Replace recursively

find /path/here/ -type f -exec sed -i ‘s/search string/replace string/g’ {} \;

Linux: Find all files matching a string

grep -r “string to search” /path/to/search/

Linux: In vi editor, copy/paste/delete/replace/insert/save/undo/redo/search-replace/goto
Open file: vi filename
Copy: yy (yank) (for multiple lines copy, 5yy – for copying 5 lines)
Paste: p
Delete: dd (for multiple lines delete, 5dd – for deleting 5 lines)
Replace: r (on character you wish to replace, press r and enter new character)
Insert: i or insert key
Save: escape and : x (without space between : and x) (x = write and quit, w = write, q = quit, q! = quit without saving)
Undo: u
Redo: Ctrl+R
Search: escape key THEN / THEN write string to find THEN enter
Search-Replace: :%s/search string/replacement string/g
Goto Line number: escape key THEN : THEN line number (e.g. :22 to go to 22nd line of current file)

Linux: Search previous execute command in terminal

in terminal, press Ctrl+R and type few characters.
This will show you previous command matching that sequence of characters
To check another command matching same characters, press Ctrl+R again

Linux: Recursively change files/directories permissions

find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;

owner / read (4) + write (2) + execute (1)
group / read (4) + write (2) + execute (1)
world / read (4) + write (2) + execute (1)

Linux: Show unique values of any column in CSV

cat file.csv | cut -f 1 -d , | sort|uniq -c | tee tempfile

here, 1 = 1st column, which can be changed to view any column
uniq -c = unique values with count of occurences of each value. You can omit -c to just see the unique values
file.csv = filename, you can have any file here with any extension
, = delimiter used to separate columns
tee tempfile = moves the output to file “tempfile”

Linux: Recursively change ownership of directories/files

chown -R www-data:www-data magento
-R = for recursive
www-data:www-data = change owner to www-data (apache)
magento = directory to change permission for, recursively

Linux: Remove all Magento cache files

From your magento root in terminal, execute this:
rm -rf var/cache/*
DON’T put any space after cache/ and *, otherwise it will delete your WHOLE magento project 😀

To delete all the active sessions on your magento store,
rm -rf var/session/*
Continue reading »

Jan 8, 2013

Mysql root password reset or create

Mysql root password reset easily by following below instructions. For those who want to create (if no root user in mysql) or reset the password for the Root user in Mysql (in Linux), this post is definately going to help you. I had a tough time in getting this to work, so thought to share it with anyone facing the same problem.

You need to use –skip-grant-tables if you don’t know mysql password to login. You can use it like this:

/usr/bin/mysqld_safe –skip-grant-tables &

Once you run the above command on terminal, write mysql and hit enter. That’s because you already said Mysql that you want to skip all the privileges checking and allowing you with all the database access without password.

You should be inside mysql now. Now execute the command use mysql; because we are going to create/change the user in “mysql” database.
Continue reading »

Nov 2, 2012

Linux: Bash script to check availability of domain names in differnet TLDs

If you want to check whether your desired domain name is available or not in different extensions, it’s tiresome to search it for each and every tld. There are also limits of performing query to whois on websites, where they will not allow you unlimited whois information queries. It’s better to have your own script which will tell you the availibility of domain name in different extensions, right from your terminal.

Below script will check your domain name for TLDs .com, .net, .org, .info, .us, .co, .tel, .tv, .biz, .cc, .ru, .eu, .in, .it, .sk,, .sh, .re and .dk
But you can add other TLDs also if you want.

First create a file, e.g., and give it proper permission to execute.

chmod 744

Now, copy below code to this newly created file
Continue reading »

Nov 2, 2012

Linux: Bash script to get email address and created/updated/expires dates of domain name

In linux, to check the whois of any domain name, the simple command is:


But, it will show you so many things which are not important, e.g. it will show you the NOTICE and TERMS of USE and so many other things.

If you are only concerned of getting the email address and creation/updation/expiry date of domain name from whois, here is the bash script that will help you out.
First create a bash script file, e.g. and give it permissions to run:

chmod 744

Continue reading »

Oct 10, 2012

Ubuntu: Delete temporary/cache files

It’s necessary to clean unnecessary files from your operating system and free up space. In Ubuntu, this is very easy if you have admin privileges.

Below command will remove all the unnecessary package files, which are no longer used by their packages. You can say they are orphaned files, not needed anymore.
sudo apt-get autoremove

Below command will remove all the cache and unnecessary files from your system. It will delete everything and make your system clean from temporary files and orphaned files.
sudo apt-get clean


Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!




Magento top 50 contributors

Magento top 50 contributors