Skip to content

Miscellaneous

aprops

The apropos command searches manual page names and descriptions for a user-supplied keyword.

aproprs <Keyword>

Example

$ apropos iscsi
iscsi-iname (8)      - iSCSI initiator name generation tool
iscsiadm (8)         - open-iscsi administration utility
iscsid (8)           - Open-iSCSI daemon
iscsistart (8)       - iSCSI boot tool
iscsiuio (8)         - iSCSI UserSpace I/O driver
$

dropwatch

It is a monitoring utility that monitors packets dropped by the kernel.

Ref: https://linux.die.net/man/1/dropwatch

dropwatch  

OR

dropwatch list

OR

dropwatch -l <metchod>

Note

  • By default the raw instruction pointer of a drop location is output, but by the use of the -l option, we can assign a translation method so that the instruction pointer can be translated into function names.
  • Currently supported lookup methods are:
  • kas - use "/proc/kallsyms" to lookup instruction pointers to function mappings

Example

dropwatch -l kas

grep

To print last N characters

Since there are two dots before "$" so so it will print last two characters

echo $<Variable> | grep -o '..$'

Since there are three dots before "$" so so it will print last three characters

echo $<Variable> | grep -o '...$'


lsof

Check processes associated with a port

lsof -i :<PortNumber>

Example

[root@localhost ~]# lsof -i :8000
COMMAND   PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
chrome  51818 suresh   36u  IPv4 1951648      0t0  TCP localhost:38218->localhost:irdmi (ESTABLISHED)
chrome  51818 suresh   38u  IPv4 1932001      0t0  TCP localhost:37992->localhost:irdmi (ESTABLISHED)
chrome  51818 suresh   50u  IPv4 1932002      0t0  TCP localhost:37994->localhost:irdmi (ESTABLISHED)
chrome  51818 suresh   57u  IPv4 1945486      0t0  TCP localhost:38166->localhost:irdmi (ESTABLISHED)
chrome  51818 suresh   58u  IPv4 1945487      0t0  TCP localhost:38168->localhost:irdmi (ESTABLISHED)
chrome  51818 suresh   59u  IPv4 1945488      0t0  TCP localhost:38170->localhost:irdmi (ESTABLISHED)
chrome  51818 suresh   60u  IPv4 1945489      0t0  TCP localhost:38172->localhost:irdmi (ESTABLISHED)
mkdocs  69651 suresh   12u  IPv4 1861859      0t0  TCP localhost:irdmi (LISTEN)
mkdocs  69651 suresh   19u  IPv4 1938994      0t0  TCP localhost:irdmi->localhost:37992 (ESTABLISHED)
mkdocs  69651 suresh   20u  IPv4 1938995      0t0  TCP localhost:irdmi->localhost:37994 (ESTABLISHED)
mkdocs  69651 suresh   22u  IPv4 1949110      0t0  TCP localhost:irdmi->localhost:38166 (ESTABLISHED)
mkdocs  69651 suresh   23u  IPv4 1949111      0t0  TCP localhost:irdmi->localhost:38168 (ESTABLISHED)
mkdocs  69651 suresh   24u  IPv4 1949112      0t0  TCP localhost:irdmi->localhost:38170 (ESTABLISHED)
mkdocs  69651 suresh   25u  IPv4 1949114      0t0  TCP localhost:irdmi->localhost:38172 (ESTABLISHED)
mkdocs  69651 suresh   26u  IPv4 1953223      0t0  TCP localhost:irdmi->localhost:38218 (ESTABLISHED)
[root@localhost ~]# 

ssh-keygen

To generate key

ssh-keygen

To generate public key from private key in SSH format

ssh-keygen -f <private key file> -y > <Public Key File>

Note

Here "y" : This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.


rsync

To copy data from one server to another

rsync -ave ssh  /home/* root@server:/home
OR
rsync -ave ssh  /home/ root@server:/home/

Note

  • If we will put /home then it will copy entire /home directory. And if we will use /home/ then it will copy data present in /home.
  • Same applies for destination location.

To copy with selinux context

rsync -azHAX /var/ /var_bck_acl/

openssl

To create private key

openssl genrsa -out mykey.pem 1024

To generate public key using private key

openssl rsa -in mykey.pem -pubout > mykey.pub
OR
openssl rsa -in mykey.pem -pubout -out mykey.pub


snmptrap

The below syntax can be used to send the snmp traps

snmptrap -c community [-p port] node_addr enterprise_id agent-addr generic " " [OID type value]

Note

Here

  • community -- public
  • port -- 162
  • node_addr -- please refer the agent address shared earlier
  • enterprise_id -- Enterprise SNMP OID
  • generic -- any snmp trap OID

Ref


stat

Displays file or file system status

To gets status of a file

stat <FileName>

Example

[root@localhost ~]# stat /etc/ssh/sshd_config 
File: /etc/ssh/sshd_config
Size: 4440          Blocks: 16         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 34203988    Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2019-10-09 18:30:04.000000000 +0530
Modify: 2019-10-09 18:30:04.000000000 +0530
Change: 2020-03-07 23:10:08.891521932 +0530
Birth: 2020-03-07 23:10:08.890521932 +0530
[root@localhost ~]#

To get status of a file system

stat <FileSystemName>

Example

[root@localhost ~]# stat /dev/mapper/fedora_localhost--live-home 
File: /dev/mapper/fedora_localhost--live-home -> ../dm-2
Size: 7             Blocks: 0          IO Block: 4096   symbolic link
Device: 6h/6d   Inode: 12722       Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:device_t:s0
Access: 2020-04-11 17:01:49.715954571 +0530
Modify: 2020-04-08 21:23:20.147691578 +0530
Change: 2020-04-08 21:23:20.147691578 +0530
Birth: -
[root@localhost ~]# 

To get the permission of a file in Octal Format

stat -c "%a %n" /etc/sudoers

Example

[root@localhost ~]# stat -c "%a %n" /etc/sudoers
440 /etc/sudoers
[root@localhost ~]#

telnet

Telnet using specific IP (interface)

Suppose your interface eth1 has IP1 and interface eth2 has IP2. And by default it is using IP1 (eth1) for telnet. So if you want to use IP2 (destination will recieve data using IP2, i.e., eth2), use the following command :

telnet -b <IP2> <destination IP> <port number>


xargs

Builds and execute command lines from standard input : That is, it will take standard input.

To find all the files which have 777 permission.

find / -type d -perm -0002 | xargs ls -ld

But, this is not the recommended way (as it will leave the files which would have space in path, which might cause distruction if wrong command is used). So, instead, you can use the following command :

find / -type d -perm -0002 | xargs -I '{}' ls -ld '{}'

Note

Here

  • -I : Replacement String (replace-str)
    • Replace occurrences of replace-str in the initial-arguments with names read from standard input.
    • Also, unquoted blanks do not terminate input items; instead the separator is the newline character.
    • Implies -x and -L 1.

xdpyinfo

Displays information of X server

Note

It can find out

  • Name of display:
  • Version number
  • Vendor name (such as The XFree86 Project)
  • Vendor release number
  • And XFree86 version number

zcat

This tool is used to read the data of gzipped file

zcat <FileName>.gz
Back to top