Top 10 Useful Linux Commands

I have compiled some of the most basic linux commands that can be most helpful for linux beginners. You can enter these commands in SSH in administering your server. These commands could be handy to webmasters who are learning VPS or dedicated server basics.

 

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

top
// shows the memory, cpu load and other processes running
free
// 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.
OR
nmap fuser localhost
// easy command

Install firewall to block unwanted ports running on your PC or in server.

FAQs

How do i change root password?
Just login as root or su root and type passwd, you will be asked for new password.

> passwd
// Be CAREFUL! If you forget your new password, you will lock yourself

I am installing a firewall in my linux server? How do i know which ports to block and to open?
When installing firewall be sure to block all unwanted open ports. A comprehensive collection of ports and services run at that port can be found here
Here is the short of ports which needs to be kept open for listening.

Common ports
21 => FTP
22 => SSH
25 => SMTP Mail Transfer
43 => WHOIS service
53 => name server (DNS)
80 => HTTP (Web server)
110 => POP protocol (for email)
143 => IMAP Protocol (for email)
443 => SSL for HTTP


Cpanel => 2077,2078,2082,2083,2086,2087,2089,2095,2096,3306, 6666.
Plesk => 8443
Webmin => 10000

If you have root permissions, you can login to your server control panel like this...

https://ipaddress:2087/
// for cpanel
https://ipaddress:8443/
// for plesk

Hope my ports compilation should be helpful for beginners who use linux.

Back to home