Thursday, November 13, 2014

LINUX BASIC COMMON COMMANDS

Filter result:


grep

ex: filter all processes and ports of java

ps -e | grep java
netstat -tunap | grep java

Process and infomation :


Information about process
$ls -l /proc/$PID/exe
OR
$ps -p PID -o comm=
OR
$cat /proc/PID/cmdline

Kill process
sudo kill -9 PID

User and Group:


Login
#su - {user-name}

Login as root
#su -

check username
#whoami

logout
#logout

Extract & Compress file:


Extract
#tar -zxvf {file.tar.gz}
#tar -xf {file.tar.gz} -C /target/directory
#tar -xzf backup.tar.gz -C /target/directory
#unzip file.zip -d destination_folder

Download
#wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz  -P /target/directory

Restating the network service:


To restart the network service under RHEL / CentOS based systems, enter:
service network restart
OR
/etc/init.d/network restart

Check linux kernel version number :


Open a shell prompt (or a terminal) and type the following command to see your current Linux kernel version:

uname -r

Or type the following command
uname -mrs

To print all information, enter

uname -a

Type the following command to see Linux version info

cat /proc/version

Find Distribution Version :


Type the following command

cat /etc/*release

OR
lsb_release -a

Port & Firewall :


Port and process command
netstat -tunap

If you want to open a single port

open iptables file
vi /etc/sysconfig/iptables

Add below line to open port.

-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

For multiple, you can use the following instead (or repeat the above line multiple times):

-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80,143 -j ACCEPT

service iptables save

Disable / Turn off Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following two commands (you must login as the root user)

/etc/init.d/iptables save

/etc/init.d/iptables stop

Turn off firewall on boot

chkconfig iptables off

Enable / Turn on Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following command to turn on iptables firewall

/etc/init.d/iptables start 

Turn on firewall on boot

chkconfig iptables on 

Linux / Unix - Checking Free Disk Space:


df command examples - to check free disk space

Type df -h or df -k to list free disk space

df -h

OR
df -k

Find Files and Folders in Linux :


find / -name "java" 

/: meaning is the root folder. hold systems
-name "java": all files have name is java.