What You’ll Learn

What You’ll Need

Linux is an open-source operating system that is used by many devices today, including computers, consumer appliances, and mobile, networking, and IoT devices. The best part of all is that Linux is free. This has contributed to the success of Linux as well as its continued evolution.

img.jpeg

The Linux ls command is used to list the names and features of files and directories.

[root@linux /]$ ls
afs  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

However, using the ls without its many options will only display generic information.

If you want to list all hidden files and folders, use the -a option, but if you wish to display the permission of the files and folders, then the -l option will also be needed.

[root@linux /]$ ls -la
total 24
dr-xr-xr-x.  18 root root  235 Nov  5  2022 .
dr-xr-xr-x.  18 root root  235 Nov  5  2022 ..
dr-xr-xr-x.   2 root root    6 Aug  9  2022 afs
lrwxrwxrwx.   1 root root    7 Aug  9  2022 bin -> usr/bin
dr-xr-xr-x.   7 root root 4096 Aug 19 19:07 boot
drwxr-xr-x.  18 root root 3780 Aug 20 15:13 dev
drwxr-xr-x. 115 root root 8192 Aug 20 02:08 etc
drwxr-xr-x.   3 root root   19 Oct 24  2022 home
lrwxrwxrwx.   1 root root    7 Aug  9  2022 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Aug  9  2022 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Aug  9  2022 media
drwxr-xr-x.   2 root root    6 Aug  9  2022 mnt
drwxr-xr-x.   2 root root    6 Aug  9  2022 opt
dr-xr-xr-x. 240 root root    0 Dec 31  1969 proc
dr-xr-x---.   2 root root 4096 Aug 20 13:56 root
drwxr-xr-x.  43 root root 1200 Aug 19 21:51 run
lrwxrwxrwx.   1 root root    8 Aug  9  2022 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Aug  9  2022 srv
dr-xr-xr-x.  12 root root    0 Mar 31 00:00 sys
drwxrwxrwt.   9 root root  180 Aug 21 12:35 tmp
drwxr-xr-x.  12 root root  144 Nov  5  2022 usr
drwxr-xr-x.  21 root root 4096 Aug 19 19:12 var

Once you display the files and folders on the Linux system using the ls command, you will need the cd command to change directories, allowing you to go into a folder to access the contents.


