Generic-cli

Från wiki.soltec.se
Hoppa till: navigering, sök

Disks/PV/VG/LV info

Display a more readable output of disks/vols/mountpoints on Linux

  # lsblk -i

Physical Volumes

  # pvscan
  # pvdisplay

Volume Groups

  # vgscan
  # vgdisplay
  # vgchange
  # vgrename
  # vgs

Logical Volumes

  # lvscan
  # lgscan
  # lvdisplay
  # lvchange
  # lvs
  # lvresize
  # lvextend
  # lvreduce
  # lvrename

Rename Root Vol

To change the root vol name, boot from a bootable ISO or CDROM
Login and run the following

# vgrename <old-vg> <new-vg>

Mount the root disk & required sub filesystems

# mount /dev/<new-vg> /mnt
# mount --bind /proc /mnt/proc/
# mount --bind /sys /mnt/sys/
# mount --bind /dev /mnt/dev/
# mount /dev/sda1 /mnt/boot/
# chroot /mnt

Edit the fstab and grub files

# sed -i 's/<old-vg>/<new-vg>/g' /etc/fstab
# sed -i 's/<old-vg>/<new-vg>/g' /etc/default/grub

Use grub2-mkconfig

# grub2-mkconfig -o /boot/grub/grub.cfg

Create new kernel initramfs/initrd image file using a specific kernel version.

# dracut --force --kver <choose kernel vers>

Tips! Run <uname -r > to show the active kernel version or check for different versions in </boot> for required kernel name.

Use the following to check content of new initramfs/initrd image

List entire content
# lsinitrd <path-to-image>
View a specific file from the image file
# lsinitrd -f /etc/fstab <path-to-image>

unmount chroot & reboot

# umount -f /mnt
# shutdown -h now

Remove cdrom/ISO and reboot.

RPM

Find out what pkg a file belongs to

  # rpm -qf <path-to-file/cmd>

Find out if a file was installed as part of a pkg

  # rpm -ql /usr/liblibXp.so.6

Display system-wide config files for a cmd

  # rpm -qcf /bin/bash

Check contents of RPM

  # rpm -qlp RPMTOPDIR/RPMS/x86_64/<name-of-pkg>.rpm

To view different architecture version of a pkg

 # rpm -q --queryformat "%{name}.%{arch}\n" pdksh-5.2.14-36.el5

GREP

grep for soltec in start of line

  # grep ^"soltec"

grep for soltec at end of line

  # grep "soltec"$

YUM

to install all pkgs in listed in file

  # yum install $(< test.txt) 
  # yum -y install $(cat list)

Display history

  # yum history
  # yum history info
  # yum history list

VI

 dG	delete from line to end of file
 d1G	delete to top including current line
 dgg	delete from line to start of file
 G   goto last line in file
 1G	to to first line in file
 0	goto start of line
 $	goto end of line
 :set number	 <--to display line numbers
 :color desert  <--to change display colours


Copy/Move data

To move data on the same system, use the following:

  # cd dir1 && tar -cf - . | (cd dir2 && tar -xpvf -)
  dir1 is the directory you want to copy.
  dir2 is the directory in which you want the copy to go.
  This tar’s the current directory to STDOUT, then changes directory, 
  and untar’s the archive without ever having to find the space for a .tar file.

Use the following to do this across systems via ssh:

  # cd dir1 && tar -cf - . | ssh system2 "cd dir2 && tar -xpvf -"

RSYNC Slash or no Slash

  • Without a slash on the source directory means copy both the source directory, and the contents (recursively if specified) to the destination directory
  • Adding a trailing slash on the SRC directory means only copy the contents of the SRC directory, recursively if specified, to the destination.

RSYNC v RSYNCD

Use rysncd instead of rsync to use resources on the target system copying the data instead of source server

TOP

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

Usage:
top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]

Using cli

# top
# top –u dbuser                  | option will display specific User process details
# top -n 1 -b > top-output.txt   | save the running top command results output to a file
# top -n 10                      |automatically exit after 10 number of repetition.

Reading the output

N.B! By default, top updates its display every three seconds
  • The first line of numbers on the dashboard includes the time, how long your computer has been running, the number of people logged in, and what the load average has been for the past one, five, and 15 minutes.
  • The second line shows the number of tasks and their states: running, stopped, sleeping, or zombie.
  • The third line displays the following central processing unit (CPU) values:
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 fourth line shows the total amount (in kibibytes) of physical memory, and how much is free, used, and buffered or cached.
  • The fifth line shows the total amount (also in kibibytes) of swap memory, and how much is free, used, and available. The latter includes memory that’s expected to be recoverable from caches.

The column headings in the process list are as follows:

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).

Memory values are shown in kibibytes.

  • The status of the process can be one of the following:
D: Uninterruptible sleep
R: Running
S: Sleeping
T: Traced (stopped)
Z: Zombie
Press Q to exit top.

TOP interactive console

h          |help screen
z          |highlight processes in red
c          |display absolute path of running process
k          |kill a process after finding PID
d          |change default screen refresh interval  default= 3 seconds
Shift+P     | to sort processes as per CPU utilization
Shift+O     | to Sort field via field letter

You can also install htop which is more user-friendly / interactive than original top

URL: HTOP

SSH

Here are two links to great sites that explain SSH, Public & Private Keys, SSH-AGENT etc.

  # Using ssh-agent forwarding
  # ssh-agent forwarding

Date/time/NTP

Display systemclock, timezone and ntp status

$ timedatectl

Edit the time settings using timedatectl

$ timedatectl list-timezones
$ timedatectl set-timezone <t.ex CET>
$ timedatectl set-time <YYYY-MM-DD>
$ timedatectl set-time <HH:MM:SS>
$ timedatectl set-ntp true

AT/Cron

$ at now +15mins
       at> mkdir /apa
$ atq                  | display at queued jobs
$ atq -c <jobnr>       | displays the content of the job
$ atrm <jobnr>         | delete the job
$ batch
     at> mkdir /apa  --> ctlr-d to save

!N.B at batch jobs are only executed when the system load average is below 0.8

URL to a Crontab generator

Crontab Generator