Short Linux commands

  • • Use command sed to delete line 5 and line 20-25:
    • # sed -i ‘5d;20,25d’ /tmp/example.file
  • • Command to modify group membership
  • • Short loop to set password for multiple users
  • • 786: Add IP address to NIC with ip command:
    • # ip a add <192.168.55.0/24> dev eth0
  • • Useful package that allow tab completion:
    • # bash-completion
  • • Packages’ extensive documentation location
  • • Command to display one line manual page description:
    • # whatis
  • • Command to find man page with in description:
    • # man -k
  • • Command to get default systemd target:
    • # systemctl get-default
  • • Command to show all service units
  • • Command to show all target units
  • • List all dependencies on the default graphical.target unit
  • • To switch between target
  • • To display time required to boot system:
    • # systemd-analyze
  • • show log messages from specific boot:
    • # journalctl -b
  • • Filter log message by priority:
    • # journalctl -p
  • • Display cgroup hierarchy in a tree format:
    • # systemd-cgls
  • • Display a tree with all dependencies between units:
    • # systemctl list-units
  • • Display status of each unit file:
    • # systemctl list-unit-files
  • • Command to change effective primary group until session end:
    • # newgrp
  • • Command to set group password:
    • # gpasswd
  • • Command to set ACL on group access:
    • # setfacl -m g:: /tmp/example.dirorfile
  • • Command to set ACL on user access:
    • # setfacl -m u:: /tmp/example.dirorfile
  • • Command to set default ACL:
    • # setfacl -m d:g:: /tmp/example.dirorfile
  • • Command utilize ACL to set other with no permissions on anything that is created in a directory:
    • # setfacl -m d:o::- /tmp/example.dirorfile
  • • Command to backup and restore ACL:
    • # getfacl -R /tmp/example.file > /tmp/exampl.acls; setfacl – -restore=/tmp/example.acls
  • • Network device naming convention: en, wl, ww, o, s, p. E.g. enp2s0
  • • Command to show all existing network connections, in addition to statistic about the number packets that have been sent and associated error messages:
    • # ip -s link
  • • Command to show current address assignments for network interfaces on your server:
    • # ip a
  • • Commands to list all listening ports on local system:
    • # ss -lt or netstat -nap
  • • Command use to get more info on network manager setting and properties:
    • # man 5 nm-settings
  • • Command to verify current user permissions to change network configurations:
    • # nmcli gen permissions
  • • nmcli command to disable auto DNS when use DHCP:
    • # nmcli con mod ipv4.ignore-auto-dns yes
  • • RPM options that uses filenames as its argument to find the specific RPM package a file belongs to (example filename httpd):
    • # rpm -qf
  • • RPM options to provide a list of files in the installed RPM package:
    • # rpm -ql
  • • RPM options to provide information of installed package :
    • # rpm -qi
  • • RPM options to show all configuration files that are available in the installed package:
    • # rpm -qc
  • • RPM options to show scripts that are used in the package. This is particularly useful if combined with the -p option:
    • # rpm -q – -scripts
  • • RPM options to show dependencies for a specific package:
    • # rpm -qR
  • • RPM options to list out all files before installation:
    • # rpm -qlp
  • • RPM option to show which parts of a specific installed package have been changed since installation:
    • # rpm -V
  • • RPM options to verify all installed packages and shows which parts of the package have been changed since installation. An easy and convenient way to do a package integrity check:
    • # rpm -Va
  • • RPM options to list all packages that are installed:
    • # rpm -qa
  • • Create physical volumes:
    • # pvcreate
  • • Show a summary of available physical volumes:
    • # pvs
  • • Show a list of physical volumes and their properties:
    • # pvdisplay
  • • Removes the physical volume signature from a block device:
    • # pvremove
  • • Creates volume groups:
    • # vgcreate
  • • Shows a summary of available volumes groups:
    • # vgs
  • • Shows a detailed list of volume groups and their properties:
    • # vgdisplay
  • • Removes a volume group:
    • # vgremove
  • • Create a logical volume:
    • # lvcreate
  • • Show a summary of all available logical volume:
    • # lvs
  • • Show a detail list of available logical volumes and their properties:
    • # lvdisplay
  • • Removes a logical volume:
    • # lvremove
  • • Command lists all events that are processed while activating new hardware devices:
    • # udevadm monitor
  • • Show definition of specific target file (e.g. multi-user.target):
    • # systemctl cat multi-user.target
  • • Manual page contains all boot parameters may used while starting the kernel:
    • # man 7 bootparam
  • • Command used to debug shell script:
    • # bash -x <script.sh>