Friday, November 20, 2009

Linux command

Linux Command Line Tips And Tricks

By Web Hosting Help Guy

All developers and sysadmins who work in a Linux environment are familiar with the following scenario – you’re at the command prompt and you know exactly what you’re trying to do, but you just can’t think of (or find) the right commands to accomplish the task in one fell swoop. Frustrated, you pound your way through four steps, finally accomplishing the task that you know you could have taken care of in one step – if only you had known the right step.

Luckily for you, we’ve gathered together our brightest Linux minds and command line ninjas and asked them to help us out by providing their most useful tricks, shortcuts, and secrets to share with the world. They’re listed below, along with a helpful description as to what they accomplish and when to use them. Enjoy!

Moving a MySQL Database To Another Server:

Not only does this command dump the database, but it creates the dump, compresses it, and securely transfers it to the remote host via SSH. Then, it decompresses the dump and imports it to the new location.

File Location/Management Commands:

This command locates all files on your server that are over 20MB (or a size of your designation) and reports both the size and the location of each file that qualifies. This command is generally restricted to those with root access.

The above command will list the size of every file in the current folder in Human readable format AND print the size of the current folder.

Simliarly, the first command below will print the size of all files in a given folder, while the one below that will find any file you specify, beginning the search in the root directory.

Usage commands:

The first command lists processes by their percentage of CPU usage, while the second command lists them by memory usage. A great quick trick to see where your server resources are going.

Permissions:

The above commands find potentially harmful file permissions and change them to more secure and acceptable levels. Remember, though, sometimes file permissions need to be set at 777, and the above command will change all 777 permissions to the more restrictive 755.

Calendars

The first command will display a calendar for the current year, while the second shows a calendar for any given year, which is perfect if for some reason you want to see what day you started second grade on in 1984.

Create a Mirror Site

This command is particularly useful if you have to move your entire website to another server – it compresses, encrypts it, and creates a mirror of it, allowing you to transport that exact copy to another server.

Compressing Many Files Into One For Export

It’s a load on your servers if it has to connect, disconnect, and reconnect every time you want to transfer data from one place to another, such as in an FTP export. The first command above compresses data from many folders into one file for easier export by making a .tgz archive. Similarly, the second command copies a file to another server of your choice.

Disabling Line Wrap In The Command Line

When coding a lengthy sequence, it can sometimes be difficult to see where the line breaks are, since in default mode the line of code will wrap it below. Turn it off with the above command for easier copying and pasting long lines of code.

Wednesday, July 29, 2009

DataBase Tips

Grant all permission for user
grant all privileges on DBNAME.* to root@IPAddress identified by 'Pasword' with grant option

Get
mysql -USER -PAssword DBNAME -B -e "SQL Query;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > FileName.csv