Saturday, March 10, 2012

Top 10 commands for linux

1. List command

ls -a
// lists all
ls -l
// lists all files including hidden files like .htaccess
ls -l | more
// shows in paged format with pipe

2. Untarring the uploaded tar.gz files

This command is the most important command and often regularly used to uncompress files..
tar -xzf filename.tar.g
How to dump/Import tar.gz (zipped) file into MySQL database
SSH command to restore/import gzipped large databases to mysql on the fly with just one single command. This is so useful as large databases can only be imported to mysql this way! Remember to upload the database dump before you issue this command
gunzip < dbname.gz | mysql -u Username -p dbname

3. Installing packages

Installing softwares in linux the most basic and you will need to know this command very well .
yum install
// for centos and redhat
apt-get install
// for debian/ubuntu

4. To look for memory usage

// shows the memory, cpu load and other processes running
// shows the memory usage of linux

5. To see the disk usage.

df -h
// shows the disk usage and outputs the disk usage left

6. To view running processes

ps aux
// shows the running processes and its ID. You can use this ID to kill the process later.

7. Deleting all files within a folder

This perhaps is one of the most sought after command to delete all subfiles and subfolders in linux with just one command in a fly.
rm -Rf /my/path
// this deletes all files. so be careful!

8. Edit a file in easy way!

I love nano command. Its just so easy to edit a file with menu options and save changes. You can easily search for specific text inside the file with the nano editor.
nano /file/path
// text editor to edit files

9. Changing Permissions and Ownership

whats there in linux without permissions and ownership
chmod -R 755 /folder/path
// this recursively changes all files and folders of the path.
chown pbu /file/name
//changes the ownership of filename
chgrp mygrp /file/name
//changes the group to new one
If you dont know how to interpret the 755 or number like permissions here is an easy way to remember
Ex: 755 means rwxr-xr-x
7 -> rwx (for owner)
5 -> r-x (non writable for group)
5 -> r-x (non writable for world)
First we consider '7' in 755 as it is made up of 3 bit binary. To construct 7 we need to construct 111(which is 4+2+1 in decimal).
5 -> 101 ( which is 4+0+1)
5 -> 101 (which is 4+0+1)
Remember 755 is the decimal of the binary and it is always made up of 4+2+1.

10. To find out what ports are open

Finding which ports are open and closed are so important in terms of security point of your server. You might want to close unwanted services using different ports.
netstat -nap --tcp
// lists connections and what ports are open.
nmap fuser localhost
// easy command
Install firewall to block unwanted ports running on your PC or in server.

No comments:

Post a Comment

thank you