Blog on [Linux]

Icon

Useful CentOS 7.n Commands

Jayan Kandathil

First published

If you administer CentOS Linux systems, the following commands would be useful.

Discovery

  • Display current CentOS version : cat /etc/centos-release
  • Display current Linux kernel version : uname -mrs
  • Display shell environment variables and their values : env
  • Display list of commands previously run : history
  • How long has the system been up? : uptime -p or uptime -s for the last datetime the system was rebooted
  • Default systemd "target" (formerly "runlevel") : systemctl get-default
  • Current "target" : who -r
  • List CPUs : lscpu
  • Memory utilization (in MB) : free -m or cat /proc/meminfo for more detailed information
  • List BLOCK devices (sd=scsi device) : lsblk
  • Display disk storage usage : df -hT
  • List devices attached to the PCI bus : lspci -vv
  • List USB devices : lsusb -v
  • List loaded kernel device drivers (modules) : lsmod
  • Boot parameters (boot images are in /boot) : cat /proc/cmdline
  • Determine boot time (and startup time of various services) : systemd-analyze blame, then q to exit.
  • List configured services : ls -alH /usr/lib/systemd/system Also check ls -alH /etc/systemd/system
  • Get details of the sshd service : cat /lib/systemd/system/ssh.service
  • Point top at a particular process : top -p [pid]
  • List available i/o schedulers for a storage device (sdc) : cat /sys/block/sdc/queue/scheduler

Logs

  • Display the contents of the kernel ring buffer : dmesg -wH or tail -f /var/log/dmesg

Disks, Filesystems

  • Display details of a disk : fdisk -l /dev/sdc
  • List available i/o schedulers for a storage device (sdc) : cat /sys/block/sdc/queue/scheduler
  • Change i/o scheduler at runtime : echo cfq > /sys/block/sdc/queue/scheduler
  • Create an ext4 filesystem : mkfs.ext4 -L DATA -v /dev/sdc1
  • Mount a filesystem : mount -o rw,noatime /dev/sdc1 /mnt/crx
  • Entry in /etc/fstab : Get UUID with blkid then UUID=fs6g5hj5675dsg-7g7d5778gd-877558g87g /mnt/crx ext4 defaults 0 2
  • Verify /etc/fstab entries before rebooting : mount -a
  • Verify the health of a filesystem : umount /mnt/crx then fsck /dev/sdc1
  • Get details of a filesystem : tune2fs -l /dev/sdc1 or dumpe2fs /dev/sdc1
  • Get details of inode utilization : df -i /dev/sdc1

Files

  • Get permissions for a folder : stat -c %a /mnt/crx for output in octal, or stat -c %A /mnt/crx
  • Get details of a file : stat /tmp/1.pdf
  • Create a symbolic link in /usr/files to the file /usr/pdf/1.pdf : ln -s /usr/pdf/1.pdf /usr/files/linkto1.pdf
  • Find all PDF files : find / -type f -name '*.pdf'
  • Find all PDF files using an index : locate '*.pdf' Index settings are in /etc/updatedb.conf (note that the contents of /tmp are excluded from the index)

Packages

stat bin

  • List all installed packages : rpm -qa
  • Get details of an already installed package (nano-2.3.1-10.el7.x86_64) : rpm -qi nano
  • Get details of a package file : rpm -qpi package.rpm
  • List the dependencies of a package file : rpm -qpR package.rpm
  • Install a package : rpm -ivh package.rpm
  • Yum (Yellowdog Updater Modified)configuration : /etc/yum.conf
  • Configured repositories : ls -alH /etc/yum.repos.d

Start/Stop

  • Reboot : shutown -r now
  • Shut down : shutdown -h now

See index for all entries in this blog.