[root@linux /]$ cd etc/
[root@linux /]$ ls -la
total 1336
drwxr-xr-x. 115 root root     8192 Aug 20 02:08 .
dr-xr-xr-x.  18 root root      235 Nov  5  2022 ..
drwxr-xr-x.   3 root root      101 Jun 30 08:21 abrt
-rw-r--r--.   1 root root       18 Oct 24  2022 adjtime
-rw-r--r--.   1 root root     1529 Jul 20  2022 aliases
drwxr-xr-x.   2 root root     4096 May  4 11:25 alternatives
drwxr-xr-x.   4 root root       58 Nov  5  2022 anaconda
-rw-r--r--.   1 root root      541 Jul 20  2022 anacrontab
-rw-r--r--.   1 root root        1 Jul 20  2022 at.deny
drwxr-x---.   4 root root      100 Apr 27 14:40 audit
drwxr-xr-x.   3 root root     4096 Aug 19 19:05 authselect
-rw-r--r--.   1 root root    15843 Mar 28 23:17 autofs.conf
-rw-------.   1 root root      232 Mar 28 23:17 autofs_ldap_auth.conf
-rw-r--r--.   1 root root     1289 Mar 28 23:17 auto.master
drwxr-xr-x.   2 root root        6 Mar 28 23:17 auto.master.d
-rw-r--r--.   1 root root      519 Mar 28 23:17 auto.misc
-rwxr-xr-x.   1 root root      901 Mar 28 23:17 auto.net
-rwxr-xr-x.   1 root root     2087 Mar 28 23:17 auto.smb
drwxr-xr-x.   2 root root       75 Aug 19 19:04 bash_completion.d
-rw-r--r--.   1 root root     2638 Jul 20  2022 bashrc
-rw-r--r--.   1 root root      535 Apr 21 21:52 bindresvport.blacklist
drwxr-xr-x.   2 root root        6 Mar 31 13:24 binfmt.d
drwxr-xr-x.   2 root root       23 Aug 19 18:57 bluetooth
drwxr-xr-x.   2 root root       29 Dec  1  2022 certmonger
-rw-r--r--.   1 root root     1371 Aug 29  2022 chrony.conf
-rw-r-----.   1 root chrony    540 Aug 29  2022 chrony.keys
drwxr-xr-x.   2 root root       26 Jun 26 07:07 cifs-utils
drwxr-xr-x.   4 root root       42 Jul 12 04:48 cockpit
drwxr-xr-x.   7 root root      134 Aug 19 18:58 containers
drwxr-xr-x.   2 root root       21 Nov  5  2022 cron.d
drwxr-xr-x.   2 root root        6 Jul 20  2022 cron.daily
-rw-r--r--.   1 root root        0 Jul 20  2022 cron.deny
drwxr-xr-x.   2 root root       22 Nov  5  2022 cron.hourly
drwxr-xr-x.   2 root root        6 Jul 20  2022 cron.monthly
-rw-r--r--.   1 root root      451 Jul 20  2022 crontab
drwxr-xr-x.   2 root root        6 Jul 20  2022 cron.weekly
drwxr-xr-x.   6 root root       81 Nov  5  2022 crypto-policies
-rw-------.   1 root root        0 Nov  5  2022 crypttab
-rw-r--r--.   1 root root     1401 Jul 20  2022 csh.cshrc
-rw-r--r--.   1 root root     1087 Jul 20  2022 csh.login
drwxr-xr-x.   4 root root       78 Jun  6 16:59 dbus-1
drwxr-xr-x.   4 root root       31 Nov  5  2022 dconf
drwxr-xr-x.   2 root root       27 Nov  5  2022 debuginfod
drwxr-xr-x.   2 root root       33 Nov  5  2022 default
drwxr-xr-x.   2 root root        6 Jul 21  2022 depmod.d
drwxr-x---.   3 root root       61 Aug 20 13:49 dhcp
-rw-r--r--.   1 root root     5169 May  4 17:53 DIR_COLORS
-rw-r--r--.   1 root root     5251 May  4 17:53 DIR_COLORS.lightbgcolor
drwxr-xr-x.   8 root root      128 Jul 28 08:42 dnf
-rw-r--r--.   1 root root    28485 Apr  3 11:01 dnsmasq.conf
drwxr-xr-x.   2 root root        6 Apr  3 11:01 dnsmasq.d
-rw-r--r--.   1 root root      117 Apr 27 07:55 dracut.conf
drwxr-xr-x.   2 root root        6 Apr 27 07:55 dracut.conf.d
-rw-r--r--.   1 root root        0 Jul 23  2022 environment
-rw-r--r--.   1 root root     1362 Jul 20  2022 ethertypes
-rw-r--r--.   1 root root        0 Jul 20  2022 exports
drwxr-xr-x.   2 root root        6 Apr 20 09:25 exports.d
lrwxrwxrwx.   1 root root       56 Jul 20  2022 favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.png
lrwxrwxrwx.   1 root root       25 Feb 23 10:23 fedora-release -> ../usr/lib/fedora-release
-rw-r--r--.   1 root root       66 Jul 20  2022 filesystems
drwxr-x---.   8 root root     4096 Aug 19 19:53 firewalld
drwxr-xr-x.   3 root root       20 Nov  5  2022 fonts
-rw-r--r--.   1 root root       20 Feb 24  2022 fprintd.conf
-rw-r--r--.   1 root root      590 Nov  5  2022 fstab
-rw-r--r--.   1 root root       38 Jul 20  2022 fuse.conf
drwxr-xr-x.   4 root root      110 Aug 19 19:04 fwupd
drwxr-xr-x.   2 root root        6 Jul 21  2022 gcrypt
-rw-r--r--.   1 root root      265 Jun 30 22:06 gdbinit
drwxr-xr-x.   2 root root        6 Jun 30 22:06 gdbinit.d
drwxr-xr-x.   2 root root        6 Oct 18  2022 gnupg
-rw-r--r--.   1 root root       94 Jul 21  2022 GREP_COLORS
drwxr-xr-x.   4 root root       40 Nov  5  2022 groff
-rw-r--r--.   1 root root      756 Aug 19 19:51 group
-rw-r--r--.   1 root root      743 Aug 19 19:12 group-
lrwxrwxrwx.   1 root root       22 Apr 10 13:05 grub2.cfg -> ../boot/grub2/grub.cfg
lrwxrwxrwx.   1 root root       22 Apr 10 13:05 grub2-efi.cfg -> ../boot/grub2/grub.cfg
drwx------.   2 root root     4096 Aug 19 19:04 grub.d
----------.   1 root root      616 Aug 19 19:51 gshadow
----------.   1 root root      606 Aug 19 19:12 gshadow-
drwxr-xr-x.   3 root root       20 Nov 16  2022 gss
drwxr-xr-x.   2 root root       87 Nov  5  2022 gssproxy
-rw-r--r--.   1 root root        9 Jul 20  2022 host.conf
-rw-r--r--.   1 root root       11 Aug 19 20:33 hostname
-rw-r--r--.   1 root root      386 Jul 20  2022 hosts
-rw-r--r--.   1 root root     5799 Apr 20 09:25 idmapd.conf
drwxr-xr-x.   3 root root       20 Nov  5  2022 initial-setup
-rw-r--r--.   1 root root      490 Mar 31 13:24 inittab
-rw-r--r--.   1 root root      943 Jul 20  2022 inputrc
drwxr-xr-x.   3 root root       19 Nov 27  2022 ipa
drwxr-xr-x.   2 root root      159 Nov  5  2022 iproute2
drwxr-xr-x.   2 root root       25 Nov  5  2022 iscsi
lrwxrwxrwx.   1 root root       16 Feb 23 10:23 issue -> ../usr/lib/issue
drwxr-xr-x.   2 root root       27 Feb 23 10:23 issue.d
lrwxrwxrwx.   1 root root       20 Feb 23 10:23 issue.net -> ../usr/lib/issue.net
drwxr-xr-x.   4 root root       33 Nov  5  2022 kdump
-rw-r--r--.   1 root root     8892 Nov  5  2022 kdump.conf
drwxr-xr-x.   3 root root       38 Mar 31 13:24 kernel
-rw-r--r--.   1 root root      880 Nov 16  2022 krb5.conf
drwxr-xr-x.   2 root root      106 Nov 16  2022 krb5.conf.d
-rw-r--r--.   1 root root    23163 Aug 19 19:51 ld.so.cache
-rw-r--r--.   1 root root       28 Jan 10  2023 ld.so.conf
drwxr-xr-x.   2 root root        6 Jan 11  2023 ld.so.conf.d
-rw-r-----.   1 root root      191 Apr 27 13:26 libaudit.conf
drwxr-xr-x.   3 root root       20 Nov  5  2022 libblockdev
drwxr-xr-x.   2 root root     4096 Nov  5  2022 libibverbs.d
drwxr-xr-x.   2 root root       35 Nov  5  2022 libnl
drwxr-xr-x.   6 root root     4096 Aug 19 18:57 libreport
drwxr-xr-x.   2 root root       62 May 15 06:28 libssh
-rw-r--r--.   1 root root     2393 Sep 23  2022 libuser.conf
-rw-r--r--.   1 root root       19 Oct 24  2022 locale.conf
lrwxrwxrwx.   1 root root       32 Oct 24  2022 localtime -> ../usr/share/zoneinfo/US/Eastern
-rw-r--r--.   1 root root     8676 Mar 27 08:13 login.defs
-rw-r--r--.   1 root root      493 Apr 16  2021 logrotate.conf
drwxr-xr-x.   2 root root     4096 Aug 19 19:12 logrotate.d
drwxr-xr-x.   6 root root      100 Nov  5  2022 lvm
-rw-r--r--.   1 root root       33 Oct 24  2022 machine-id
-rw-r--r--.   1 root root      111 Jul 26  2022 magic
-rw-r--r--.   1 root root      272 Apr 27  2021 mailcap
-rw-r--r--.   1 root root     5122 Aug  3  2022 makedumpfile.conf.sample
-rw-r--r--.   1 root root     5235 Jul 21  2022 man_db.conf
-rw-r--r--.   1 root root    69857 Apr 27  2021 mime.types
-rw-r--r--.   1 root root      782 Jul 20  2022 mke2fs.conf
drwxr-xr-x.   2 root root       54 Aug 19 19:04 modprobe.d
drwxr-xr-x.   2 root root        6 Mar 31 13:24 modules-load.d
-rw-r--r--.   1 root root        0 Jul 20  2022 motd
drwxr-xr-x.   2 root root       21 Nov  5  2022 motd.d
lrwxrwxrwx.   1 root root       19 Aug  4  2022 mtab -> ../proc/self/mounts
drwxr-xr-x.   2 root root        6 Nov 15  2022 multipath
drwxr-x---.   2 root named       6 Jul 20 06:17 named
-rw-r-----.   1 root named    1934 Aug 19 20:48 named.conf
-rw-r-----.   1 root named   12288 Aug 19 19:13 .named.conf.swp
-rw-r-----.   1 root named    1034 Jul 20 06:17 named.rfc1912.zones
-rw-r--r--.   1 root named     686 Jul 20 06:17 named.root.key
-rw-r--r--.   1 root root      767 Apr 21 21:52 netconfig
drwxr-xr-x.   7 root root      134 Apr 20 07:38 NetworkManager
-rw-r--r--.   1 root root       58 Jul 20  2022 networks
-rw-r--r--.   1 root root     1468 Apr 20 09:25 nfs.conf
-rw-r--r--.   1 root root     3604 Apr 20 09:25 nfsmount.conf
drwx------.   3 root root       66 Nov  5  2022 nftables
lrwxrwxrwx.   1 root root       29 Aug 19 19:05 nsswitch.conf -> /etc/authselect/nsswitch.conf
drwxr-xr-x.   2 root root        6 Dec  9  2022 oddjob
-rw-r--r--.   1 root root     4922 Dec  9  2022 oddjobd.conf
drwxr-xr-x.   2 root root       70 Dec  9  2022 oddjobd.conf.d
drwxr-xr-x.   2 root root       75 Nov  5  2022 openhpi
drwxr-xr-x.   4 root root       50 Mar  7 18:52 openldap
lrwxrwxrwx.   1 root root       16 Aug  8 09:10 opensc-aarch64.conf -> /etc/opensc.conf
-rw-r--r--.   1 root root      441 Aug  8 09:08 opensc.conf
drwxr-xr-x.   2 root root        6 Aug  9  2022 opt
lrwxrwxrwx.   1 root root       21 Feb 23 10:23 os-release -> ../usr/lib/os-release
drwxr-xr-x.   3 root root       23 Nov 23  2022 ostree
drwxr-xr-x.   2 root root       48 Jan 24  2023 PackageKit
drwxr-xr-x.   2 root root     4096 Aug 19 19:05 pam.d
-rw-r--r--.   1 root root     1767 Aug 19 19:51 passwd
-rw-r--r--.   1 root root     1723 Aug 19 19:12 passwd-
-rw-r--r--.   1 root root      263 Jun 23 06:36 passwdqc.conf
-rw-r--r--.   1 root root     2872 Jul 22  2022 pinforc
drwxr-xr-x.   3 root root       21 Jul 24 03:39 pkcs11
drwxr-xr-x.   3 root root       27 Nov  5  2022 pkgconfig
drwxr-xr-x.  10 root root      123 Nov  5  2022 pki
drwxr-xr-x.   2 root root       28 Nov  5  2022 plymouth
drwxr-xr-x.   5 root root       52 Nov  5  2022 pm
drwxr-xr-x.   5 root root       72 Apr 11 06:30 polkit-1
drwxr-xr-x.   2 root root        6 Sep 16  2022 popt.d
-rw-r--r--.   1 root root      233 Jul 20  2022 printcap
-rw-r--r--.   1 root root     1945 Jul 20  2022 profile
drwxr-xr-x.   2 root root     4096 Aug 19 19:04 profile.d
-rw-r--r--.   1 root root     6568 Jul 20  2022 protocols
-rw-------.   1 root root        0 Nov  5  2022 .pwd.lock
drwxr-xr-x.   3 root root       50 Aug 19 19:04 qemu-ga
drwxr-xr-x.   3 root root       20 Mar 31 13:24 rc.d
drwxr-xr-x.   2 root root       25 Sep 19  2022 reader.conf.d
lrwxrwxrwx.   1 root root       14 Feb 23 10:23 redhat-release -> fedora-release
-rw-r--r--.   1 root root     1787 Jul 21  2022 request-key.conf
drwxr-xr-x.   2 root root       77 Nov  5  2022 request-key.d
lrwxrwxrwx.   1 root root       39 Nov  5  2022 resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
-rw-r-----.   1 root named     100 Aug 19 19:21 rndc.key
-rw-r--r--.   1 root root     1634 Jan 10  2023 rpc
drwxr-xr-x.   2 root root        6 Apr 24 08:06 rpm
-rw-r--r--.   1 root root      458 Oct 21  2022 rsyncd.conf
-rw-r--r--.   1 root root     3223 Jul 27  2022 rsyslog.conf
drwxr-xr-x.   2 root root        6 Jul 27  2022 rsyslog.d
drwxr-xr-x.   2 root root       64 Aug 19 19:12 rwtab.d
drwxr-xr-x.   2 root root       61 Aug 19 18:57 samba
drwxr-xr-x.   2 root root        6 Aug 18  2022 sasl2
drwxr-xr-x.   7 root root     4096 Feb  1  2023 security
drwxr-xr-x.   3 root root       79 Mar 27 08:07 selinux
-rw-r--r--.   1 root root    10593 Jul 21  2022 sensors3.conf
drwxr-xr-x.   2 root root        6 Jul 21  2022 sensors.d
-rw-r--r--.   1 root root   701745 Jul 20  2022 services
-rw-r--r--.   1 root root      216 Feb 27 13:23 sestatus.conf
drwxr-xr-x.   2 root root       33 Feb 27 11:38 setroubleshoot
----------.   1 root root      984 Aug 19 19:51 shadow
----------.   1 root root      963 Aug 19 19:12 shadow-
-rw-r--r--.   1 root root       44 Jul 20  2022 shells
drwxr-xr-x.   2 root root       62 Nov  5  2022 skel
drwxr-xr-x.   3 root root       74 Aug 19 19:04 smartmontools
drwxr-xr-x.   6 root root       86 Nov  5  2022 sos
drwxr-xr-x.   4 root root     4096 Jul 21 11:31 ssh
drwxr-xr-x.   2 root root       91 Aug 19 18:55 ssl
drwx------.   4 root root       31 Jun 26 07:07 sssd
drwxr-xr-x.   2 root root        6 Aug  9  2022 statetab.d
-rw-r--r--.   1 root root       19 Oct 24  2022 subgid
-rw-r--r--.   1 root root        0 Jul 20  2022 subgid-
-rw-r--r--.   1 root root       19 Oct 24  2022 subuid
-rw-r--r--.   1 root root        0 Jul 20  2022 subuid-
-rw-r-----.   1 root root     4316 Mar  1 12:08 sudo.conf
-r--r-----.   1 root root     4375 Mar  1 12:04 sudoers
drwxr-x---.   2 root root        6 Mar  1 12:08 sudoers.d
drwxr-xr-x.   3 root root       24 Feb 23 10:23 swid
drwxr-xr-x.   3 root root     4096 Aug 19 19:51 sysconfig
-rw-r--r--.   1 root root      449 Mar 31 13:24 sysctl.conf
drwxr-xr-x.   2 root root       28 Mar 31 13:24 sysctl.d
drwxr-xr-x.   5 root root     4096 Mar 31 13:24 systemd
lrwxrwxrwx.   1 root root       14 Feb 23 10:23 system-release -> fedora-release
lrwxrwxrwx.   1 root root       29 Feb 23 10:23 system-release-cpe -> ../usr/lib/system-release-cpe
drwxr-xr-x.   2 root root        6 Jun  6 04:41 terminfo
drwxr-xr-x.   2 root root        6 Mar 31 13:24 tmpfiles.d
drwxr-xr-x.   3 root root       51 Aug 19 18:56 tpm2-tss
-rw-r--r--.   1 root root      375 Jul 20 06:17 trusted-key.key
drwxr-xr-x.   4 root root       68 Aug 19 19:08 udev
drwxr-xr-x.   3 root root       82 Nov  5  2022 udisks2
-rw-r--r--.   1 root root      208 Nov  5  2022 .updated
-rw-r--r--.   1 root root      616 Dec 27  2022 updatedb.conf
-rw-r--r--.   1 root root       28 Oct 24  2022 vconsole.conf
-rw-r--r--.   1 root root     4017 Jul 21 03:09 vimrc
-rw-r--r--.   1 root root     1183 Jul 21 03:09 virc
drwxr-xr-x.   4 root root     4096 Aug 19 19:04 vmware-tools
-rw-r--r--.   1 root root     4925 Jul 23  2022 wgetrc
-rw-r--r--.   1 root root      380 Jan  3  2022 whois.conf
drwxr-xr-x.   2 root root       33 Nov  5  2022 wpa_supplicant
drwxr-xr-x.   6 root root       70 Nov  5  2022 X11
-rw-r--r--.   1 root root      817 Jul 20  2022 xattr.conf
drwxr-xr-x.   4 root root       38 Nov  5  2022 xdg
drwxr-xr-x.   2 root root     4096 Jan 29  2023 yum.repos.d
[root@linux etc]$

Notice that the Linux prompt information changes from [root@linux /] to [root@linux etc]$, reflecting the directory that you are in. The pwd command can also be used to display the present working directory.

[root@linux /]$ pwd
/etc

The Linux more command is a command-line utility that allows users to view text files one page at a time.

For example, let’s assume that you are in the /etc directory, and you want to view the content of a file called hosts. The more command can be used to display the content of that file.


[root@linux /]$ more hosts

# Loopback entries; do not change.
# For historical reasons, localhost precedes localhost.localdomain:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
# See hosts(5) for proper format and other examples:
# 192.168.1.10 foo.mydomain.org foo
# 192.168.1.13 bar.mydomain.org bar

(END)

Notice that the more command puts you into a view mode, meaning that you can view more pages by using the space bar on your computer. Once you reach the end of the document, you will see (END) at the bottom. In order to exit, you will need to type the letter q to exit the view mode.

The Linux top command allows the user to see which resources are taking up the most CPU on the system based on system process and application names. It gives you an overall view of the current state of the CPU utilization. Once the top command is used, it will put you into a top-view mode that will display the information in real time.


top - 13:49:52 up 1 day, 17:39,  1 user,  load average: 0.09, 0.08, 0.08
Tasks: 178 total,   1 running, 177 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.2 us,  0.2 sy,  0.0 ni, 99.4 id,  0.0 wa,  0.1 hi,  0.1 si,  0.0 st
MiB Mem :   7824.7 total,   6236.1 free,    536.1 used,   1052.6 buff/cache
MiB Swap:   7824.0 total,   7824.0 free,      0.0 used.   7039.0 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
    716 systemd+  20   0   17688   6656   5888 S   0.7   0.1   7:45.83 systemd-oomd
  19142 spawn     20   0  225248   3200   2560 R   0.7   0.0   0:00.11 top
   9692 named     20   0  641304  32232   7680 S   0.3   0.4   7:03.56 named
      1 root      20   0  174536  15800   9384 S   0.0   0.2   0:16.74 systemd
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.50 kthreadd
      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp
      5 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 slub_flushwq
      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 netns
     11 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 mm_percpu_wq
     13 root      20   0       0      0      0 I   0.0   0.0   0:00.00 rcu_tasks_kthread
     14 root      20   0       0      0      0 I   0.0   0.0   0:00.00 rcu_tasks_rude_kthread
     15 root      20   0       0      0      0 I   0.0   0.0   0:00.00 rcu_tasks_trace_kthread
     16 root      20   0       0      0      0 S   0.0   0.0   0:00.38 ksoftirqd/0
     17 root      20   0       0      0      0 I   0.0   0.0   0:27.38 rcu_preempt
     18 root      rt   0       0      0      0 S   0.0   0.0   0:00.33 migration/0
     19 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp/0

There are a lot of values being displayed using the top command, including:


us: Amount of time the CPU spends executing processes for people in "user space."
sy: Amount of time spent running system "kernel space" processes.
ni: Amount of time spent executing processes with a manually set nice value.
id: Amount of CPU idle time.
wa: Amount of time the CPU spends waiting for I/O to complete.
hi: Amount of time spent servicing hardware interrupts.
si: Amount of time spent servicing software interrupts.
st: Amount of time lost due to running virtual machines ("steal time").

The column headings information displays the following:

PID: Process ID.
USER: The owner of the process.
PR: Process priority.
NI: The nice value of the process.
VIRT: Amount of virtual memory used by the process.
RES: Amount of resident memory used by the process.
SHR: Amount of shared memory used by the process.
S: Status of the process. (See the list below for the values this field can take).
%CPU: The share of CPU time used by the process since the last update.
%MEM: The share of physical memory used.
TIME+: Total CPU time used by the task in hundredths of a second.
COMMAND: The command name or command line (name + options).

Because the top command will display information in real time, it will show the status information as follows:

D: Uninterruptible sleep
R: Running
S: Sleeping
T: Traced (stopped)
Z: Zombie

To exit from top-view mode, you will need to use the q key on your keyboard.

The Linux netstat command is used to print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. We will be using it to print network connection and routing table information.

