Common Administrative commands in RedHat 6 & 7

I’m posting a quick cheat sheet of the command line changes in RedHat or CentOS 7, full list is available here. I’m pasting my own version below as these are the commands I use most often.

PS – Process List

DescriptionRedHat 6RedHat 7
Show processesps -auxps-x
Show processes (Group like processes into a process tree)ps -auxfps -auxf
Show processes (full format listing)ps -efps -ef
Show processes that belong to meps -xps -x
Show threads of a processps -fL -C httpd ps -fL -C httpd
Check execution time of a processps -eo comm,etime,user | grep httpd ps -eo comm,etime,user | grep httpd


Find a process with high CPU or MEMORY
ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem | head

ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%cpu | head
ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem | head OR

ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%cpu | head
Find an unresponsive processps -A | grep -i stress ps -A | grep -i stress
Terminate a processkill -9 2583 2584 kill -9 2583 2584
View RealTime process info by MEMORY or CPUwatch -n 1 ‘ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem | head’ watch -n 1 ‘ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem | head’

Services

DescriptionRedHat 6RedHat 7

List all services
chkconfig –list 
ls /etc/init.d/
systemctl -at service 
ls /etc/systemd/system/*.service 
ls /usr/lib/systemd/system/*.service

List running services

service –status-all

systemctl -t service –state=active
Start/stop service service name start 
service name stop
systemctl start name.service 
systemctl stop name.service
Enable/disable service
chkconfig name on 
chkconfig name off
systemctl enable name.service 
systemctl disable name.service
View service status service name status systemctl status name.service

Check if service is enabled

chkconfig name –list

systemctl is-enabled name

Create new service file or modify configuration
chkconfig –add systemctl daemon-reload 
/etc/systemd/system/*.service

View run level/target
runlevel 
who -r
systemctl get-default 
who -r

Change run level/target
/etc/inittab 
init run_level
systemctl isolate name.target
systemctl set-default
Find file by name locate locate
Find file by characteristic findfind

Boot/Kernel

DescriptionRedHat 6RedHat 7

Single user/rescue mode

append 1 or s or init=/bin/bash to kernel cmdline

append rd.break or init=/bin/bash to kernel cmdline

Shut down system
shutdown shutdown

Power off system
poweroff poweroff
systemctl poweroff
Reboot system reboot reboot 
systemctl reboot
Configure default run level/target /etc/inittab systemctl set-default
Configure GRUB bootloader /boot/grub/grub.conf /etc/default/grub 
grub2-mkconfig 
grub-set-default

This entry was posted in Linux and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *