Linux useful commands

memory

  • free -mh

  • sar -r 2 2

  • ps -eo pid,comm,user,%mem,%cpu --sort=-%mem | head

free -m
[dev@dev-vm-422-centos home]$ free -mh
             total       used       free     shared    buffers     cached
Mem:           23G        21G       2.0G        50M       481M        17G
-/+ buffers/cache:       3.6G        19G
Swap:           0B         0B         0B
[root@sf-vm-1 dev]# ps -eo pid,cmd,%mem,%cpu --sort=-%mem | head
  PID CMD                         %MEM %CPU
  641 /usr/bin/python -Es /usr/sb  0.1  0.0
  664 /usr/bin/python -Es /usr/sb  0.1  0.0
  844 /usr/lib/polkit-1/polkitd -  0.0  0.0
  770 /usr/sbin/NetworkManager --  0.0  0.0
    1 /usr/lib/systemd/systemd --  0.0  0.0
  644 /usr/sbin/abrtd -d -s        0.0  0.0
 2421 sshd: rjin [priv]            0.0  0.0
  484 /usr/lib/systemd/systemd-jo  0.0  0.0
  645 /usr/bin/abrt-watch-log -F   0.0  0.0
[root@sf-vm-1 dev]# sar -r 2 2
Linux 3.10.0-229.el7.x86_64 (sf-vm-1) 	04/01/2020 	_x86_64_	(4 CPU)

03:21:10 AM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
03:21:12 AM  15544296    724804      4.46       884    442832    269948      1.47    300056    211544     76628
03:21:14 AM  15544296    724804      4.46       884    442832    269948      1.47    300112    211544     76628
Average:     15544296    724804      4.46       884    442832    269948      1.47    300084    211544     76628

CPU

  • sar -u 2 2

  • ps -eo pid,ppid,comm,user,%mem,%cpu --sort=-%cpu | head

  • nproc

  • lscpu

  • mpstat -P ALL 2 2

[root@sf-vm-1 ~]# mpstat -P ALL 2 2
Linux 3.10.0-229.el7.x86_64 (sf-vm-1) 	04/01/2020 	_x86_64_	(4 CPU)

04:25:23 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:25:25 AM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:25 AM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:25 AM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:25 AM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:25 AM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

04:25:25 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:25:27 AM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:27 AM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:27 AM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:27 AM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:25:27 AM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
Average:       0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
Average:       1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
Average:       2    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
Average:       3    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
[root@sf-vm-1 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 63
Model name:            Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
Stepping:              2
CPU MHz:               2394.455
BogoMIPS:              4788.91
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              15360K
NUMA node0 CPU(s):     0-3
[root@sf-vm-1 ~]# nproc
4
sar -u 3 3
[dev@sf-vm-1 ~]$ sar -u 2 2
Linux 3.10.0-229.el7.x86_64 (sf-vm-1) 	04/01/2020 	_x86_64_	(4 CPU)

03:11:53 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
03:11:55 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
03:11:57 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
Average:        all      0.00      0.00      0.00      0.00      0.00    100.00
[root@sf-vm-1 ~]# ps -eo pid,ppid,comm,user,%mem,%cpu --sort=-%cpu | head
  PID  PPID COMMAND         USER     %MEM %CPU
    1     0 systemd         root      0.0  0.0
    2     0 kthreadd        root      0.0  0.0
    3     2 ksoftirqd/0     root      0.0  0.0
    5     2 kworker/0:0H    root      0.0  0.0
    6     2 kworker/u8:0    root      0.0  0.0
    7     2 migration/0     root      0.0  0.0
    8     2 rcu_bh          root      0.0  0.0
    9     2 rcuob/0         root      0.0  0.0
   10     2 rcuob/1         root      0.0  0.0

process

ps -e --forest | grep sshd

lsof -p pid

disk and files

df -hP

du -h 

ls -i

ls -ltr

state file

fuser filename

lsof filename

network

ss -altp | grep

nestat -altp | grep

fuser -v -k -n tcp 80

lsof -i :80

dig 


nslookup


grep tcp/80 /etc/services




iptable

accounts and permission

w

last

id userid

chage -l userid
chage -M -1 userid

chmod 775 file

chmod -R 775 folder

chwon root. file


history

system

init 6 
reboot

shutdown -h +10
shutdown -r now

halt 
poweroff -f
df -pH

fdisk -l 


free -mh

sar -u 2 2 

sar -



cpu

lsof  -i 80

lsof -p pid



fuser  -v 


ps aux | grep httpd

ps -eo pid,com,%mem,%cpu 

ps -e —forest

top

ss -altp

ls -i 

ls -ltr

Last updated

Was this helpful?