To display both listening and nonlistening sockets, you can use the -a option.


[root@linux /]$ netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:domain        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN
tcp        0      0 dns-master:domain       0.0.0.0:*               LISTEN
tcp        0      0 localhost:domain        0.0.0.0:*               LISTEN
tcp        0      0 localhost:domain        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:hostmon         0.0.0.0:*               LISTEN
tcp        0      0 localhost:rndc          0.0.0.0:*               LISTEN
tcp        0    172 dns-master:ssh          172.16.1.36:56450       ESTABLISHED
tcp6       0      0 [::]:websm              [::]:*                  LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
tcp6       0      0 [::]:hostmon            [::]:*                  LISTEN
udp        0      0 0.0.0.0:hostmon         0.0.0.0:*
udp        0      0 dns-master:domain       0.0.0.0:*
udp        0      0 dns-master:domain       0.0.0.0:*
udp        0      0 dns-master:domain       0.0.0.0:*
udp        0      0 dns-master:domain       0.0.0.0:*
udp        0      0 localhost:domain        0.0.0.0:*
udp        0      0 localhost:domain        0.0.0.0:*
udp        0      0 localhost:domain        0.0.0.0:*
udp        0      0 localhost:domain        0.0.0.0:*
udp        0      0 localhost:domain        0.0.0.0:*
udp        0      0 localhost:domain        0.0.0.0:*
udp        0      0 0.0.0.0:bootps          0.0.0.0:*
udp        0      0 localhost:323           0.0.0.0:*
udp6       0      0 [::]:hostmon            [::]:*
udp6       0      0 localhost:323           [::]:*
udp6       0      0 dns-maste:dhcpv6-client [::]:*
raw        0      0 0.0.0.0:icmp            0.0.0.0:*               7
raw6       0      0 [::]:ipv6-icmp          [::]:*                  7

