Wednesday, November 13, 2013

Red Hat/CentOS commonly used command line collection

Yum

yum install <package-name>         #install package
yum remove <package-name>          #remove package
yum erase <package-name>           #delete package
yum search <keyword>               #search if exsit package containing keyword
yum repolist                       #show repository list
yum update                         #update installed packages

Good site searching for repos: Linux packages search

How to add a yum repository mannually

Yum repository directory is located at /etc/yum.repos.d/, so if you have a yum .repo file, just copy this file into the directory.
And there are some repositories wrapped as rpm files, such as postgreSQL. What you need to do is to download the rpm files and install them.
See Also:  Adding, Enabling, and Disabling a Yum Repository

RPM

rpm -i <package-name>.rpm          #install rpm package
rpm -qa | grep <package>           #check if installed

PS

ps                                 #show process
ps -l                              #Display information associated with the                                          following keywords: uid, pid, ppid, flags,                                        cpu, pri, nice, vsz=SZ, rss, wchan,                                              state=S, paddr=ADDR, tty, time, and                                              command=CMD
ps aux | grep <keyword>            #show details of process


Kill

kill [signal] PID                  #kill specified process using pid, most used                                       is '-9' to kill process.
kill -l                            #display all the [signal]s
kill `ps | grep <keyword> | awk '{print $1}'`  #kill process by <keyword>

TOP

top                                #display all process
top -user <user>                   #display <user>'s process
top -pid <pid>                     #display process by given <pid>

service

service <service-name> status      #show service status(running or stopped)
service <service-name> start       #start service
service <service-name> stop        #stop service

hostname

hostname                           #show hostname
hostname --fqd                     #show fully qualified domain name(FQDN)
hostname NEW_NAME                  #change hostname temporary

See also:  How to Change the Hostname of a Linux System

restart the network

/etc/init.d/network restart        #!Red Hat Specific, may not applicable in                                        other linux


Add third-party repositories

EPEL: see here

User

Add user
userdel user                         #delete user
useradd -G <group-name> <username>   #add user to non-existed group
useradd -g <group-name> <username>   #add user to primary group
usermod -a -G <group-name> <username> #add a existing user to existing group
usermod -g <group-name> <username>   #change user's primary group to <group-name>
passwd <username>                    #setup password for user
id <username>                        #show user information


tar

tar -zxvf <file-name>.tar.gz         #extract tar.gz file

Netstat

netstat -a   #list all ports of TCP/UDP
netstat -at  #list TCP connection
netstat -au  #list UDP connection
netstat -l   #list all listening ports