Frequently used Linux Commands

ifconfig - configure a network interface :
 

The “ifconfig” command with no arguments will display all the active interfaces details. The ifconfig command also used to check the assigned IP address of an server.

ifconfig -a

The following ifconfig command with -a argument will display information of all active or inactive network interfaces on server. It displays the results for eth0, lo.


Linux command to replace a keyword in multiple file :
find . -name '*.exp' | xargs sed  -i 's/set_topology/#set_topology/g'
In above example replace set_topology with #set_topology in all .exp files.

How to enable root access on Linux
configure
set system login user root authentication plaintext-password root123
commit
save
 

How to enable ssh root access on Linux
configure
set service ssh allow-root
commit
save


How to enable telnet root access on Linux
configure
set service telnet allow-root
commit
save


Linux command to find file size

df – show disk usage
du – show directory space usage
free – show memory and swap usage

 

du -h <filename>
[root@cisco /]# ls -lrt boot/
total 179175
-rwxr-xr-x. 1 root root  3811616 Dec  6  2011 vmlinuz-2.6.32-220.el6.i686
-rw-r--r--. 1 root root  1823458 Dec  6  2011 System.map-2.6.32-220.el6.i686
-rw-r--r--. 1 root root   105744 Dec  6  2011 config-2.6.32-220.el6.i686
-rw-r--r--. 1 root root   168173 Dec  6  2011 symvers-2.6.32-220.el6.i686.gz
-rw-r--r--. 1 root root  3242592 Oct  5  2012 vmlinuz-2.6.32.59-ZebOS7_10_1
-rw-r--r--. 1 root root  1551956 Oct  5  2012 System.map-2.6.32.59-ZebOS7_10_1
drwx------. 2 root root    12288 Dec  3  2012 lost+found
drwxr-xr-x. 3 root root     1024 Dec  3  2012 efi
-rw-r--r--. 1 root root 14733014 Dec  3  2012 initramfs-2.6.32-220.el6.i686.img
-rw-r--r--. 1 root root 77259645 Dec 10  2012 initramfs-2.6.32.59-ZebOS7_10_1.img
-rw-r--r--. 1 root root  3266176 Dec 12  2013 vmlinuz-2.6.32.59-ZebOS7_10_5
-rw-r--r--. 1 root root  1588509 Dec 12  2013 System.map-2.6.32.59-ZebOS7_10_5
-rw-r--r--. 1 root root 75887961 Nov 12  2014 initramfs-2.6.32.59-ZebOS7_10_5.img
drwxr-xr-x. 2 root root     1024 Nov 12  2014 grub

[root@cisco /]# du -h boot/
277K    boot/grub
239K    boot/efi/EFI/redhat
241K    boot/efi/EFI
243K    boot/efi
13K     boot/lost+found
176M    boot/

[root@cisco /]# ls boot/efi/
EFI

[root@cisco /]# ls boot/efi/EFI/
redhat

[root@cisco /]# ls boot/efi/EFI/redhat/
grub.efi
 

df -h
[root@cisco /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_vpc1-lv_root
                      5.8G  5.4G  107M  99% /
tmpfs                 187M     0  187M   0% /dev/shm
/dev/sda1             485M  186M  274M  41% /boot


[root@cisco /]# free -m
             total       used       free     shared    buffers     cached
Mem:           372        365          6          0        104         44
-/+ buffers/cache:        216        155
Swap:         1727          0       1727

/proc/meminfo

The next way to check memory usage is to read the /proc/meminfo file. Know that the /proc file system does not contain real files. They are rather virtual files that contain dynamic information about the kernel and the system.
[root@vpc11 /]# cat /proc/meminfo
MemTotal:         381296 kB
MemFree:            7092 kB
Buffers:          107104 kB
Cached:            45316 kB
SwapCached:          164 kB
Active:            94232 kB
Inactive:         114516 kB
Active(anon):      27924 kB
Inactive(anon):    28620 kB
Active(file):      66308 kB
Inactive(file):    85896 kB
Unevictable:           0 kB
Mlocked:               0 kB
HighTotal:             0 kB
HighFree:              0 kB
LowTotal:         381296 kB
LowFree:            7092 kB
SwapTotal:       1769464 kB
SwapFree:        1769072 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:         56188 kB
Mapped:            13044 kB
Shmem:               216 kB
Slab:             157340 kB
SReclaimable:     114640 kB
SUnreclaim:        42700 kB
KernelStack:         848 kB
PageTables:         1776 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1960112 kB
Committed_AS:     154048 kB
VmallocTotal:     509956 kB
VmallocUsed:        2916 kB
VmallocChunk:     467140 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:        8180 kB
DirectMap2M:      516096 kB

vmstat

The vmstat command with the s option, lays out the memory usage statistics much like the proc command. Here is an example

[root@vpc11 /]# vmstat -s
       381296  total memory
       374204  used memory
        94248  active memory
       114524  inactive memory
         7092  free memory
       107104  buffer memory
        45340  swap cache
      1769464  total swap
          392  used swap
      1769072  free swap
        17628 non-nice user cpu ticks
          250 nice user cpu ticks
        10176 system cpu ticks
     52401867 idle cpu ticks
        12789 IO-wait cpu ticks
         1328 IRQ cpu ticks
          398 softirq cpu ticks
            0 stolen cpu ticks
       820782 pages paged in
      1036644 pages paged out
            0 pages swapped in
          102 pages swapped out
      5308293 interrupts
     12370350 CPU context switches
   1434517884 boot time
        29304 forks


top command

The top command is generally used to check memory and cpu usage per process. However it also reports total memory usage and can be used to monitor the total RAM usage. The header on output has the required information. Here is a sample output

top - 12:25:44 up 6 days,  1:44,  3 users,  load average: 0.01, 0.02, 0.00
Tasks:  96 total,   1 running,  95 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    381296k total,   374452k used,     6844k free,   107128k buffers
Swap:  1769464k total,      392k used,  1769072k free,    45508k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
29044 root      20   0 11532 2612 1612 S  0.3  0.7   0:00.61 nsm
29306 root      20   0  2680 1064  844 R  0.3  0.3   0:00.06 top
    1 root      20   0  2892 1240 1064 S  0.0  0.3   0:02.44 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      20   0     0    0    0 S  0.0  0.0   0:01.62 ksoftirqd/0
    4 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    5 root      20   0     0    0    0 S  0.0  0.0   0:09.07 events/0

grep pattern file Search for pattern in file

  • grep -r pattern dir Search recursively for pattern in dir
  • command | grep pattern Search pattern in the output of a command
  • locate file Find all instances of file
  • find . -name filename Searches in the current directory (represented by a period) and below it, for files and directories with names starting with filename
  • pgrep pattern Searches for all the named processes , that matches with the pattern and, by default, returns their ID
Linux command to show Centos version running

[root@cisco ~]# cat /etc/*release
CentOS release 6.2 (Final)

[root@cisco ~]# lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.2 (Final)
Release:        6.2
Codename:       Final

ps uw -p <pid>

[root@VPC50 ~]# ps -ef | grep netconfd
root      1369  1224  0 16:26 pts/0    00:00:00 netconfd --superuser=root
root      1577  1516  0 16:31 pts/2    00:00:00 grep --color=auto netconfd
 

[root@VPC50 ~]# ps uw -p 1369
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1369  0.0  0.6  18748  6064 pts/0    S+   16:26   0:00 netconfd --superuser=root

 

No comments:

Post a Comment