Notice that it will display the hostname information under the Local Address. To display the IP address instead, you will need to use the -n option.


[root@linux /]$ netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.54:53           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 192.168.1.26:53         0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN
tcp        0    172 192.168.1.26:22         172.16.1.36:56450       ESTABLISHED
tcp6       0      0 :::9090                 :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::5355                 :::*                    LISTEN
udp        0      0 0.0.0.0:5355            0.0.0.0:*
udp        0      0 192.168.1.26:53         0.0.0.0:*
udp        0      0 192.168.1.26:53         0.0.0.0:*
udp        0      0 192.168.1.26:53         0.0.0.0:*
udp        0      0 192.168.1.26:53         0.0.0.0:*
udp        0      0 127.0.0.1:53            0.0.0.0:*
udp        0      0 127.0.0.1:53            0.0.0.0:*
udp        0      0 127.0.0.1:53            0.0.0.0:*
udp        0      0 127.0.0.1:53            0.0.0.0:*
udp        0      0 127.0.0.54:53           0.0.0.0:*
udp        0      0 127.0.0.53:53           0.0.0.0:*
udp        0      0 0.0.0.0:67              0.0.0.0:*
udp        0      0 127.0.0.1:323           0.0.0.0:*
udp6       0      0 :::5355                 :::*
udp6       0      0 ::1:323                 :::*
udp6       0      0 fe80::a1bf:3dd6:350:546 :::*
raw        0      0 0.0.0.0:1               0.0.0.0:*
raw6       0      0 :::58                   :::*

In order to display all ports that are listening on the Linux server, you can use the grep filter.

[root@linux /]$ netstat -an | grep LISTEN
tcp        0      0 127.0.0.54:53           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 192.168.1.26:53         0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN
tcp6       0      0 :::9090                 :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::5355                 :::*                    LISTEN

The grep | LISTEN filter is very useful because it allows the administrator to see which services are being advertised on the server and which IP/port is being used to make it accessible to the user.

If you use the grep | ESTABLISHED filter, it will allow the administrator to see who is connected to the server using a certain IP/port.


[root@linux /]$ netstat -an | grep ESTABLISHED
tcp        0      0 192.168.1.26:22         172.16.1.36:56450       ESTABLISHED
udp        0      0 192.168.1.26:56495      198.97.190.53:53        ESTABLISHED

The -r option allows the administrator of the Linux server to see which routing table information is populated.

[root@linux /]$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         _gateway        0.0.0.0         UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

If the administrator wants to see multicast information on all interfaces, they can use the -g option instead.

[root@linux /]$ netstat -g
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      224.0.0.1
eth0            1      224.0.0.252
eth0            1      224.0.0.1
wlan0           1      224.0.0.1
lo              1      ff02::1
lo              1      ff01::1
eth0            1      ff02::1:ff69:467
eth0            1      ff02::1:3
eth0            1      ff02::1:ff02:c715
eth0            1      ff02::1
eth0            1      ff01::1
wlan0           1      ff02::1
wlan0           1      ff01::1

Learn More