Table des matières
Last updated on: 2020/01/30 03:28
Basic Shell Commands and Text Manipulation Tools
To do - You are currently the root user in your terminal. Before proceeding further, type exit and hit the ↵ Enter key.
Use of Basic Shell Commands
The stty Command
Using this command with the -a switch allows you to identify which combination of keys should be used to control a foreground process:
trainee@debian8:~$ stty -a speed 38400 baud; rows 23; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
trainee@ubuntu1604:~$ stty -a speed 38400 baud; rows 26; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
[trainee@centos7 ~]$ stty -a speed 38400 baud; rows 26; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
trainee@SLES12SP1:~> stty -a speed 38400 baud; rows 24; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
The two most important combinations are intr = ^C and susp = ^Z. The former kills the process whilst the latter suspends its execution.
Command Line Switches
To do : Use the –help option of the stty command to view the command line switches.
The date command
This command's output gives the current system date and time. The command can also be used to set the system date:
trainee@debian8:~$ date Fri 19 Aug 04:44:26 BST 2016
trainee@ubuntu1604:~$ date Fri 30 Sep 15:19:21 CEST 2016
[trainee@centos7 ~]$ date Thu 29 Sep 04:53:58 CEST 2016
trainee@SLES12SP1:~> date Fri 30 Sep 15:19:54 CEST 2016
Command Line Switches
To do : Use the –help option of the date command to view the command line switches.
The who Command
This command's output shows who is currently connected to the system:
trainee@debian8:~$ who trainee pts/0 2016-08-18 23:33 (10.0.2.2)
trainee@ubuntu1604:~$ who trainee pts/0 2016-09-29 20:36 (10.0.2.2)
[trainee@centos7 ~]$ who trainee pts/0 2016-09-28 23:29 (gateway)
trainee@SLES12SP1:~> who trainee pts/0 2016-09-30 10:24 (10.0.2.2)
Command Line Switches
To do : Use the –help option of the who command to view the command line switches.
The df Command
This command's output shows the free space on each mounted block device:
trainee@debian8:~$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 9947060 3386724 6031956 36% / udev 10240 0 10240 0% /dev tmpfs 101256 4796 96460 5% /run tmpfs 253132 0 253132 0% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 253132 0 253132 0% /sys/fs/cgroup tmpfs 50628 0 50628 0% /run/user/1000
trainee@ubuntu1604:~$ df Filesystem 1K-blocks Used Available Use% Mounted on udev 230832 0 230832 0% /dev tmpfs 50028 2864 47164 6% /run /dev/sda1 9480420 4269160 4706636 48% / tmpfs 250124 0 250124 0% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 250124 0 250124 0% /sys/fs/cgroup tmpfs 50028 0 50028 0% /run/user/1000
[trainee@centos7 ~]$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 10229760 4274948 5954812 42% / devtmpfs 236036 0 236036 0% /dev tmpfs 250388 0 250388 0% /dev/shm tmpfs 250388 4716 245672 2% /run tmpfs 250388 0 250388 0% /sys/fs/cgroup tmpfs 250388 72 250316 1% /tmp /dev/sda1 201388 201368 20 100% /boot tmpfs 50080 0 50080 0% /run/user/1000
trainee@SLES12SP1:~> df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 18867200 3510848 15185952 19% / devtmpfs 188376 0 188376 0% /dev tmpfs 197260 0 197260 0% /dev/shm tmpfs 197260 5716 191544 3% /run tmpfs 197260 0 197260 0% /sys/fs/cgroup /dev/sda2 18867200 3510848 15185952 19% /.snapshots /dev/sda2 18867200 3510848 15185952 19% /var/lib/mariadb /dev/sda2 18867200 3510848 15185952 19% /var/lib/libvirt/images /dev/sda2 18867200 3510848 15185952 19% /var/lib/mailman /dev/sda2 18867200 3510848 15185952 19% /var/tmp /dev/sda2 18867200 3510848 15185952 19% /var/lib/pgsql /dev/sda2 18867200 3510848 15185952 19% /usr/local /dev/sda2 18867200 3510848 15185952 19% /tmp /dev/sda2 18867200 3510848 15185952 19% /var/spool /dev/sda2 18867200 3510848 15185952 19% /srv /dev/sda2 18867200 3510848 15185952 19% /var/opt /dev/sda2 18867200 3510848 15185952 19% /opt /dev/sda2 18867200 3510848 15185952 19% /var/log /dev/sda2 18867200 3510848 15185952 19% /var/lib/mysql /dev/sda2 18867200 3510848 15185952 19% /home /dev/sda2 18867200 3510848 15185952 19% /var/crash /dev/sda2 18867200 3510848 15185952 19% /var/lib/named /dev/sda2 18867200 3510848 15185952 19% /boot/grub2/x86_64-efi /dev/sda2 18867200 3510848 15185952 19% /boot/grub2/i386-pc
The units are shown as blocks. In order to humanize the output, it is possible to use the -h switch (also known as a parameter, option or flag):
trainee@debian8:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.5G 3.3G 5.8G 36% / udev 10M 0 10M 0% /dev tmpfs 99M 4.7M 95M 5% /run tmpfs 248M 0 248M 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 248M 0 248M 0% /sys/fs/cgroup tmpfs 50M 0 50M 0% /run/user/1000
trainee@ubuntu1604:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 226M 0 226M 0% /dev tmpfs 49M 2.8M 47M 6% /run /dev/sda1 9.1G 4.1G 4.5G 48% / tmpfs 245M 0 245M 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 245M 0 245M 0% /sys/fs/cgroup tmpfs 49M 0 49M 0% /run/user/1000
[trainee@centos7 ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.8G 4.1G 5.7G 42% / devtmpfs 231M 0 231M 0% /dev tmpfs 245M 0 245M 0% /dev/shm tmpfs 245M 4.7M 240M 2% /run tmpfs 245M 0 245M 0% /sys/fs/cgroup tmpfs 245M 72K 245M 1% /tmp /dev/sda1 197M 197M 20K 100% /boot tmpfs 49M 0 49M 0% /run/user/1000
trainee@SLES12SP1:~> df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 3.4G 15G 19% / devtmpfs 184M 0 184M 0% /dev tmpfs 193M 0 193M 0% /dev/shm tmpfs 193M 5.6M 188M 3% /run tmpfs 193M 0 193M 0% /sys/fs/cgroup /dev/sda2 18G 3.4G 15G 19% /.snapshots /dev/sda2 18G 3.4G 15G 19% /var/lib/mariadb /dev/sda2 18G 3.4G 15G 19% /var/lib/libvirt/images /dev/sda2 18G 3.4G 15G 19% /var/lib/mailman /dev/sda2 18G 3.4G 15G 19% /var/tmp /dev/sda2 18G 3.4G 15G 19% /var/lib/pgsql /dev/sda2 18G 3.4G 15G 19% /usr/local /dev/sda2 18G 3.4G 15G 19% /tmp /dev/sda2 18G 3.4G 15G 19% /var/spool /dev/sda2 18G 3.4G 15G 19% /srv /dev/sda2 18G 3.4G 15G 19% /var/opt /dev/sda2 18G 3.4G 15G 19% /opt /dev/sda2 18G 3.4G 15G 19% /var/log /dev/sda2 18G 3.4G 15G 19% /var/lib/mysql /dev/sda2 18G 3.4G 15G 19% /home /dev/sda2 18G 3.4G 15G 19% /var/crash /dev/sda2 18G 3.4G 15G 19% /var/lib/named /dev/sda2 18G 3.4G 15G 19% /boot/grub2/x86_64-efi /dev/sda2 18G 3.4G 15G 19% /boot/grub2/i386-pc
Command Line Switches
To do : Use the –help option of the df command to view the command line switches.
The free Command
This command's output shows the memory usage:
trainee@debian8:~$ free total used free shared buffers cached Mem: 506268 499724 6544 3048 125976 121412 -/+ buffers/cache: 252336 253932 Swap: 2046972 1756 2045216
trainee@ubuntu1604:~$ free total used free shared buff/cache available Mem: 500252 88116 8820 1460 403316 387464 Swap: 1997820 10604 1987216
[trainee@centos7 ~]$ free total used free shared buff/cache available Mem: 500780 192460 11580 3356 296740 245128 Swap: 2096124 3852 2092272
trainee@SLES12SP1:~> free total used free shared buffers cached Mem: 394524 385872 8652 5120 452 296176 -/+ buffers/cache: 89244 305280 Swap: 2103292 600 2102692
The units are shown as blocks. In order to humanize the output, it is possible to use the -h switch:
trainee@debian8:~$ free -h total used free shared buffers cached Mem: 494M 488M 6.3M 3.0M 123M 118M -/+ buffers/cache: 246M 247M Swap: 2.0G 1.7M 2.0G
trainee@ubuntu1604:~$ free -h total used free shared buff/cache available Mem: 488M 86M 8.5M 1.4M 393M 378M Swap: 1.9G 10M 1.9G
[trainee@centos7 ~]$ free -h total used free shared buff/cache available Mem: 489M 188M 11M 3.3M 289M 239M Swap: 2.0G 3.8M 2.0G
trainee@SLES12SP1:~> free -h total used free shared buffers cached Mem: 385M 376M 8.4M 5.0M 452K 289M -/+ buffers/cache: 87M 298M Swap: 2.0G 600K 2.0G
Command Line Switches
To do : Use the –help option of the free command to view the command line switches.
The whoami Command
This command's output indicates the user name associated with the current effective user ID:
trainee@debian8:~$ whoami trainee
trainee@ubuntu1604:~$ whoami trainee
[trainee@centos7 ~]$ whoami trainee
trainee@SLES12SP1:~> whoami trainee
Now become the system administrator root:
trainee@debian8:~$ su - Password: fenestros root@debian8:~#
trainee@ubuntu1604:~$ sudo su - [sudo] password for trainee: trainee root@ubuntu1604:~#
[trainee@centos7 ~]$ su - Password: fenestros Last login: Wed Sep 28 12:08:28 CEST 2016 on pts/0
trainee@SLES12SP1:~> su - Password: fenestros SLES12SP1:~ #
Important : Note that the password will not be visible.
Now use the whoami command again:
root@debian8:~# whoami root root@debian8:~#
root@ubuntu1604:~# whoami root root@ubuntu1604:~#
[root@centos7 ~]# whoami root [root@centos7 ~]#
SLES12SP1:~ # whoami root SLES12SP1:~ #
Important : Note the current effective user ID is root.
Finally execute the exit command to return as trainee:
root@debian8:~# exit logout trainee@debian8:~
root@ubuntu1604:~# exit logout trainee@ubuntu1604:~$
[root@centos7 ~]# exit logout [trainee@centos7 ~]$
SLES12SP1:~ # exit logout trainee@SLES12SP1:~>
Command Line Switches
To do : Use the –help option of the whoami command to view the command line switches.
The pwd Command
This command's output shows the current working directory:
trainee@debian8:~$ pwd /home/trainee
trainee@ubuntu1604:~$ pwd /home/trainee
[trainee@centos7 ~]$ pwd /home/trainee
trainee@SLES12SP1:~> pwd /home/trainee
Command Line Switches
To do : Use the help command with pwd option to view the command line switches.
The cd Command
This command's output changes the current working directory to that specified by the argument:
trainee@debian8:~$ cd /tmp trainee@debian8:/tmp$ pwd /tmp trainee@debian8:/tmp$
trainee@ubuntu1604:~$ cd /tmp trainee@ubuntu1604:/tmp$ pwd /tmp trainee@ubuntu1604:/tmp$
[trainee@centos7 ~]$ cd /tmp [trainee@centos7 tmp]$ pwd /tmp [trainee@centos7 tmp]$
trainee@SLES12SP1:~> cd /tmp trainee@SLES12SP1:/tmp> pwd /tmp trainee@SLES12SP1:/tmp>
Command Line Switches
To do : Use the help command with cd option to view the command line switches.
The ls Command
This commands output lists information about the files in directory specified as an argument. If no argument is specified, the output lists the files in the current working directory:
trainee@debian8:/tmp$ ls hsperfdata_root inode pulse-PKdhtXMmr18n
trainee@ubuntu1604:/tmp$ ls hsperfdata_root inode systemd-private-cd33d40e1d3a4e08a9cde3de3603311e-systemd-timesyncd.service-bxC1MJ
[trainee@centos7 tmp]$ ls hsperfdata_root inode systemd-private-45071248a58f4fd2a4de940a5734c8ec-cups.service-ODc5L6
trainee@SLES12SP1:/tmp> ls hsperfdata_root inode managera1411267841657715235client managera3336001029897679475server managera4847938942232964844client managera5050357016347721452server systemd-private-04f820fa26c745be8ddba814c6292f21-rtkit-daemon.service-o4lKP5 systemicontmp5578677472245134133dat systemicontmp7082392205020802884dat
Command Line Switches
To do : Use the –help option of the ls command to view the command line switches.
The lsof Command
This command's output shows information about open files:
trainee@debian8:/tmp$ su - Password: fenestros root@debian8:~# lsof | more COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd 1 root cwd DIR 8,1 4096 2 / systemd 1 root rtd DIR 8,1 4096 2 / systemd 1 root txt REG 8,1 1309064 26423 /lib/systemd/systemd systemd 1 root mem REG 8,1 18640 26081 /lib/x86_64-linux-gnu/libattr.so.1.1.0 systemd 1 root mem REG 8,1 14664 26064 /lib/x86_64-linux-gnu/libdl-2.19.so systemd 1 root mem REG 8,1 448440 26091 /lib/x86_64-linux-gnu/libpcre.so.3.13.1 systemd 1 root mem REG 8,1 31784 26076 /lib/x86_64-linux-gnu/librt-2.19.so systemd 1 root mem REG 8,1 92888 26135 /lib/x86_64-linux-gnu/libkmod.so.2.2.8 systemd 1 root mem REG 8,1 19016 26113 /lib/x86_64-linux-gnu/libcap.so.2.24 systemd 1 root mem REG 8,1 113024 26093 /lib/x86_64-linux-gnu/libaudit.so.1.0.0 systemd 1 root mem REG 8,1 64024 26096 /lib/x86_64-linux-gnu/libpam.so.0.83.1 systemd 1 root mem REG 8,1 142728 26137 /lib/x86_64-linux-gnu/libselinux.so.1 systemd 1 root mem REG 8,1 1738176 26061 /lib/x86_64-linux-gnu/libc-2.19.so systemd 1 root mem REG 8,1 137440 26041 /lib/x86_64-linux-gnu/libpthread-2.19.so systemd 1 root mem REG 8,1 140928 26058 /lib/x86_64-linux-gnu/ld-2.19.so systemd 1 root 0u CHR 1,3 0t0 5593 /dev/null systemd 1 root 1u CHR 1,3 0t0 5593 /dev/null systemd 1 root 2u CHR 1,3 0t0 5593 /dev/null systemd 1 root 3w CHR 1,11 0t0 5599 /dev/kmsg systemd 1 root 4u 0000 0,9 0 5589 anon_inode systemd 1 root 5u 0000 0,9 0 5589 anon_inode systemd 1 root 6r DIR 0,20 0 1 /sys/fs/cgroup/systemd --More--
trainee@ubuntu1604:/tmp$ sudo su - [sudo] password for trainee: trainee root@ubuntu1604:~# lsof | more COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd 1 root cwd DIR 8,1 4096 2 / systemd 1 root rtd DIR 8,1 4096 2 / systemd 1 root txt REG 8,1 1577232 325621 /lib/systemd/systemd systemd 1 root mem REG 8,1 18976 266610 /lib/x86_64-linux-gnu/libuuid.so.1.3.0 systemd 1 root mem REG 8,1 262408 266418 /lib/x86_64-linux-gnu/libblkid.so.1.1.0 systemd 1 root mem REG 8,1 14608 266450 /lib/x86_64-linux-gnu/libdl-2.23.so systemd 1 root mem REG 8,1 456632 266555 /lib/x86_64-linux-gnu/libpcre.so.3.13.2 systemd 1 root mem REG 8,1 1864888 266426 /lib/x86_64-linux-gnu/libc-2.23.so systemd 1 root mem REG 8,1 138744 266572 /lib/x86_64-linux-gnu/libpthread-2.23.so systemd 1 root mem REG 8,1 286824 266502 /lib/x86_64-linux-gnu/libmount.so.1.1.0 systemd 1 root mem REG 8,1 64144 266408 /lib/x86_64-linux-gnu/libapparmor.so.1.4.0 systemd 1 root mem REG 8,1 92864 266489 /lib/x86_64-linux-gnu/libkmod.so.2.3.0 systemd 1 root mem REG 8,1 117288 266416 /lib/x86_64-linux-gnu/libaudit.so.1.0.0 systemd 1 root mem REG 8,1 55904 266542 /lib/x86_64-linux-gnu/libpam.so.0.83.1 systemd 1 root mem REG 8,1 252152 266583 /lib/x86_64-linux-gnu/libseccomp.so.2.2.3 systemd 1 root mem REG 8,1 31712 266580 /lib/x86_64-linux-gnu/librt-2.23.so systemd 1 root mem REG 8,1 23128 266429 /lib/x86_64-linux-gnu/libcap.so.2.24 systemd 1 root mem REG 8,1 130224 266584 /lib/x86_64-linux-gnu/libselinux.so.1 systemd 1 root mem REG 8,1 162632 266398 /lib/x86_64-linux-gnu/ld-2.23.so systemd 1 root 0u CHR 1,3 0t0 6 /dev/null systemd 1 root 1u CHR 1,3 0t0 6 /dev/null systemd 1 root 2u CHR 1,3 0t0 6 /dev/null --More--
[trainee@centos7 tmp]$ su - Password: fenestros Last login: Thu Sep 29 06:24:28 CEST 2016 on pts/0 [root@centos7 ~]# lsof | more COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd 1 root cwd DIR 8,2 4096 128 / systemd 1 root rtd DIR 8,2 4096 128 / systemd 1 root txt REG 8,2 1494056 33607555 /usr/lib/systemd/systemd systemd 1 root mem REG 8,2 20032 17241167 /usr/lib64/libuuid.so.1.3.0 systemd 1 root mem REG 8,2 252696 20114965 /usr/lib64/libblkid.so.1.1.0 systemd 1 root mem REG 8,2 90632 18751025 /usr/lib64/libz.so.1.2.7 systemd 1 root mem REG 8,2 19888 17326380 /usr/lib64/libattr.so.1.1.0 systemd 1 root mem REG 8,2 19520 17239651 /usr/lib64/libdl-2.17.so systemd 1 root mem REG 8,2 153192 18023397 /usr/lib64/liblzma.so.5.0.99 systemd 1 root mem REG 8,2 398272 18105157 /usr/lib64/libpcre.so.1.2.0 systemd 1 root mem REG 8,2 2107816 17239525 /usr/lib64/libc-2.17.so systemd 1 root mem REG 8,2 142304 17240882 /usr/lib64/libpthread-2.17.so systemd 1 root mem REG 8,2 88720 17511831 /usr/lib64/libgcc_s-4.8.5-20150702.so.1 systemd 1 root mem REG 8,2 44096 17241011 /usr/lib64/librt-2.17.so systemd 1 root mem REG 8,2 260784 20114966 /usr/lib64/libmount.so.1.1.0 systemd 1 root mem REG 8,2 91768 18023376 /usr/lib64/libkmod.so.2.2.10 systemd 1 root mem REG 8,2 118792 17326381 /usr/lib64/libaudit.so.1.0.0 systemd 1 root mem REG 8,2 61648 18105139 /usr/lib64/libpam.so.0.83.1 systemd 1 root mem REG 8,2 20024 17326423 /usr/lib64/libcap.so.2.22 systemd 1 root mem REG 8,2 147120 18447456 /usr/lib64/libselinux.so.1 systemd 1 root mem REG 8,2 164440 21744303 /usr/lib64/ld-2.17.so systemd 1 root mem REG 8,2 1333123 50334524 /etc/selinux/targeted/contexts/files/file_contexts.bin --More--
trainee@SLES12SP1:/tmp> su - Password: SLES12SP1:~ # lsof | more COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd 1 root cwd DIR 0,34 156 256 / systemd 1 root rtd DIR 0,34 156 256 / systemd 1 root txt REG 0,34 1218976 74832 /usr/lib/systemd/systemd systemd 1 root mem REG 0,34 18904 23416 /lib64/libdl-2.19.so systemd 1 root mem REG 0,34 416064 24152 /usr/lib64/libpcre.so.1.2.1 systemd 1 root mem REG 0,34 1974416 23410 /lib64/libc-2.19.so systemd 1 root mem REG 0,34 137440 23438 /lib64/libpthread-2.19.so systemd 1 root mem REG 0,34 42672 23442 /lib64/librt-2.19.so systemd 1 root mem REG 0,34 150128 24032 /usr/lib64/libseccomp.so.2.1.0 systemd 1 root mem REG 0,34 43960 25095 /lib64/libapparmor.so.1.0.4 systemd 1 root mem REG 0,34 84864 24581 /usr/lib64/libkmod.so.2.2.7 systemd 1 root mem REG 0,34 18976 24919 /lib64/libcap.so.2.22 systemd 1 root mem REG 0,34 100312 24963 /usr/lib64/libaudit.so.1.0.0 systemd 1 root mem REG 0,34 60096 59333 /lib64/libpam.so.0.83.1 systemd 1 root mem REG 0,34 40880 23873 /lib64/libwrap.so.0.7.6 systemd 1 root mem REG 0,34 138792 25858 /lib64/libselinux.so.1 systemd 1 root mem REG 0,34 158192 23402 /lib64/ld-2.19.so systemd 1 root 0u CHR 1,3 0t0 4298 /dev/null systemd 1 root 1u CHR 1,3 0t0 4298 /dev/null systemd 1 root 2u CHR 1,3 0t0 4298 /dev/null systemd 1 root 3r 0000 0,10 0 4268 anon_inode systemd 1 root 4u 0000 0,10 0 4268 anon_inode --More--
Command Line Switches
To do : Use the –help option of the lsof command to view the command line switches.
The touch Command
This command updates the access and modification times of one or several file(s) to the current time. If the file does not exist, the system creates an empty file:
root@debian8:~# exit logout trainee@debian8:/tmp$ touch test trainee@debian8:/tmp$ ls hsperfdata_root inode pulse-PKdhtXMmr18n test
root@ubuntu1604:~# exit logout trainee@ubuntu1604:/tmp$ touch test trainee@ubuntu1604:/tmp$ ls hsperfdata_root inode systemd-private-cd33d40e1d3a4e08a9cde3de3603311e-systemd-timesyncd.service-bxC1MJ test
[root@centos7 ~]# exit logout [trainee@centos7 tmp]$ touch test [trainee@centos7 tmp]$ ls hsperfdata_root systemd-private-45071248a58f4fd2a4de940a5734c8ec-cups.service-ODc5L6 inode test
SLES12SP1:~ # exit logout trainee@SLES12SP1:/tmp> touch test trainee@SLES12SP1:/tmp> ls hsperfdata_root inode managera1411267841657715235client managera3336001029897679475server managera4847938942232964844client managera5050357016347721452server systemd-private-04f820fa26c745be8ddba814c6292f21-rtkit-daemon.service-o4lKP5 systemicontmp5578677472245134133dat systemicontmp7082392205020802884dat test
Command Line Switches
To do : Use the –help option of the touch command to view the command line switches.
The echo Command
This command writes the arguments to the standard output (i.e. the screen):
trainee@debian8:/tmp$ echo fenestros fenestros
trainee@ubuntu1604:/tmp$ echo fenestros fenestros
[trainee@centos7 tmp]$ echo fenestros fenestros
trainee@SLES12SP1:/tmp> echo fenestros fenestros
Command Line Switches
To do : Use the help command with echo option to view the command line switches.
The cp Command
This command is used to copy a source to a destination or multiple sources to a directory:
trainee@debian8:/tmp$ cp test ~ trainee@debian8:/tmp$ ls -l ~ total 36 drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Desktop drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Documents drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Downloads drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Music drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Pictures drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Public drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Templates -rw-r--r-- 1 trainee trainee 0 Aug 19 16:14 test drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Videos -rw-r--r-- 1 trainee trainee 391 Aug 18 23:34 vitext
trainee@ubuntu1604:/tmp$ cp test ~ trainee@ubuntu1604:/tmp$ ls -l ~ total 48 drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Desktop drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Documents drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Downloads -rw-r--r-- 1 trainee trainee 8980 mai 3 07:27 examples.desktop drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Music drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Pictures drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Public drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Templates -rw-rw-r-- 1 trainee trainee 0 oct. 4 13:31 test drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Videos -rw-rw-r-- 1 trainee trainee 442 sept. 30 11:35 vitext
[trainee@centos7 tmp]$ cp test ~ [trainee@centos7 tmp]$ ls -l ~ total 4 drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Desktop drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Documents drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Downloads drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Music drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Pictures drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Public drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Templates -rw-rw-r--. 1 trainee trainee 0 Sep 29 17:23 test drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Videos -rw-rw-r--. 1 trainee trainee 442 Sep 29 00:53 vitext
trainee@SLES12SP1:/tmp> cp test ~ trainee@SLES12SP1:/tmp> ls -l ~ total 4 drwxr-xr-x 1 trainee users 0 May 1 15:58 bin drwxr-xr-x 1 trainee users 0 May 2 16:11 Desktop drwxr-xr-x 1 trainee users 0 May 2 16:11 Documents drwxr-xr-x 1 trainee users 0 May 2 16:11 Downloads drwxr-xr-x 1 trainee users 0 May 2 16:11 Music drwxr-xr-x 1 trainee users 0 May 2 16:11 Pictures drwxr-xr-x 1 trainee users 0 May 2 16:11 Public drwxr-xr-x 1 trainee users 20 May 1 15:58 public_html drwxr-xr-x 1 trainee users 0 May 2 16:11 Templates -rw-r--r-- 1 trainee users 0 Oct 1 06:01 test drwxr-xr-x 1 trainee users 0 May 2 16:11 Videos -rw-r--r-- 1 trainee users 391 Sep 30 10:27 vitext
Note the use of the ~ (tilde) character which is a shortcut to the current user's home directory. In the case of this example : /home/trainee.
Command Line Switches
To do : Use the –help option of the cp command to view the command line switches.
The file Command
This command determines a file type:
trainee@debian8:/tmp$ file ~/test /home/trainee/test: empty
trainee@ubuntu1604:/tmp$ file ~/test /home/trainee/test: empty
[trainee@centos7 tmp]$ file ~/test /home/trainee/test: empty
trainee@SLES12SP1:/tmp> file ~/test /home/trainee/test: empty
Important - Note that in the case of the first line of the above output, tha command file is incapable of informing you of the type of file since test is empty.
Using the > key, redirect the output of echo fenestros into the /home/trainee/test file as follows:
trainee@debian8:/tmp$ echo "fenestros" > ~/test
trainee@ubuntu1604:/tmp$ echo "fenestros" > ~/test
[trainee@centos7 tmp]$ echo "fenestros" > ~/test
trainee@SLES12SP1:/tmp> echo "fenestros" > ~/test
Now use the file command once again to determine the file type:
trainee@debian8:/tmp$ file ~/test /home/trainee/test: ASCII text
trainee@ubuntu1604:/tmp$ file ~/test /home/trainee/test: ASCII text
[trainee@centos7 tmp]$ file ~/test /home/trainee/test: ASCII text
trainee@SLES12SP1:/tmp> file ~/test /home/trainee/test: ASCII text
Command Line Switches
To do : Use the –help option of the file command to view the command line switches.
The cat Command
This commands concatenate files, or standard input, to standard output. In the case of only one file as an argument, the effective result is to print the file contents to the screen:
trainee@debian8:/tmp$ cat ~/test fenestros
trainee@ubuntu1604:/tmp$ cat ~/test fenestros
[trainee@centos7 tmp]$ cat ~/test fenestros
trainee@SLES12SP1:/tmp> cat ~/test fenestros
Command Line Switches
To do : Use the –help option of the cat command to view the command line switches.
The mv Command
This command renames a source to a destination or moves sources to a directory:
trainee@debian8:/tmp$ mv ~/test . trainee@debian8:/tmp$ ls -l ~ total 36 drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Desktop drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Documents drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Downloads drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Music drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Pictures drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Public drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Templates drwxr-xr-x 2 trainee trainee 4096 May 1 20:42 Videos -rw-r--r-- 1 trainee trainee 391 Aug 18 23:34 vitext trainee@debian8:/tmp$ mv test TeSt trainee@debian8:/tmp$ ls -l total 16 drwxr-xr-x 2 root root 4096 Aug 18 11:33 hsperfdata_root drwxr-xr-x 2 root root 4096 Aug 18 13:36 inode drwx------ 2 root root 4096 Aug 18 11:29 pulse-PKdhtXMmr18n -rw-r--r-- 1 trainee trainee 10 Aug 19 16:20 TeSt
trainee@ubuntu1604:/tmp$ mv ~/test . trainee@ubuntu1604:/tmp$ ls -l ~ total 48 drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Desktop drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Documents drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Downloads -rw-r--r-- 1 trainee trainee 8980 mai 3 07:27 examples.desktop drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Music drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Pictures drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Public drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Templates drwxr-xr-x 2 trainee trainee 4096 mai 3 08:03 Videos -rw-rw-r-- 1 trainee trainee 442 sept. 30 11:35 vitext trainee@ubuntu1604:/tmp$ mv test TeSt trainee@ubuntu1604:/tmp$ ls -l total 16 drwxr-xr-x 2 root root 4096 sept. 28 10:34 hsperfdata_root drwxr-xr-x 2 root root 4096 sept. 29 10:32 inode drwx------ 3 root root 4096 sept. 29 10:19 systemd-private-cd33d40e1d3a4e08a9cde3de3603311e-systemd-timesyncd.service-bxC1MJ -rw-rw-r-- 1 trainee trainee 10 oct. 4 13:36 TeSt
[trainee@centos7 tmp]$ mv ~/test . [trainee@centos7 tmp]$ ls -l ~ total 4 drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Desktop drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Documents drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Downloads drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Music drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Pictures drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Public drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Templates drwxr-xr-x. 2 trainee trainee 6 Apr 30 11:54 Videos -rw-rw-r--. 1 trainee trainee 442 Sep 29 00:53 vitext [trainee@centos7 tmp]$ mv test TeSt [trainee@centos7 tmp]$ ls -l total 4 drwxr-xr-x. 2 root root 80 Sep 28 10:52 hsperfdata_root drwxr-xr-x. 2 root root 100 Sep 28 12:30 inode drwx------. 3 root root 60 Sep 28 10:49 systemd-private-45071248a58f4fd2a4de940a5734c8ec-cups.service-ODc5L6 -rw-rw-r--. 1 trainee trainee 10 Sep 29 17:28 TeSt
trainee@SLES12SP1:/tmp> mv test TeSt trainee@SLES12SP1:/tmp> ls -l total 12 drwxr-xr-x 1 root root 8 Sep 30 10:26 hsperfdata_root drwxr-xr-x 1 trainee users 48 Aug 18 13:14 inode -rwxrwxrwx 1 root root 50048 May 3 14:01 managera1411267841657715235client -rwxrwxrwx 1 root root 50048 May 3 14:01 managera3336001029897679475server -rwxrwxrwx 1 root root 50048 May 3 14:01 managera4847938942232964844client -rwxrwxrwx 1 root root 50048 May 3 14:01 managera5050357016347721452server drwx------ 1 root root 6 May 3 13:54 systemd-private-04f820fa26c745be8ddba814c6292f21-rtkit-daemon.service-o4lKP5 -rw-r--r-- 1 root root 0 May 3 14:01 systemicontmp5578677472245134133dat drwxr-xr-x 1 root root 0 May 3 14:01 systemicontmp7082392205020802884dat -rw-r--r-- 1 trainee users 10 Oct 1 06:06 TeSt
Note the use of the shortcut . which indicates the current working directory.
Command Line Switches
To do : Use the –help option of the mv command to view the command line switches.
The mkdir Command
This command creates the directory(ies) if it (they) does (do) not exist:
trainee@debian8:/tmp$ cd ~ trainee@debian8:~$ mkdir testdir trainee@debian8:~$ ls Desktop Documents Downloads Music Pictures Public Templates testdir Videos vitext
trainee@ubuntu1604:/tmp$ cd ~ trainee@ubuntu1604:~$ mkdir testdir trainee@ubuntu1604:~$ ls Desktop Downloads Music Public testdir vitext Documents examples.desktop Pictures Templates Videos
[trainee@centos7 tmp]$ cd ~ [trainee@centos7 ~]$ mkdir testdir [trainee@centos7 ~]$ ls Desktop Documents Downloads Music Pictures Public Templates testdir Videos vitext
trainee@SLES12SP1:/tmp> cd ~ trainee@SLES12SP1:~> mkdir testdir trainee@SLES12SP1:~> ls bin Documents Music Public Templates Videos Desktop Downloads Pictures public_html testdir vitext
Command Line Switches
To do : Use the –help option of the mkdir command to view the command line switches.
The rmdir Command
This command removes the directory(ies) if it (they) is (are) empty:
trainee@debian8:~$ rmdir testdir trainee@debian8:~$ ls Desktop Documents Downloads Music Pictures Public Templates Videos vitext
trainee@ubuntu1604:~$ rmdir testdir trainee@ubuntu1604:~$ ls Desktop Downloads Music Public Videos Documents examples.desktop Pictures Templates vitext
[trainee@centos7 ~]$ rmdir testdir [trainee@centos7 ~]$ ls Desktop Documents Downloads Music Pictures Public Templates Videos vitext
trainee@SLES12SP1:~> rmdir testdir trainee@SLES12SP1:~> ls bin Documents Music Public Templates vitext Desktop Downloads Pictures public_html Videos
Command Line Switches
To do : Use the –help option of the rmdir command to view the command line switches.
The rm Command
This command removes a directory, empty of not, as well as files:
trainee@debian8:~$ mkdir testdir1 trainee@debian8:~$ cd /tmp trainee@debian8:/tmp$ echo "fenestros" > TeSt trainee@debian8:/tmp$ cd ~ trainee@debian8:~$ mv /tmp/TeSt ~/testdir1 trainee@debian8:~$ ls -lR testdir1/ testdir1/: total 4 -rw-r--r-- 1 trainee trainee 10 Aug 19 17:01 TeSt trainee@debian8:~$ rmdir testdir1/ rmdir: failed to remove ‘testdir1/’: Directory not empty trainee@debian8:~$ rm -rf testdir1/ trainee@debian8:~$ ls Desktop Documents Downloads Music Pictures Public Templates Videos vitext
trainee@ubuntu1604:~$ mkdir testdir1 trainee@ubuntu1604:~$ cd /tmp trainee@ubuntu1604:/tmp$ echo "fenestros" > TeSt trainee@ubuntu1604:/tmp$ cd ~ trainee@ubuntu1604:~$ mv /tmp/TeSt ~/testdir1 trainee@ubuntu1604:~$ ls -lR testdir1/ testdir1/: total 4 -rw-rw-r-- 1 trainee trainee 10 oct. 4 14:17 TeSt trainee@ubuntu1604:~$ rmdir testdir1/ rmdir: failed to remove 'testdir1/': Directory not empty trainee@ubuntu1604:~$ rm -rf testdir1/ trainee@ubuntu1604:~$ ls Desktop Downloads Music Public Videos Documents examples.desktop Pictures Templates vitext
[trainee@centos7 ~]$ mkdir testdir1 [trainee@centos7 ~]$ cd /tmp [trainee@centos7 tmp]$ echo "fenestros" > TeSt [trainee@centos7 tmp]$ cd ~ [trainee@centos7 ~]$ mv /tmp/TeSt ~/testdir1 [trainee@centos7 ~]$ ls -lR testdir1/ testdir1/: total 4 -rw-rw-r--. 1 trainee trainee 10 Sep 29 18:13 TeSt [trainee@centos7 ~]$ rmdir testdir1/ rmdir: failed to remove ‘testdir1/’: Directory not empty [trainee@centos7 ~]$ rm -rf testdir1/ [trainee@centos7 ~]$ ls Desktop Documents Downloads Music Pictures Public Templates Videos vitext
trainee@SLES12SP1:~> mkdir testdir1 trainee@SLES12SP1:~> cd /tmp trainee@SLES12SP1:/tmp> echo "fenestros" > TeSt trainee@SLES12SP1:/tmp> cd ~ trainee@SLES12SP1:~> mv /tmp/TeSt ~/testdir1 trainee@SLES12SP1:~> ls -lR testdir1/ testdir1/: total 4 -rw-r--r-- 1 trainee users 10 Oct 1 06:47 TeSt trainee@SLES12SP1:~> rmdir testdir1/ rmdir: failed to remove ‘testdir1/’: Directory not empty trainee@SLES12SP1:~> rm -rf testdir1/ trainee@SLES12SP1:~> ls bin Documents Music Public Templates vitext Desktop Downloads Pictures public_html Videos
Command Line Switches
To do : Use the –help option of the rm command to view the command line switches.
The sort Command
This command writes a sorted concatenation of all files to standard output:
trainee@debian8:~$ touch aac abc bca xyz trainee@debian8:~$ ls aac bca Documents Music Public Videos xyz abc Desktop Downloads Pictures Templates vitext trainee@debian8:~$ ls | sort aac abc bca Desktop Documents Downloads Music Pictures Public Templates Videos vitext xyz trainee@debian8:~$ ls | sort -r xyz vitext Videos Templates Public Pictures Music Downloads Documents Desktop bca abc aac
trainee@ubuntu1604:~$ touch aac abc bca xyz trainee@ubuntu1604:~$ ls aac bca Documents examples.desktop Pictures Templates vitext abc Desktop Downloads Music Public Videos xyz trainee@ubuntu1604:~$ ls | sort aac abc bca Desktop Documents Downloads examples.desktop Music Pictures Public Templates Videos vitext xyz trainee@ubuntu1604:~$ ls | sort -r xyz vitext Videos Templates Public Pictures Music examples.desktop Downloads Documents Desktop bca abc aac
[trainee@centos7 ~]$ touch aac abc bca xyz [trainee@centos7 ~]$ ls aac bca Documents Music Public Videos xyz abc Desktop Downloads Pictures Templates vitext [trainee@centos7 ~]$ ls | sort aac abc bca Desktop Documents Downloads Music Pictures Public Templates Videos vitext xyz [trainee@centos7 ~]$ ls | sort -r xyz vitext Videos Templates Public Pictures Music Downloads Documents Desktop bca abc aac
trainee@SLES12SP1:~> ls | sort aac abc bca bin Desktop Documents Downloads Music Pictures Public public_html Templates Videos vitext xyz trainee@SLES12SP1:~> ls | sort -r xyz vitext Videos Templates public_html Public Pictures Music Downloads Documents Desktop bin bca abc aac
Important - Note the use of the | character, called a pipe. A pipe is used to channel the standard output of the command that precedes it into the standard input of the command that follows it.
Command Line Switches
To do : Use the –help option of the sort command to view the command line switches.
The more Command
This command is used to display a long file page by page:
trainee@debian8:~$ more /etc/services # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, officially ports have two entries # even if the protocol doesn't support UDP operations. # # Updated from http://www.iana.org/assignments/port-numbers and other # sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services . # New ports will be added on request if they have been officially assigned # by IANA and used in the real-world or are needed by a debian package. # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol --More--(4%)
trainee@ubuntu1604:~$ more /etc/services # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, officially ports have two entries # even if the protocol doesn't support UDP operations. # # Updated from http://www.iana.org/assignments/port-numbers and other # sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services . # New ports will be added on request if they have been officially assigned # by IANA and used in the real-world or are needed by a debian package. # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol --More--(4%)
[trainee@centos7 ~]$ more /etc/services # /etc/services: # $Id: services,v 1.55 2013/04/14 ovasik Exp $ # # Network services, Internet style # IANA services version: last updated 2013-04-10 # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports # are included, only the more common ones. # # The latest IANA port assignments can be gotten from # http://www.iana.org/assignments/port-numbers # The Well Known Ports are those from 0 through 1023. # The Registered Ports are those from 1024 through 49151 # The Dynamic and/or Private Ports are those from 49152 through 65535 # # Each line describes one service, and is of the form: # # service-name port/protocol [aliases ...] [# comment] tcpmux 1/tcp # TCP port service multiplexer --More--(0%)
trainee@SLES12SP1:~> more /etc/services # # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # # This list could be found on: # http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbe rs.xml # # See also: services(5) # # # SERVICE NAME AND TRANSPORT PROTOCOL PORT NUMBER REGISTRY # # (last updated on 2011-11-23) # # ************************************************************************ # * Since we merged and converted this registry it loads more slowly. We * # * know it should load faster and are working on ways to achieve that. * # * Thank you for your patience. * # ************************************************************************ # --More--(0%)
Important - The ↵ Enter key scrolls down line by line, the Space Bar key scrolls down page by page and the Q key comes back to the command line prompt.
Command Line Switches
To do : Use the –help option of the more command to view the command line switches.
The less Command
The less command produces a similar result to that of the more command. Practice using the less command and refer to the help using less –help. Which command seems the most powerful and versatile ?
trainee@debian8:~$ less /etc/services # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, officially ports have two entries # even if the protocol doesn't support UDP operations. # # Updated from http://www.iana.org/assignments/port-numbers and other # sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services . # New ports will be added on request if they have been officially assigned # by IANA and used in the real-world or are needed by a debian package. # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol /etc/services
trainee@ubuntu1604:~$ less /etc/services # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, officially ports have two entries # even if the protocol doesn't support UDP operations. # # Updated from http://www.iana.org/assignments/port-numbers and other # sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services . # New ports will be added on request if they have been officially assigned # by IANA and used in the real-world or are needed by a debian package. # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol /etc/services
[trainee@centos7 ~]$ less /etc/services # /etc/services: # $Id: services,v 1.55 2013/04/14 ovasik Exp $ # # Network services, Internet style # IANA services version: last updated 2013-04-10 # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports # are included, only the more common ones. # # The latest IANA port assignments can be gotten from # http://www.iana.org/assignments/port-numbers # The Well Known Ports are those from 0 through 1023. # The Registered Ports are those from 1024 through 49151 # The Dynamic and/or Private Ports are those from 49152 through 65535 # # Each line describes one service, and is of the form: # # service-name port/protocol [aliases ...] [# comment] tcpmux 1/tcp # TCP port service multiplexer /etc/services
trainee@SLES12SP1:~> less /etc/services # # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # # This list could be found on: # http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml # # See also: services(5) # # # SERVICE NAME AND TRANSPORT PROTOCOL PORT NUMBER REGISTRY # # (last updated on 2011-11-23) # # ************************************************************************ # * Since we merged and converted this registry it loads more slowly. We * # * know it should load faster and are working on ways to achieve that. * # * Thank you for your patience. * # ************************************************************************ /etc/services lines 1-22/16228 0%
Command Line Switches
To do : Use the –help option of the less command to view the command line switches.
The find Command
This command is used to search for a specific file or directory. The default path is the current directory and default expression is -print:
trainee@debian8:~$ find acc find: `acc': No such file or directory trainee@debian8:~$ find aac aac
trainee@ubuntu1604:~$ find acc find: ‘acc’: No such file or directory trainee@ubuntu1604:~$ find aac aac
[trainee@centos7 ~]$ find acc find: ‘acc’: No such file or directory [trainee@centos7 ~]$ find aac aac
trainee@SLES12SP1:~> find acc find: ‘acc’: No such file or directory trainee@SLES12SP1:~> find aac aac
Important : Note that when the file cannot be found, the find command informs you clearly. However when the file is found, the find command just prints the name of the file to standard output.
Command Line Switches
To do : Use the –help option of the find command to view the command line switches.
The su Command
This command is used to change the effective user id and group id to that of the user passed as an argument. When executed with no argument, the system assumes the destination user is root:
trainee@debian8:~$ su - Password: fenestros
trainee@ubuntu1604:~$ sudo su - [sudo] password for trainee: trainee
[trainee@centos7 ~]$ su - Password: fenestros Last login: Thu Sep 29 17:08:56 CEST 2016 on pts/0
trainee@SLES12SP1:~> su - Password: fenestros
Important : Note that the password will not be visible.
Command Line Switches
To do : Use the –help option of the su command to view the command line switches.
The updatedb and locate Commands
The locate command is used to list files in databases that match a pattern supplied as an argument to the command. The locate command uses a database. This database needs to be created using the updatedb command before using the locate command.
The default database is /var/lib/mlocate/mlocate.db:
root@debian8:~# ls -l /var/lib/mlocate/mlocate.db -rw-r----- 1 root mlocate 2067895 Aug 19 07:35 /var/lib/mlocate/mlocate.db
root@ubuntu1604:~# ls -l /var/lib/mlocate/mlocate.db -rw-r----- 1 root mlocate 5293946 oct. 2 07:35 /var/lib/mlocate/mlocate.db
[root@centos7 ~]# ls -l /var/lib/mlocate/mlocate.db -rw-r-----. 1 root slocate 3887117 Sep 29 03:46 /var/lib/mlocate/mlocate.db
SLES12SP1:~ # ls -l /var/lib/mlocate/mlocate.db -rw-r--r-- 1 root root 3804323 Sep 30 10:30 /var/lib/mlocate/mlocate.db
Important : For information concerning the database format, please see man 5 locatedb.
The updatedb command is configured by editing the /etc/updatedb.conf file:
root@debian8:~# cat /etc/updatedb.conf PRUNE_BIND_MOUNTS="yes" # PRUNENAMES=".git .bzr .hg .svn" PRUNEPATHS="/tmp /var/spool /media" PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre tmpfs usbfs udf fuse.glusterfs fuse.sshfs curlftpfs"
root@ubuntu1604:~# cat /etc/updatedb.conf PRUNE_BIND_MOUNTS="yes" # PRUNENAMES=".git .bzr .hg .svn" PRUNEPATHS="/tmp /var/spool /media /home/.ecryptfs /var/lib/schroot" PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre tmpfs usbfs udf fuse.glusterfs fuse.sshfs curlftpfs ecryptfs fusesmb devtmpfs"
[root@centos7 ~]# cat /etc/updatedb.conf PRUNE_BIND_MOUNTS = "yes" PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fuse.sshfs fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs" PRUNENAMES = ".git .hg .svn" PRUNEPATHS = "/afs /media /mnt /net /sfs /tmp /udev /var/cache/ccache /var/lib/yum/yumdb /var/spool/cups /var/spool/squid /var/tmp"
SLES12SP1:~ # cat /etc/updatedb.conf # /etc/updatedb.conf: config file for mlocate # This file sets variables that are used by updatedb. # For more info, see the updatedb.conf(5) manpage. # Filesystems that are pruned from updatedb database PRUNEFS="afs anon_inodefs auto autofs bdev binfmt binfmt_misc cgroup cifs coda configfs cramfs cpuset debugfs devfs devpts devtmps ecryptfs eventpollfs exofs futexfs ftpfs fuse fusectl gfs gfs2 hostfs hugetlbfs inotifyfs iso9660 jffs2 lustre misc mqueue ncpfs nfs NFS nfs4 nfsd nnpfs ocfs ocfs2 pipefs proc ramfs rpc_pipefs securityfs selinuxfs sfs shfs smbfs sockfs spufs sshfs subfs supermount sysfs tmpfs ubifs udf usbfs vboxsf vperfctrfs" # Paths which are pruned from updatedb database PRUNEPATHS="/tmp /var/tmp /var/cache /var/lock /var/run /var/spool /mnt /cdrom /usr/tmp /proc /media /sys /.snapshots /var/run/media" # Folder names that are pruned from updatedb database PRUNENAMES=".git .hg .svn CVS" # Skip bind mounts. PRUNE_BIND_MOUNTS="yes"
Use of these two commands is very simple:
root@debian8:~# updatedb root@debian8:~# locate aac /home/trainee/aac /lib/modules/3.16.0-4-amd64/kernel/drivers/scsi/aacraid /lib/modules/3.16.0-4-amd64/kernel/drivers/scsi/aacraid/aacraid.ko /usr/lib/x86_64-linux-gnu/libaacs.so.0 /usr/lib/x86_64-linux-gnu/libaacs.so.0.4.1 /usr/share/doc/libaacs0 /usr/share/doc/libaacs0/KEYDB.cfg.gz /usr/share/doc/libaacs0/changelog.Debian.amd64.gz /usr/share/doc/libaacs0/changelog.Debian.gz /usr/share/doc/libaacs0/changelog.gz /usr/share/doc/libaacs0/copyright /usr/share/mime/audio/aac.xml /var/cache/apt/archives/libaacs0_0.7.1-1+b1_amd64.deb /var/lib/dpkg/info/libaacs0:amd64.list /var/lib/dpkg/info/libaacs0:amd64.md5sums /var/lib/dpkg/info/libaacs0:amd64.postinst /var/lib/dpkg/info/libaacs0:amd64.postrm /var/lib/dpkg/info/libaacs0:amd64.shlibs
root@ubuntu1604:~# updatedb root@ubuntu1604:~# locate aac /home/trainee/aac /lib/modules/4.4.0-21-generic/kernel/drivers/scsi/aacraid /lib/modules/4.4.0-21-generic/kernel/drivers/scsi/aacraid/aacraid.ko /lib/modules/4.4.0-38-generic/kernel/drivers/scsi/aacraid /lib/modules/4.4.0-38-generic/kernel/drivers/scsi/aacraid/aacraid.ko /usr/share/app-install/desktop/krita-data:kde4__calligraactive.desktop /usr/share/mime/audio/aac.xml /usr/src/linux-headers-4.4.0-21/drivers/scsi/aacraid /usr/src/linux-headers-4.4.0-21/drivers/scsi/aacraid/Makefile /usr/src/linux-headers-4.4.0-21-generic/include/config/scsi/aacraid.h /usr/src/linux-headers-4.4.0-38/drivers/scsi/aacraid /usr/src/linux-headers-4.4.0-38/drivers/scsi/aacraid/Makefile /usr/src/linux-headers-4.4.0-38-generic/include/config/scsi/aacraid.h
[root@centos7 ~]# updatedb [root@centos7 ~]# locate aac /home/trainee/aac /usr/lib/modules/3.10.0-327.13.1.el7.x86_64/kernel/drivers/scsi/aacraid /usr/lib/modules/3.10.0-327.13.1.el7.x86_64/kernel/drivers/scsi/aacraid/aacraid.ko /usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/scsi/aacraid /usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/scsi/aacraid/aacraid.ko /usr/lib/python2.7/site-packages/ipalib/plugins/caacl.py /usr/lib/python2.7/site-packages/ipalib/plugins/caacl.pyc /usr/lib/python2.7/site-packages/ipalib/plugins/caacl.pyo /usr/share/gtk-doc/html/gst-plugins-good-plugins-1.0/gst-plugins-good-plugins-aacparse.html /usr/share/gupnp-dlna-2.0/dlna-profiles/aac.xml /usr/share/mime/audio/aac.xml /usr/src/kernels/3.10.0-327.13.1.el7.x86_64/drivers/scsi/aacraid /usr/src/kernels/3.10.0-327.13.1.el7.x86_64/drivers/scsi/aacraid/Makefile /usr/src/kernels/3.10.0-327.13.1.el7.x86_64/include/config/scsi/aacraid.h /usr/src/kernels/3.10.0-327.el7.x86_64/drivers/scsi/aacraid /usr/src/kernels/3.10.0-327.el7.x86_64/drivers/scsi/aacraid/Makefile /usr/src/kernels/3.10.0-327.el7.x86_64/include/config/scsi/aacraid.h
SLES12SP1:~ # locate aac /lib/modules/3.12.49-11-default/kernel/drivers/scsi/aacraid /lib/modules/3.12.49-11-default/kernel/drivers/scsi/aacraid/aacraid.ko /usr/share/YaST2/scrconf/aaconf.scr /usr/share/mime/audio/aac.xml
Command Line Switches
To do : Use the –help option of the updatedb and locate commands to view their command line switches.
The whereis Command
This command is used to show the full paths of the executable, the configuration files and the manuals associated with the argument:
root@debian8:~# whereis passwd passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1ssl.gz /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
root@ubuntu1604:~# whereis passwd passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz /usr/share/man/man1/passwd.1ssl.gz
[root@centos7 ~]# whereis passwd passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
SLES12SP1:~ # whereis passwd passwd: /usr/bin/passwd /etc/passwd /etc/passwd.YaST2save /usr/share/man/man1/passwd.1ssl.gz /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
Command Line Switches
To do : Use the –help option of the whereis command to view the command line switches.
The which Command
This command searches the PATH variable and returns to standard output the first full path associated with the argument:
root@debian8:~# which passwd /usr/bin/passwd
root@ubuntu1604:~# which passwd /usr/bin/passwd
[root@centos7 ~]# which passwd /bin/passwd
SLES12SP1:~ # which passwd /usr/bin/passwd
Command Line Switches
To do : Use the –help option of the which command to view the command line switches.
The uptime Command
This command prints to standard output the current time, the length of time the system has been up, the number of users on the system and the average number of jobs in the run queue over the last 1, 5 and 15 minutes:
root@debian8:~# uptime 18:02:14 up 1 day, 6:33, 1 user, load average: 0.00, 0.01, 0.05
root@ubuntu1604:~# uptime 15:18:02 up 1 day, 13:10, 1 user, load average: 0,00, 0,03, 0,0
[root@centos7 ~]# uptime 19:18:57 up 1 day, 8:30, 1 user, load average: 0.10, 0.09, 0.07
SLES12SP1:~ # uptime 07:48am up 21:25, 1 user, load average: 0.10, 0.05, 0.05
Command Line Switches
The switches associated with this command are:
To do : Use the –help option of the uptime command to view the command line switches.
The w Command
This command outputs the same data as the uptime command on the first line and then complements this information with the details of each user connected to the system, including what each user is currently doing. This is the replacement under Linux for the Unix command whodo:
root@debian8:~# w 18:11:31 up 1 day, 6:42, 1 user, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT trainee pts/0 10.0.2.2 14:16 0.00s 0.13s 0.03s sshd: trainee [priv]
root@ubuntu1604:~# w 15:27:17 up 1 day, 13:19, 1 user, load average: 0,10, 0,06, 0,06 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT trainee pts/0 10.0.2.2 lun.17 0.00s 0.11s 0.00s sshd: trainee [priv]
[root@centos7 ~]# w 19:28:55 up 1 day, 8:40, 1 user, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT trainee pts/0 gateway 15:22 7.00s 0.16s 0.12s sshd: trainee [priv]
SLES12SP1:~ # w 07:57:55 up 21:34, 1 user, load average: 0.00, 0.03, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT trainee pts/0 10.0.2.2 04:09 0.00s 0.12s 0.00s sshd: trainee [priv]
The JCPU time is the time used by all processes attached to the tty. It does not include past background jobs, but does include currently running background jobs.
The PCPU time is the time used by the current process, named in the what field.
Command Line Switches
To do : Use the –help option of the w command to view the command line switches.
The uname Command
This command prints system information to the standard output:
root@debian8:~# uname -a Linux debian8 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux root@debian8:~# uname -s Linux root@debian8:~# uname -n debian8 root@debian8:~# uname -r 3.16.0-4-amd64 root@debian8:~# uname -v #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) root@debian8:~# uname -m x86_64 root@debian8:~# uname -p unknown root@debian8:~# uname -i unknown root@debian8:~# uname -o GNU/Linux
root@ubuntu1604:~# uname -a Linux ubuntu1604 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux root@ubuntu1604:~# uname -s Linux root@ubuntu1604:~# uname -n ubuntu1604 root@ubuntu1604:~# uname -r 4.4.0-21-generic root@ubuntu1604:~# uname -v #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 root@ubuntu1604:~# uname -m x86_64 root@ubuntu1604:~# uname -p x86_64 root@ubuntu1604:~# uname -i x86_64 root@ubuntu1604:~# uname -o GNU/Linux
[root@centos7 ~]# uname -a Linux centos7.fenestros.loc 3.10.0-327.13.1.el7.x86_64 #1 SMP Thu Mar 31 16:04:38 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux [root@centos7 ~]# uname -s Linux [root@centos7 ~]# uname -n centos7.fenestros.loc [root@centos7 ~]# uname -r 3.10.0-327.13.1.el7.x86_64 [root@centos7 ~]# uname -v #1 SMP Thu Mar 31 16:04:38 UTC 2016 [root@centos7 ~]# uname -m x86_64 [root@centos7 ~]# uname -p x86_64 [root@centos7 ~]# uname -i x86_64 [root@centos7 ~]# uname -o GNU/Linux
SLES12SP1:~ # uname -a Linux SLES12SP1 3.12.49-11-default #1 SMP Wed Nov 11 20:52:43 UTC 2015 (8d714a0) x86_64 x86_64 x86_64 GNU/Linux SLES12SP1:~ # uname -s Linux SLES12SP1:~ # uname -n SLES12SP1 SLES12SP1:~ # uname -r 3.12.49-11-default SLES12SP1:~ # uname -v #1 SMP Wed Nov 11 20:52:43 UTC 2015 (8d714a0) SLES12SP1:~ # uname -m x86_64 SLES12SP1:~ # uname -p x86_64 SLES12SP1:~ # uname -i x86_64 SLES12SP1:~ # uname -o GNU/Linux
Command Line Switches
To do : Use the –help option of the uname command to view the command line switches.
The du Command
This command summarizes disk usage of each file, recursively for directories:
root@debian8:~# du -sh /* 2>/dev/null 12M /bin 31M /boot 0 /dev 6.9M /etc 1.9M /home 0 /initrd.img 207M /lib 4.0K /lib64 16K /lost+found 8.0K /media 4.0K /mnt 152M /opt 0 /proc 59M /root 4.7M /run 8.5M /sbin 4.0K /srv 0 /sys 100K /tmp 2.0G /usr 767M /var 0 /vmlinuz
root@ubuntu1604:~# du -sh /* 2>/dev/null 13M /bin 100M /boot 4,0K /cdrom 0 /dev 13M /etc 1,7M /home 0 /initrd.img 0 /initrd.img.old 584M /lib 4,0K /lib64 16K /lost+found 4,0K /media 4,0K /mnt 155M /opt 0 /proc 6,1M /root 4,1M /run 13M /sbin 4,0K /snap 4,0K /srv 0 /sys 72K /tmp 2,9G /usr 341M /var 0 /vmlinuz 0 /vmlinuz.old
[root@centos7 ~]# du -sh /* 2>/dev/null 0 /bin 187M /boot 0 /dev 33M /etc 20M /home 0 /lib 0 /lib64 0 /lost+found 0 /media 0 /mnt 173M /opt 0 /proc 43M /root 8.7M /run 0 /sbin 0 /srv 0 /sys 64K /tmp 3.6G /usr 228M /var
SLES12SP1:~ # du -sh /* 2>/dev/null 5.1M /bin 44M /boot 0 /dev 19M /etc 216K /home 190M /lib 16M /lib64 0 /mnt 151M /opt 0 /proc 6.1M /root 5.4M /run 11M /sbin 0 /selinux 64K /srv 0 /sys 60K /tmp 2.6G /usr 133M /var
Important : Note the use of the 2>/dev/null redirection. This sends all eventual errors in the file descriptor 2 directly to /dev/null so that they do not appear in the output. File descriptors are covered in the The Command Line Interface unit.
Command Line Switches
To do : Use the –help option of the du command to view the command line switches.
The clear Command
This command is used to clear the current screen of the terminal:
root@debian8:~# clear root@debian8:~#
root@ubuntu1604:~# clear root@ubuntu1604:~#
[root@centos7 ~]# clear [root@centos7 ~]#
SLES12SP1:~ # clear SLES12SP1:~ #
The exit Command
This command exits the current shell:
root@debian8:~# exit logout trainee@debian8:~$
root@ubuntu1604:~# exit logout trainee@ubuntu1604:~$
[root@centos7 ~]# exit logout [trainee@centos7 ~]$
SLES12SP1:~ # exit logout trainee@SLES12SP1:~>
Command Line Switches
To do : Use the help command with exit option to view the command line switches.
The logout Command
This command logs out a user from a login shell writing the utmp and wtmp entries in the log files.
Command Line Switches
To do : Use the help command with logout option to view the command line switches.
The sleep Command
This command pauses for a number seconds. The number is specified as the first argument.
Command Line Switches
To do : Use the –help option of the sleep command to view the command line switches.
The wall Command
When using RHEL/CentOS 7:
Wall sends a message to everybody logged in with their mesg(1) permission set to yes. The message can be given as an argument to wall, or it can be sent to wall's standard input. When using the standard input from a terminal, the message should be terminated with the EOF key (usually Control-D). The length of the message is limited to 20 lines. For every invocation of wall a notification will be written to syslog, with facility LOG_USER and level LOG_INFO.
Start a second session as trainee via ssh on your VM. Return to your first session as root and type :
[trainee@centos7 ~]$ su - Password: fenestros Last login: Thu Sep 29 17:08:56 CEST 2016 on pts/0 [root@centos7 ~]# wall this is a message from root [root@centos7 ~]# Broadcast message from root@centos7.fenestros.loc (pts/0) (Fri Sep 30 05:35:26 2016): this is a message from root [Enter] [root@centos7 ~]#
In the second session you should see the following message :
[trainee@centos7 ~]$ Broadcast message from root@centos7.fenestros.loc (pts/0) (Fri Sep 30 05:35:26 2016): this is a message from root
Now look at the end of the/var/log/messages file :
[root@centos7 ~]# tail /var/log/messages Sep 30 05:31:08 centos7 sh: Sleeping '' '' Sep 30 05:34:16 centos7 sh: Sleeping '' '' Sep 30 05:35:13 centos7 systemd: Started Session 311 of user trainee. Sep 30 05:35:13 centos7 systemd-logind: New session 311 of user trainee. Sep 30 05:35:13 centos7 systemd: Starting Session 311 of user trainee. Sep 30 05:35:13 centos7 dbus[515]: [system] Activating service name='org.freedesktop.problems' (using servicehelper) Sep 30 05:35:13 centos7 dbus-daemon: dbus[515]: [system] Activating service name='org.freedesktop.problems' (using servicehelper) Sep 30 05:35:13 centos7 dbus[515]: [system] Successfully activated service 'org.freedesktop.problems' Sep 30 05:35:13 centos7 dbus-daemon: dbus[515]: [system] Successfully activated service 'org.freedesktop.problems' Sep 30 05:35:26 centos7 wall[27550]: wall: user root broadcasted 1 lines (29 chars)
Important : La commande wall ignore la variable d’environnement TZ. L’heure affichée dans la première page est basée sur les paramètres de régionalisation du système.
When using Debian 8, Ubuntu 16.04 LTS and SLES 12:
wall displays a message, or the contents of a file, or otherwise its standard input, on the terminals of all currently logged in users.The command will wrap lines that are longer than 79 characters. Short lines are whitespace padded to have 79 characters. The command will always put a carriage return and new line at the end of each line. Only the superuser can write on the terminals of users who have chosen to deny messages or are using a program which automatically denies messages. Reading from a file is refused when the invoker is not superuser and the program is suid or sgid.
Start a second session as trainee via ssh on your VM. Return to your first session as root and type :
trainee@debian8:~$ su - Password: fenestros root@debian8:~# wall this is a message from root Broadcast message from trainee@debian8 (pts/0) (Sat Aug 20 03:23:20 2016): this is a message from root root@debian8:~#
trainee@ubuntu1604:~$ sudo su - [sudo] password for trainee: trainee root@ubuntu1604:~# wall this is a message from root Broadcast message from trainee@ubuntu1604 (pts/0) (Fri Oct 7 10:18:21 2016): this is a message from root root@ubuntu1604:~#
trainee@SLES12SP1:~> su - Password: fenestros SLES12SP1:~ # wall this is a message from root Broadcast message from trainee@SLES12SP1 (pts/1) (Sat Oct 1 18:39:50 2016): this is a message from root SLES12SP1:~ #
In the second session you should see the following message :
Broadcast message from trainee@debian8 (pts/0) (Sat Aug 20 03:23:20 2016): this is a message from root
Broadcast message from trainee@ubuntu1604 (pts/0) (Fri Oct 7 10:18:21 2016): this is a message from root
Broadcast message from trainee@SLES12SP1 (pts/1) (Sat Oct 1 18:39:50 2016): this is a message from root
The seq Command
The seq command prints numbers from FIRST to LAST, in steps of INCREMENT:
- seq [OPTION]… LAST
- seq [OPTION]… FIRST LAST
- seq [OPTION]… FIRST INCREMENT LAST
For example :
root@debian8:~# seq 10 1 2 3 4 5 6 7 8 9 10 root@debian8:~# seq 20 30 20 21 22 23 24 25 26 27 28 29 30 root@debian8:~# seq 20 10 90 20 30 40 50 60 70 80 90 root@debian8:~#
root@ubuntu1604:~# seq 10 1 2 3 4 5 6 7 8 9 10 root@ubuntu1604:~# seq 20 30 20 21 22 23 24 25 26 27 28 29 30 root@ubuntu1604:~# seq 20 10 90 20 30 40 50 60 70 80 90 root@ubuntu1604:~#
[root@centos7 ~]# seq 10 1 2 3 4 5 6 7 8 9 10 [root@centos7 ~]# seq 20 30 20 21 22 23 24 25 26 27 28 29 30 [root@centos7 ~]# seq 20 10 90 20 30 40 50 60 70 80 90 [root@centos7 ~]#
SLES12SP1:~ # seq 10 1 2 3 4 5 6 7 8 9 10 SLES12SP1:~ # seq 20 30 20 21 22 23 24 25 26 27 28 29 30 SLES12SP1:~ # seq 20 10 90 20 30 40 50 60 70 80 90 SLES12SP1:~ #
Command Line Switches
To do : Use the –help option of the seq command to view the command line switches.
The screen Command
Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.
The screen command is not installed by default under Debian 8, Ubuntu 16.04 LTS and RHEL/CentOS 7. Use the appropriate package manager to install it:
root@debian8:~# which screen root@debian8:~# apt-get install screen Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: iselect screenie byobu The following NEW packages will be installed: screen 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 569 kB of archives. After this operation, 930 kB of additional disk space will be used. Get:1 http://ftp.fr.debian.org/debian/ jessie/main screen amd64 4.2.1-3+deb8u1 [569 kB] Fetched 569 kB in 0s (3,163 kB/s) Selecting previously unselected package screen. (Reading database ... 82450 files and directories currently installed.) Preparing to unpack .../screen_4.2.1-3+deb8u1_amd64.deb ... Unpacking screen (4.2.1-3+deb8u1) ... Processing triggers for systemd (215-17+deb8u4) ... Processing triggers for install-info (5.2.0.dfsg.1-6) ... Processing triggers for man-db (2.7.0.2-5) ... Setting up screen (4.2.1-3+deb8u1) ... Processing triggers for systemd (215-17+deb8u4) ... root@debian8:~# which screen /usr/bin/screen
root@ubuntu1604:~# which screen root@ubuntu1604:~# apt-get install screen Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libpango1.0-0 libpangox-1.0-0 Use 'apt autoremove' to remove them. Suggested packages: iselect | screenie | byobu The following NEW packages will be installed: screen 0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded. Need to get 560 kB of archives. After this operation, 972 kB of additional disk space will be used. Get:1 http://fr.archive.ubuntu.com/ubuntu xenial/main amd64 screen amd64 4.3.1-2build1 [560 kB] Fetched 560 kB in 0s (2 306 kB/s) Selecting previously unselected package screen. (Reading database ... 207619 files and directories currently installed.) Preparing to unpack .../screen_4.3.1-2build1_amd64.deb ... Unpacking screen (4.3.1-2build1) ... Processing triggers for systemd (229-4ubuntu10) ... Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for install-info (6.1.0.dfsg.1-5) ... Processing triggers for man-db (2.7.5-1) ... Setting up screen (4.3.1-2build1) ... Processing triggers for systemd (229-4ubuntu10) ... Processing triggers for ureadahead (0.100.0-19) ... root@ubuntu1604:~# which screen /usr/bin/screen
[root@centos7 ~]# which screen /usr/bin/which: no screen in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) [root@centos7 ~]# yum install screen Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.rezopole.net * extras: centos.mirror.ate.info * updates: centos.mirror.fr.planethoster.net Resolving Dependencies --> Running transaction check ---> Package screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================= Package Arch Version Repository Size ================================================================================= Installing: screen x86_64 4.1.0-0.23.20120314git3c2946.el7_2 updates 552 k Transaction Summary ================================================================================= Install 1 Package Total download size: 552 k Installed size: 914 k Is this ok [y/d/N]: y Downloading packages: screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64.rpm | 552 kB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64 1/1 Verifying : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64 1/1 Installed: screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2 Complete! [root@centos7 ~]# which screen /bin/screen
However, the screen command is installed by default under SLES 12 :
SLES12SP1:~ # which screen /usr/bin/screen
Create a session with screen:
root@debian8:~# screen -S mysession
root@ubuntu1604:~# screen -S mysession
[root@centos7 ~]# screen -S mysession
SLES12SP1:~ # screen -S mysession
Important - When using RHEL/CentOS 7, you will notice that the title of the window holding the ssh session changes to [screen 0: root@centos7:~]. However when using Debian 8, Ubuntu 16.04 LTS or SLES 12 you will not see this.
Now press the CTRL and A keys, release the A key and press the C key in order to create a second nested screen.
Important - When using RHEL/CentOS 7, you will notice that the title of the window holding the ssh session changes to [screen 1: root@centos7:~]. However when using Debian 8, Ubuntu 16.04 LTS or SLES 12 you will not see this.
To return to the first screen, use the CTRL A A keys. This allows you to toggle between the last two screens used.
To see the status of all active screens, use the screen -ls command:
root@debian8:~# screen -ls There is a screen on: 27309.mysession (20/08/16 04:20:08) (Attached) 1 Socket in /var/run/screen/S-root.
root@ubuntu1604:~# screen -ls There is a screen on: 1745.mysession (07/10/2016 11:00:55) (Attached) 1 Socket in /var/run/screen/S-root
[root@centos7 ~]# screen -ls There is a screen on: 25812.mysession (Attached) 1 Socket in /var/run/screen/S-root.
SLES12SP1:~ # screen -ls There is a screen on: 11827.mysession (Attached) 1 Socket in /var/run/screens/S-root.
Now enter the following commands:
root@debian8:~# sleep 9999 & [1] 2941 root@debian8:~# jobs [1]+ Running sleep 9999 & root@debian8:~#
root@ubuntu1604:~# sleep 9999 & [1] 9699 root@ubuntu1604:~# jobs [1]+ Running sleep 9999 & root@ubuntu1604:~#
[root@centos7 ~]# sleep 9999 & [1] 2272 [root@centos7 ~]# jobs [1]+ Running sleep 9999 & [root@centos7 ~]#
SLES12SP1:~ # sleep 9999 & [1] 19879 SLES12SP1:~ # jobs [1]+ Running sleep 9999 & SLES12SP1:~ #
In order to detach the current screen press the CTRL and A keys, release the A key and press the D key:
root@debian8:~# screen -S mysession [detached from 27309.mysession] root@debian8:~#
root@ubuntu1604:~# screen -S mysession [detached from 1745.mysession] root@ubuntu1604:~#
[root@centos7 ~]# screen -S mysession [detached from 25812.mysession] [root@centos7 ~]#
[detached from 11827.mysession] SLES12SP1:~ #
To re-attach the screen, execute the following command:
root@debian8:~# screen -r
root@ubuntu1604:~# screen -r
[root@centos7 ~]# screen -r
SLES12SP1:~ # screen -r
Using the jobs command, check if the process created by the sleep command is still running:unit
root@debian8:~# jobs [1]+ Running sleep 9999 &
root@ubuntu1604:~# jobs [1]+ Running sleep 9999 &
[root@centos7 ~]# jobs [1]+ Running sleep 9999 &
SLES12SP1:~ # jobs [1]+ Running sleep 9999 &
To move forward or backwards between screens press the CTRL and A keys, release the A key and press the N key or press the CTRL and A keys, release the A key and press the P key.
Once again detach the current screen by pressing the CTRL A keys, releasing the A key and then pressing D:
root@debian8:~# screen -S mysession [detached from 27309.mysession] key root@debian8:~#
root@ubuntu1604:~# screen -S mysession [detached from 1745.mysession] root@ubuntu1604:~#
[root@centos7 ~]# screen -S mysession [detached from 25812.mysession] [root@centos7 ~]#
[detached from 11827.mysession] SLES12SP1:~ #
Now create a new, non-nested screen:
root@debian8:~# screen -S mysession1
root@ubuntu1604:~# screen -S mysession1
[root@centos7 ~]# screen -S mysession1
SLES12SP1:~ # screen -S mysession1
Use the screen -ls command to see what has happened:
root@debian8:~# screen -ls There are screens on: 10234.mysession1 (20/08/16 07:17:19) (Attached) 27309.mysession (20/08/16 04:20:08) (Detached) 2 Sockets in /var/run/screen/S-root.
root@ubuntu1604:~# screen -ls There are screens on: 15800.mysession1 (07/10/2016 13:58:29) (Attached) 1745.mysession (07/10/2016 11:00:55) (Detached) 2 Sockets in /var/run/screen/S-root.
[root@centos7 ~]# screen -ls There are screens on: 14942.mysession1 (Attached) 25812.mysession (Detached) 2 Sockets in /var/run/screen/S-root.
SLES12SP1:~ # screen -ls There are screens on: 26655.mysession1 (Attached) 11827.mysession (Detached) 2 Sockets in /var/run/screens/S-root.
To re-attach a specific screen, reference it by it's number:
root@debian8:~# screen -r 27309
root@ubuntu1604:~# screen -r 1745
[root@centos7 ~]# screen -r 25812
SLES12SP1:~ # screen -r 11827
Finally, check out what has happened:
root@debian8:~# sleep 9999 & [1] 2941 root@debian8:~# jobs [1]+ Running sleep 9999 &unit root@debian8:~# jobs [1]+ Running sleep 9999 & root@debian8:~# screen -ls There are screens on: 10234.mysession1 (20/08/16 07:17:20) (Attached) 27309.mysession (20/08/16 04:20:09) (Attached) 2 Sockets in /var/run/screen/S-root.
root@ubuntu1604:~# sleep 9999 & [1] 9699 root@ubuntu1604:~# jobs [1]+ Running sleep 9999 & root@ubuntu1604:~# jobs [1]+ Running sleep 9999 & root@ubuntu1604:~# screen -ls There are screens on: 15800.mysession1 (07/10/2016 13:58:29) (Attached) 1745.mysession (07/10/2016 11:00:55) (Attached) 2 Sockets in /var/run/screen/S-root.
[root@centos7 ~]# sleep 9999 & [1] 2272 [root@centos7 ~]# jobs [1]+ Running sleep 9999 & [root@centos7 ~]# jobs [1]+ Running sleep 9999 & [root@centos7 ~]# screen -ls There is a screen on: 25812.mysession (Attached) 1 Socket in /var/run/screen/S-root. [root@centos7 ~]# screen -ls There are screens on: 14942.mysession1 (Attached) 25812.mysession (Attached) 2 Sockets in /var/run/screen/S-root.
SLES12SP1:~ # sleep 9999 & [1] 19879 SLES12SP1:~ # jobs [1]+ Running sleep 9999 & SLES12SP1:~ # jobs [1]+ Running sleep 9999 & SLES12SP1:~ # screen -ls There are screens on: 26655.mysession1 (Attached) 11827.mysession (Attached) 2 Sockets in /var/run/screens/S-root.
Command Line Switches
To do : Use the –help option of the screen command to view the command line switches.
Switches and Arguments
Switches under Linux can either be short or long. Several differences are important to note.
Firstly short options are generally preceded by a single dash -, whilst long options are preceded by a double dash - -.
An example is the help option used with most commands:
- -h
- –help
Secondly, Linux short switches can be combined whereas long switches cannot be combined. For example ls -l -a -i can also be written as ls -lai, ls -lia or ls -ali:
root@debian8:~# ls -lai /tmp total 40 130564 drwxrwxrwt 10 root root 4096 Aug 20 09:17 . 2 drwxr-xr-x 22 root root 4096 Aug 1 12:38 .. 130572 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .font-unix 134332 drwxr-xr-x 2 root root 4096 Aug 18 11:33 hsperfdata_root 130570 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .ICE-unix 140612 drwxr-xr-x 2 root root 4096 Aug 18 13:36 inode 140574 srw------- 1 root root 0 Aug 18 11:32 .java_pid1704 140611 srw------- 1 root root 0 Aug 18 11:33 .java_pid2098 134331 drwx------ 2 root root 4096 Aug 18 11:29 pulse-PKdhtXMmr18n 130573 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .Test-unix 130569 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .X11-unix 130571 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .XIM-unix root@debian8:~# ls -ali /tmp total 40 130564 drwxrwxrwt 10 root root 4096 Aug 20 09:17 . 2 drwxr-xr-x 22 root root 4096 Aug 1 12:38 .. 130572 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .font-unix 134332 drwxr-xr-x 2 root root 4096 Aug 18 11:33 hsperfdata_root 130570 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .ICE-unix 140612 drwxr-xr-x 2 root root 4096 Aug 18 13:36 inode 140574 srw------- 1 root root 0 Aug 18 11:32 .java_pid1704 140611 srw------- 1 root root 0 Aug 18 11:33 .java_pid2098 134331 drwx------ 2 root root 4096 Aug 18 11:29 pulse-PKdhtXMmr18n 130573 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .Test-unix 130569 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .X11-unix 130571 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .XIM-unix
root@ubuntu1604:~# ls -lai /tmp total 40 390918 drwxrwxrwt 10 root root 4096 oct. 7 16:31 . 2 drwxr-xr-x 24 root root 4096 sept. 28 10:40 .. 521792 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .font-unix 522570 drwxr-xr-x 2 root root 4096 sept. 28 10:34 hsperfdata_root 521777 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .ICE-unix 521308 drwxr-xr-x 2 root root 4096 sept. 29 10:32 inode 395765 srw------- 1 root root 0 sept. 28 10:34 .java_pid2124 521306 drwx------ 3 root root 4096 sept. 29 10:19 systemd-private-cd33d40e1d3a4e08a9cde3de3603311e-systemd-timesyncd.service-bxC1MJ 521801 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .Test-unix 521757 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .X11-unix 521785 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .XIM-unix root@ubuntu1604:~# ls -ali /tmp total 40 390918 drwxrwxrwt 10 root root 4096 oct. 7 16:31 . 2 drwxr-xr-x 24 root root 4096 sept. 28 10:40 .. 521792 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .font-unix 522570 drwxr-xr-x 2 root root 4096 sept. 28 10:34 hsperfdata_root 521777 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .ICE-unix 521308 drwxr-xr-x 2 root root 4096 sept. 29 10:32 inode 395765 srw------- 1 root root 0 sept. 28 10:34 .java_pid2124 521306 drwx------ 3 root root 4096 sept. 29 10:19 systemd-private-cd33d40e1d3a4e08a9cde3de3603311e-systemd-timesyncd.service-bxC1MJ 521801 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .Test-unix 521757 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .X11-unix 521785 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .XIM-unix
[root@centos7 ~]# ls -lai /tmp total 244 11071 drwxrwxrwt. 10 root root 260 Sep 30 06:24 . 128 dr-xr-xr-x. 18 root root 4096 Dec 10 2015 .. 13635 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .font-unix 24858 drwxr-xr-x. 2 root root 100 Sep 30 06:05 hsperfdata_root 13597 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .ICE-unix 287056 drwxr-xr-x. 2 root root 100 Sep 28 12:30 inode 24861 srw-------. 1 root root 0 Sep 28 10:52 .java_pid3213 25344 srw-------. 1 root root 0 Sep 28 10:52 .java_pid3302 16615 drwx------. 3 root root 60 Sep 28 10:49 systemd-private-45071248a58f4fd2a4de940a5734c8ec-cups.service-ODc5L6 13595 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .Test-unix 13590 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .X11-unix 13629 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .XIM-unix 8098838 -rw-------. 1 root root 242724 Sep 30 05:45 yum_save_tx.2016-09-30.05-45.FF7KO4.yumtx [root@centos7 ~]# ls -ali /tmp total 244 11071 drwxrwxrwt. 10 root root 260 Sep 30 06:24 . 128 dr-xr-xr-x. 18 root root 4096 Dec 10 2015 .. 13635 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .font-unix 24858 drwxr-xr-x. 2 root root 100 Sep 30 06:05 hsperfdata_root 13597 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .ICE-unix 287056 drwxr-xr-x. 2 root root 100 Sep 28 12:30 inode 24861 srw-------. 1 root root 0 Sep 28 10:52 .java_pid3213 25344 srw-------. 1 root root 0 Sep 28 10:52 .java_pid3302 16615 drwx------. 3 root root 60 Sep 28 10:49 systemd-private-45071248a58f4fd2a4de940a5734c8ec-cups.service-ODc5L6 13595 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .Test-unix 13590 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .X11-unix 13629 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .XIM-unix 8098838 -rw-------. 1 root root 242724 Sep 30 05:45 yum_save_tx.2016-09-30.05-45.FF7KO4.yumtx
SLES12SP1:~ # ls -lai /tmp total 8 256 drwxrwxrwt 1 root root 802 Oct 2 01:00 . 256 drwxr-xr-x 1 root root 156 May 1 14:55 .. 258 drwxrwxrwt 1 root root 0 May 3 13:54 .ICE-unix 261 drwxrwxrwt 1 root root 0 May 2 15:56 .Test-unix 257 drwxrwxrwt 1 root root 0 May 3 13:53 .X11-unix 259 drwxrwxrwt 1 root root 0 May 2 15:56 .XIM-unix 373 drwx------ 1 trainee users 12 May 3 13:54 .esd-1000 279 drwx------ 1 gdm gdm 0 May 3 13:54 .esd-486 260 drwxrwxrwt 1 root root 0 May 2 15:56 .font-unix 502 srw------- 1 root root 0 Sep 30 10:26 .java_pid2399 462 srw------- 1 root root 0 Aug 18 12:48 .java_pid2546 448 srw------- 1 root root 0 May 3 14:01 .java_pid3281 403 drwxr-xr-x 1 root root 8 Sep 30 10:26 hsperfdata_root 488 drwxr-xr-x 1 trainee users 48 Aug 18 13:14 inode 444 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera1411267841657715235client 439 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera3336001029897679475server 440 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera4847938942232964844client 443 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera5050357016347721452server 388 drwx------ 1 root root 6 May 3 13:54 systemd-private-04f820fa26c745be8ddba814c6292f21-rtkit-daemon.service-o4lKP5 427 -rw-r--r-- 1 root root 0 May 3 14:01 systemicontmp5578677472245134133dat 426 drwxr-xr-x 1 root root 0 May 3 14:01 systemicontmp7082392205020802884dat SLES12SP1:~ # ls -ali /tmp total 8 256 drwxrwxrwt 1 root root 802 Oct 2 01:00 . 256 drwxr-xr-x 1 root root 156 May 1 14:55 .. 258 drwxrwxrwt 1 root root 0 May 3 13:54 .ICE-unix 261 drwxrwxrwt 1 root root 0 May 2 15:56 .Test-unix 257 drwxrwxrwt 1 root root 0 May 3 13:53 .X11-unix 259 drwxrwxrwt 1 root root 0 May 2 15:56 .XIM-unix 373 drwx------ 1 trainee users 12 May 3 13:54 .esd-1000 279 drwx------ 1 gdm gdm 0 May 3 13:54 .esd-486 260 drwxrwxrwt 1 root root 0 May 2 15:56 .font-unix 502 srw------- 1 root root 0 Sep 30 10:26 .java_pid2399 462 srw------- 1 root root 0 Aug 18 12:48 .java_pid2546 448 srw------- 1 root root 0 May 3 14:01 .java_pid3281 403 drwxr-xr-x 1 root root 8 Sep 30 10:26 hsperfdata_root 488 drwxr-xr-x 1 trainee users 48 Aug 18 13:14 inode 444 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera1411267841657715235client 439 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera3336001029897679475server 440 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera4847938942232964844client 443 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera5050357016347721452server 388 drwx------ 1 root root 6 May 3 13:54 systemd-private-04f820fa26c745be8ddba814c6292f21-rtkit-daemon.service-o4lKP5 427 -rw-r--r-- 1 root root 0 May 3 14:01 systemicontmp5578677472245134133dat 426 drwxr-xr-x 1 root root 0 May 3 14:01 systemicontmp7082392205020802884dat
However ls -l –all –inode cannot be written ls -l –allinode:
root@debian8:~# ls -l --all --inode /tmp total 40 130564 drwxrwxrwt 10 root root 4096 Aug 20 09:17 . 2 drwxr-xr-x 22 root root 4096 Aug 1 12:38 .. 130572 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .font-unix 134332 drwxr-xr-x 2 root root 4096 Aug 18 11:33 hsperfdata_root 130570 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .ICE-unix 140612 drwxr-xr-x 2 root root 4096 Aug 18 13:36 inode 140574 srw------- 1 root root 0 Aug 18 11:32 .java_pid1704 140611 srw------- 1 root root 0 Aug 18 11:33 .java_pid2098 134331 drwx------ 2 root root 4096 Aug 18 11:29 pulse-PKdhtXMmr18n 130573 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .Test-unix 130569 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .X11-unix 130571 drwxrwxrwt 2 root root 4096 Aug 18 11:28 .XIM-unix root@debian8:~# ls -l --allinode /tmp ls: unrecognized option '--allinode' Try 'ls --help' for more information.
root@ubuntu1604:~# ls -l --all --inode /tmp total 40 390918 drwxrwxrwt 10 root root 4096 oct. 7 16:31 . 2 drwxr-xr-x 24 root root 4096 sept. 28 10:40 .. 521792 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .font-unix 522570 drwxr-xr-x 2 root root 4096 sept. 28 10:34 hsperfdata_root 521777 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .ICE-unix 521308 drwxr-xr-x 2 root root 4096 sept. 29 10:32 inode 395765 srw------- 1 root root 0 sept. 28 10:34 .java_pid2124 521306 drwx------ 3 root root 4096 sept. 29 10:19 systemd-private-cd33d40e1d3a4e08a9cde3de3603311e-systemd-timesyncd.service-bxC1MJ 521801 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .Test-unix 521757 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .X11-unix 521785 drwxrwxrwt 2 root root 4096 sept. 28 10:31 .XIM-unix root@ubuntu1604:~# ls -l --allinode /tmp ls: unrecognized option '--allinode' Try 'ls --help' for more information.
[root@centos7 ~]# ls -l --all --inode /tmp total 244 11071 drwxrwxrwt. 10 root root 260 Sep 30 06:24 . 128 dr-xr-xr-x. 18 root root 4096 Dec 10 2015 .. 13635 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .font-unix 24858 drwxr-xr-x. 2 root root 100 Sep 30 06:05 hsperfdata_root 13597 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .ICE-unix 287056 drwxr-xr-x. 2 root root 100 Sep 28 12:30 inode 24861 srw-------. 1 root root 0 Sep 28 10:52 .java_pid3213 25344 srw-------. 1 root root 0 Sep 28 10:52 .java_pid3302 16615 drwx------. 3 root root 60 Sep 28 10:49 systemd-private-45071248a58f4fd2a4de940a5734c8ec-cups.service-ODc5L6 13595 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .Test-unix 13590 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .X11-unix 13629 drwxrwxrwt. 2 root root 40 Sep 28 10:48 .XIM-unix 8098838 -rw-------. 1 root root 242724 Sep 30 05:45 yum_save_tx.2016-09-30.05-45.FF7KO4.yumtx [root@centos7 ~]# ls -l --allinode /tmp ls: unrecognized option '--allinode' Try 'ls --help' for more information
SLES12SP1:~ # ls -l --all --inode /tmp total 8 256 drwxrwxrwt 1 root root 802 Oct 2 01:00 . 256 drwxr-xr-x 1 root root 156 May 1 14:55 .. 258 drwxrwxrwt 1 root root 0 May 3 13:54 .ICE-unix 261 drwxrwxrwt 1 root root 0 May 2 15:56 .Test-unix 257 drwxrwxrwt 1 root root 0 May 3 13:53 .X11-unix 259 drwxrwxrwt 1 root root 0 May 2 15:56 .XIM-unix 373 drwx------ 1 trainee users 12 May 3 13:54 .esd-1000 279 drwx------ 1 gdm gdm 0 May 3 13:54 .esd-486 260 drwxrwxrwt 1 root root 0 May 2 15:56 .font-unix 502 srw------- 1 root root 0 Sep 30 10:26 .java_pid2399 462 srw------- 1 root root 0 Aug 18 12:48 .java_pid2546 448 srw------- 1 root root 0 May 3 14:01 .java_pid3281 403 drwxr-xr-x 1 root root 8 Sep 30 10:26 hsperfdata_root 488 drwxr-xr-x 1 trainee users 48 Aug 18 13:14 inode 444 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera1411267841657715235client 439 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera3336001029897679475server 440 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera4847938942232964844client 443 -rwxrwxrwx 1 root root 50048 May 3 14:01 managera5050357016347721452server 388 drwx------ 1 root root 6 May 3 13:54 systemd-private-04f820fa26c745be8ddba814c6292f21-rtkit-daemon.service-o4lKP5 427 -rw-r--r-- 1 root root 0 May 3 14:01 systemicontmp5578677472245134133dat 426 drwxr-xr-x 1 root root 0 May 3 14:01 systemicontmp7082392205020802884dat SLES12SP1:~ # ls -l --allinode /tmp ls: unrecognized option '--allinode' Try 'ls --help' for more information.
Important - You should not combine any short options that take an argument.
Manipulating Text Files
Text files play a very important role under Linux. For example, almost all configuration files are simple text files and being able to manipulate them is of great importance. Manipulating text files is essentially achieved by using Regular Expressions. There are two types of Regular Expressions:
- The IEEE POSIX Basic Regular Expressions (BRE) understood by the commands vi, grep, expr and sed,
- The IEEE POSIX Extended Regular Expressions (ERE) understood by the commands egrep ( grep -E ) and awk.
Regular Expressions
Regular Expressions use Metacharacters. Certain are common to both BREs and EREs:
Metacharacter | Description |
---|---|
^string | Match lines beginning with string |
string$ | Match lines ending with string |
\Metacharacter | Cancel any special effect associated with Metacharacter |
[string] | Match any of the characters within string |
[^string] | Exclude any of the characters in string |
. | Match any character except when at the end of a line |
character* | Match 0 or more occurrences of character |
\< | Match string at the beginning of a word |
\> | Match string at the end of a word |
BREs
Certain Metacharacters are specific to BREs:
Metacharacter | Description |
---|---|
\{x,y\} | Match from x to y occurrences of the preceeding element |
\{x\} | Match exactly x occurrences of the preceeding element |
\{x,\} | Match x or more occurrences of the preceeding element |
\(BRE) | Commit to memory the BRE |
\1 | Recall the first BRE committed to memory |
\2, \3 … | Recall the second BRE committed to memory, recall the third BRE committed to memory … |
EREs
Certain Metacharacters are specific to EREs:
Metacharacter | Description |
---|---|
{x,y} | Match from x to y occurrences of the preceeding element |
{x} | Match exactly x occurrences of the preceeding element |
{x,} | |
? | Matches 0 or 1 occurrence of the preceeding element |
+ | Matches 1 or more occurrence(s) of the preceeding element |
| | Matches either the expression before or the expression after the operator |
() | Combines the Reguler Expressions between the parentheses |
Text-search Utilities
The grep Command
The grep command can be used to find lines containing a string of characters in a group of files. The -v or –invert-case option can be stipulated to find lines that do not contain the specified string.
The grep command is case sensitive. The -i or –ignore-case option can be specified in order to use grep in a non case sensitive search.
The grep command can also use BREs.
Command Line Switches
To do : Use the –help option of the grep command to view the command line switches.
The egrep Command
The egrep command is identical to the grep command when used with the -E switch. Both can use EREs.
Command Line Switches
To do : Use the –help option of the egrep command to view the command line switches.
The fgrep Command
The fgrep command is identical to the grep command when used with the -F switch. Both have no knowledge of Regular Expressions.
To do : Use the –help option of the fgrep command to view the command line switches.
LAB #1 - Using grep, egrep and fgrep
Download the following file by clicking on it's title:
- greptest
fenestrOS fenestros 555-5555 f .fenestros .fe £
Move the file to the /tmp directory:
root@debian8:~# mv /home/trainee/Downloads/greptest /tmp/greptest
root@ubuntu1604:~# mv /home/trainee/Downloads/greptest /tmp/greptest
[root@centos7 ~]# mv /home/trainee/Downloads/greptest /tmp/greptest
SLES12SP1:~ # mv /home/trainee/Downloads/greptest /tmp/greptest
Now use grep to search for lines containing at least one uppercase or lowercase letter:
root@debian8:~# grep '[a-zA-Z]' /tmp/greptest fenestrOS fenestros f .fenestros .fe
root@ubuntu1604:~# grep '[a-zA-Z]' /tmp/greptest fenestrOS fenestros f .fenestros .fe
[root@centos7 ~]# grep '[a-zA-Z]' /tmp/greptest fenestrOS fenestros f .fenestros .fe
SLES12SP1:~ # grep '[a-zA-Z]' /tmp/greptest fenestrOS fenestros f .fenestros .fe
Next use grep to search for lines containing at least one uppercase or lowercase letter or a number:
root@debian8:~# grep '[a-zA-Z0-9]' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe
root@ubuntu1604:~# grep '[a-zA-Z0-9]' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe
[root@centos7 ~]# grep '[a-zA-Z0-9]' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe
SLES12SP1:~ # grep '[a-zA-Z0-9]' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe
To search for the NNN-NNNN pattern where N is a number, use the following command:
root@debian8:~# grep '[0-9]\{3\}-[0-9]\{4\}' /tmp/greptest 555-5555
root@ubuntu1604:~# grep '[0-9]\{3\}-[0-9]\{4\}' /tmp/greptest 555-5555
[root@centos7 ~]# grep '[0-9]\{3\}-[0-9]\{4\}' /tmp/greptest 555-5555
SLES12SP1:~ # grep '[0-9]\{3\}-[0-9]\{4\}' /tmp/greptest 555-5555
Lines containing just one character have that character both at the beginning (^) and at the end ($) of the line:
root@debian8:~# grep '^.$' /tmp/greptest f £
root@ubuntu1604:~# grep '^.$' /tmp/greptest f £
[root@centos7 ~]# grep '^.$' /tmp/greptest f £
SLES12SP1:~ # grep '^.$' /tmp/greptest f £
To search for a line containing a special character such as ., that character needs to be preceded by \:
root@debian8:~# grep '^\.' /tmp/greptest .fenestros .fe
root@ubuntu1604:~# grep '^\.' /tmp/greptest .fenestros .fe
[root@centos7 ~]# grep '^\.' /tmp/greptest .fenestros .fe
SLES12SP1:~ # grep '^\.' /tmp/greptest .fenestros .fe
The grep command can also be used to search for a string in all the files within a specific directory as follows grep -rnw 'directory' -e “pattern”. You can also search only within certain files by specifying the files extensions: grep –include={*.doc,*.xls} -rnw 'directory' -e “pattern”. Finally you can exclude certain file extensions as follows: grep –exclude=*.doc -rnw 'directory' -e “pattern”.
Download the following file by clicking on it's title:
- greptest
# Starting comment fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
Move the file to the /tmp directory:
root@debian8:~# mv /home/trainee/Downloads/greptest /tmp/greptest
root@ubuntu1604:~# mv /home/trainee/Downloads/greptest /tmp/greptest
[root@centos7 ~]# mv /home/trainee/Downloads/greptest /tmp/greptest
SLES12SP1:~ # mv /home/trainee/Downloads/greptest /tmp/greptest
Now use the grep command with the -E switch to remove all the comments and empty lines:
root@debian8:~# grep -E -v '^(#|$)' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
root@ubuntu1604:~# grep -E -v '^(#|$)' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
[root@centos7 ~]# grep -E -v '^(#|$)' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
SLES12SP1:~ # grep -E -v '^(#|$)' /tmp/greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
The expression '^(#|$)' matches all lines beginning with the # character OR all lines with zero characters between the start and the end of the line.
Now use the egrep command to do the same thing, this time redirecting the output to the file /tmp/greptest1:
root@debian8:~# egrep -v '^(#|$)' /tmp/greptest > /tmp/greptest1 root@debian8:~# cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
root@ubuntu1604:~# egrep -v '^(#|$)' /tmp/greptest > /tmp/greptest1 root@ubuntu1604:~# cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
[root@centos7 ~]# egrep -v '^(#|$)' /tmp/greptest > /tmp/greptest1 [root@centos7 ~]# cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
SLES12SP1:~ # egrep -v '^(#|$)' /tmp/greptest > /tmp/greptest1 SLES12SP1:~ # cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
Important: The above command is very useful when you want to quickly ascertain which directives are active in a very long configuration file.
Download the following file by clicking on it's title:
- greptest
# Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
Move the file to the /tmp directory:
root@debian8:~# mv /home/trainee/Downloads/greptest /tmp/greptest
root@ubuntu1604:~# mv /home/trainee/Downloads/greptest /tmp/greptest
[root@centos7 ~]# mv /home/trainee/Downloads/greptest /tmp/greptest
SLES12SP1:~ # mv /home/trainee/Downloads/greptest /tmp/greptest
Now use fgrep to match the line starting with the ^ character:
root@debian8:~# fgrep '^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
root@ubuntu1604:~# fgrep '^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
[root@centos7 ~]# fgrep '^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
SLES12SP1:~ # fgrep '^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
Compare the above output to that when using the grep command:
root@debian8:~# grep '^' /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
root@ubuntu1604:~# grep '^' /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
[root@centos7 ~]# grep '^' /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
SLES12SP1:~ # grep '^' /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
As you can see, grep matched every line that had a beginning. In order to get the same result as the grep command, you need to use the following command:
root@debian8:~# grep '^\^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
root@ubuntu1604:~# grep '^\^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
[root@centos7 ~]# grep '^\^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
SLES12SP1:~ # grep '^\^' /tmp/greptest ^ This line will be used to demonstrate the use of fgrep
The Stream EDitor SED
sed is an abbreviation of Stream EDitor and is a non-interactive text editor. sed's basic syntax is as follows:
sed [address] command [arguments] file
The specified commands are applied to each line in the file unless an address is specified. Sed prints all results to standard output and does not modify the source file. The address therefore specifies which lines are concerned by the command.
sed's addresses are as follows:
address | Matching lines |
---|---|
x | Line number x |
$ | The last line of the file |
/BRE/ | Lines matching the specified BRE |
x,y | From line x to line y |
/ERb1/, /ERb2/ | All lines from the first line that matches the first BRE to the first line that matches the second BRE |
sed's commands are as follows:
command | Description |
---|---|
d | Do not show the matching line(s) on standard output |
p | Show the matching line(s) on standard output |
s | Do a substitution upon match |
w | Write the matching line(s) to a file |
= | Print the matching line's number |
! | Exclude the line(s) matching the address |
Command Line Switches
To do : Use the –help option of the fgrep command to view the command line switches.
LAB #2 - Using sed
Start by displaying the contents of the file /etc/services whilst inhibiting the display of the first 10 lines:
root@debian8:~# sed '1,10d' /etc/services | more # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp 21/tcp fsp 21/udp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp telnet 23/tcp smtp 25/tcp mail --More--
root@ubuntu1604:~# sed '1,10d' /etc/services | more # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp 21/tcp fsp 21/udp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp telnet 23/tcp smtp 25/tcp mail --More--
[root@centos7 ~]# sed '1,10d' /etc/services | more # are included, only the more common ones. # # The latest IANA port assignments can be gotten from # http://www.iana.org/assignments/port-numbers # The Well Known Ports are those from 0 through 1023. # The Registered Ports are those from 1024 through 49151 # The Dynamic and/or Private Ports are those from 49152 through 65535 # # Each line describes one service, and is of the form: # # service-name port/protocol [aliases ...] [# comment] tcpmux 1/tcp # TCP port service multiplexer tcpmux 1/udp # TCP port service multiplexer rje 5/tcp # Remote Job Entry rje 5/udp # Remote Job Entry echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users systat 11/udp users daytime 13/tcp --More--
SLES12SP1:~ # sed '1,10d' /etc/services | more # See also: services(5) # # # SERVICE NAME AND TRANSPORT PROTOCOL PORT NUMBER REGISTRY # # (last updated on 2011-11-23) # # ************************************************************************ # * Since we merged and converted this registry it loads more slowly. We * # * know it should load faster and are working on ways to achieve that. * # * Thank you for your patience. * # ************************************************************************ # # Service names and port numbers are used to distinguish between different # services that run over transport protocols such as TCP, UDP, DCCP, and # SCTP. # # Service names are assigned on a first-come, first-served process, as # documented in [RFC6335]. # # Port numbers are assigned in various ways, based on three ranges: System # Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private # Ports (49152-65535); the difference uses of these ranges is described in --More--
Now display the same file without any commented lines:
root@debian8:~# sed '/^#/d' /etc/services | more tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp 21/tcp fsp 21/udp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp telnet 23/tcp smtp 25/tcp mail time 37/tcp timserver --More--
root@ubuntu1604:~# sed '/^#/d' /etc/services | more tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp 21/tcp fsp 21/udp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp telnet 23/tcp smtp 25/tcp mail time 37/tcp timserver --More--
[root@centos7 ~]# sed '/^#/d' /etc/services | more tcpmux 1/tcp # TCP port service multiplexer tcpmux 1/udp # TCP port service multiplexer rje 5/tcp # Remote Job Entry rje 5/udp # Remote Job Entry echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users systat 11/udp users daytime 13/tcp daytime 13/udp qotd 17/tcp quote qotd 17/udp quote msp 18/tcp # message send protocol msp 18/udp # message send protocol chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp-data 20/udp ftp 21/tcp ftp 21/udp fsp fspd --More--
SLES12SP1:~ # sed '/^#/d' /etc/services | more tcpmux 1/tcp # TCP Port Service Multiplexer [Mark_Lottor] tcpmux 1/udp # TCP Port Service Multiplexer [Mark_Lottor] compressnet 2/tcp # Management Utility compressnet 2/udp # Management Utility compressnet 3/tcp # Compression Process [Bernie_Volz] compressnet 3/udp # Compression Process [Bernie_Volz] rje 5/tcp # Remote Job Entry [Jon_Postel] rje 5/udp # Remote Job Entry [Jon_Postel] echo 7/tcp # Echo [Jon_Postel] echo 7/udp # Echo [Jon_Postel] discard 9/tcp # Discard [Jon_Postel] discard 9/udp # Discard [Jon_Postel] discard 9/sctp # Discard [Randall_Stewart] [RFC4960] discard 9/dccp # Discard [Eddie_Kohler] [RFC4340] systat 11/tcp # Active Users [Jon_Postel] systat 11/udp # Active Users [Jon_Postel] daytime 13/tcp # Daytime [RFC867] [Jon_Postel] daytime 13/udp # Daytime [RFC867] [Jon_Postel] qotd 17/tcp # Quote of the Day [Jon_Postel] qotd 17/udp # Quote of the Day [Jon_Postel] msp 18/tcp # Message Send Protocol (historic) [Rina_Nethan iel] msp 18/udp # Message Send Protocol (historic) [Rina_Nethan --More--
Important: Note that the BRE is preceeded and followed by the / character.
Continue by trying to just display the first two lines of /etc/passwd:
root@debian8:~# sed '1,2p' /etc/passwd root:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin ...
root@ubuntu1604:~# sed '1,2p' /etc/passwd root:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync ...
[root@centos7 ~]# sed '1,2p' /etc/passwd root:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin ...
SLES12SP1:~ # sed '1,2p' /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false ...
Important: As you can see in the above output, the command used displays not only the first two lines but also the entire file. As a result the first two lines are displayed twice.
To force sed to only display the lines you specify, use the -n switch:
root@debian8:~# sed -n '1,2p' /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
root@ubuntu1604:~# sed -n '1,2p' /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
[root@centos7 ~]# sed -n '1,2p' /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin
SLES12SP1:~ # sed -n '1,2p' /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash
Now you want to use sed to strip out the comments from /etc/services and save the result to /tmp/sedtest without displaying anything on standard output:
root@debian8:~# sed -n '/^#/!w /tmp/sedtest' /etc/services root@debian8:~# more /tmp/sedtest tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp 21/tcp fsp 21/udp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp telnet 23/tcp smtp 25/tcp mail time 37/tcp timserver --More--(2%)
root@ubuntu1604:~# sed -n '/^#/!w /tmp/sedtest' /etc/services root@ubuntu1604:~# more /tmp/sedtest tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp 21/tcp fsp 21/udp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp telnet 23/tcp smtp 25/tcp mail time 37/tcp timserver --More--(2%)
[root@centos7 ~]# sed -n '/^#/!w /tmp/sedtest' /etc/services [root@centos7 ~]# more /tmp/sedtest tcpmux 1/tcp # TCP port service multiplexer tcpmux 1/udp # TCP port service multiplexer rje 5/tcp # Remote Job Entry rje 5/udp # Remote Job Entry echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users systat 11/udp users daytime 13/tcp daytime 13/udp qotd 17/tcp quote qotd 17/udp quote msp 18/tcp # message send protocol msp 18/udp # message send protocol chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp-data 20/udp ftp 21/tcp ftp 21/udp fsp fspd --More--(0%)
SLES12SP1:~ # sed -n '/^#/!w /tmp/sedtest' /etc/services SLES12SP1:~ # more /tmp/sedtest tcpmux 1/tcp # TCP Port Service Multiplexer [Mark_Lottor] tcpmux 1/udp # TCP Port Service Multiplexer [Mark_Lottor] compressnet 2/tcp # Management Utility compressnet 2/udp # Management Utility compressnet 3/tcp # Compression Process [Bernie_Volz] compressnet 3/udp # Compression Process [Bernie_Volz] rje 5/tcp # Remote Job Entry [Jon_Postel] rje 5/udp # Remote Job Entry [Jon_Postel] echo 7/tcp # Echo [Jon_Postel] echo 7/udp # Echo [Jon_Postel] discard 9/tcp # Discard [Jon_Postel] discard 9/udp # Discard [Jon_Postel] discard 9/sctp # Discard [Randall_Stewart] [RFC4960] discard 9/dccp # Discard [Eddie_Kohler] [RFC4340] systat 11/tcp # Active Users [Jon_Postel] systat 11/udp # Active Users [Jon_Postel] daytime 13/tcp # Daytime [RFC867] [Jon_Postel] daytime 13/udp # Daytime [RFC867] [Jon_Postel] qotd 17/tcp # Quote of the Day [Jon_Postel] qotd 17/udp # Quote of the Day [Jon_Postel] msp 18/tcp # Message Send Protocol (historic) [Rina_Nethan iel] msp 18/udp # Message Send Protocol (historic) [Rina_Nethan --More--(0%)
Important: In the above command, we start by matching all lines in the /etc/services file that start with a #. We then tell sed to write all non-matching lines to the file /tmp/sedtest.
Finally, create a file containing user1,user2,user3. Replace the commas by spaces:
root@debian8:~# echo "user1,user2,user3" > /tmp/sedtest1 root@debian8:~# cat /tmp/sedtest1 | sed 's/,/ /g' user1 user2 user3
root@ubuntu1604:~# echo "user1,user2,user3" > /tmp/sedtest1 root@ubuntu1604:~# cat /tmp/sedtest1 | sed 's/,/ /g' user1 user2 user3
[root@centos7 ~]# echo "user1,user2,user3" > /tmp/sedtest1 [root@centos7 ~]# cat /tmp/sedtest1 | sed 's/,/ /g' user1 user2 user3
SLES12SP1:~ # echo "user1,user2,user3" > /tmp/sedtest1 SLES12SP1:~ # cat /tmp/sedtest1 | sed 's/,/ /g' user1 user2 user3
Important: The above sed command has the following format s/what is to be replaced (character, string or BRE)/replacement/g. The use of the g character forces sed to replace all occurences that match. If g is not stipulated, only the first matching occurence is replaced.
The Text Processor AWK
Presentation
The awk command acts as a filter and uses the following syntax:
awk [-F seperator] '[condition] {action}' [file]
Field Separation
A file or a text stream is treated by awk as a sequence of records. By default each line is a record. Awk analyzes each record, separating that record into fields and then storing the record and fields in variables:
- $0 contains the record,
- $1 contains the first field,
- $2 contains the second field,
- e.t.c.
Awk interprets a space as a separator between fields unless a different separator is specified with the -F option.
Awk then checks if the condition is met for each record and if so, executes the action.
For example, the following command takes the standard output of ls -l and prints fields 8, 3 and 4 to standard output:
root@debian8:~# ls -l | awk '{print $8 $3 $4}' 2016rootroot 2016rootroot 2016rootroot 2016rootroot 2016rootroot
root@ubuntu1604:~# ls -l | awk '{print $8 $3 $4}' 10:40rootroot 2016rootroot 2016rootroot
[root@centos7 ~]# ls -l | awk '{print $8 $3 $4}' 2015rootroot 19:09270users 2015rootroot 2015rootroot
SLES12SP1:~ # ls -l | awk '{print $8 $3 $4}' 06:55traineeusers 06:55traineeusers 06:55traineeusers 09:04traineeusers 15:41traineeusers 2016traineeusers 2016traineeusers 14:00traineeusers 15:59traineeusers 16:16traineeusers 16:16traineeusers 17:00traineeusers 16:14traineeusers 2016traineeusers 2016traineeusers 2016traineeusers 2016traineeusers 2016traineeusers 15:46traineeusers 03:59traineeusers 2016traineeusers 10:27traineeusers 06:55traineeusers
Since there is no condition, the action is applied to every record.
To make the output easier to read, you can include spaces between each field:
root@debian8:~# ls -l | awk '{print $8 " " $3 " " $4}' 2016 root root 2016 root root 2016 root root 2016 root root 2016 root root
root@ubuntu1604:~# ls -l | awk '{print $8 " " $3 " " $4}' 10:40 root root 2016 root root 2016 root root
[root@centos7 ~]# ls -l | awk '{print $8 " " $3 " " $4}' 2015 root root 19:09 270 users 2015 root root 2015 root root
SLES12SP1:~ # ls -l | awk '{print $8 " " $3 " " $4}' 06:55 trainee users 06:55 trainee users 06:55 trainee users 09:04 trainee users 15:41 trainee users 2016 trainee users 2016 trainee users 14:00 trainee users 15:59 trainee users 16:16 trainee users 16:16 trainee users 17:00 trainee users 16:14 trainee users 2016 trainee users 2016 trainee users 2016 trainee users 2016 trainee users 2016 trainee users 15:46 trainee users 03:59 trainee users 2016 trainee users 10:27 trainee users 06:55 trainee users
Conditions
A regular expression applied to a record
- Format:
- /regular expression/ {action}
- Exemple:
- /hello/ {print $0}
A regular expression applied to a field
- Format:
- $n ~/regular expression/ {action}
- $n!~/regular expression/ {action}
- Examples:
- $1 ~/hello/ {print $0}
- $1!~/hello/ {print $0}
Comparisons
- Format:
- $n operator criteria {action}
- Example:
- $1 > 20 {print $0}
Operators
Operator | Condition |
---|---|
< | Less than |
⇐ | Less than or equal to |
== | Equal to |
!= | Different |
> | Greater than |
>= | Greater than or equal to |
Logical Operators
- Format:
- test1 logical operator test2 {action}
- Example:
- $1 ~/hello/ && $2 > 20 {print $0}
Operators
Operator | Condition |
---|---|
|| | OR |
&& | AND |
! | NO |
Built-in Variables
- Format:
- expression1, expression2 {instruction}
- Example:
- NR==7, NR==10 {print $0}
Variables
Variable | Description |
---|---|
NR | Total number of records |
NF | Total number of fields |
FILENAME | Name of current input file |
FS | The field separator, by default a space or tab |
RS | The record separator, by default newline |
OFS | Output field separator, by default a space |
ORS | Output record separator, by default newline |
OFMT | Numeric output format, by default“%.6g” |
Awk Scripts
To combine several clauses composed of conditions and actions in the same statement, it is advisable to create an awk script. Awk scripts are comprised of three sections:
- BEGIN
- This section is executed once, prior to executing the body of the script
- BODY
- This sections contains the clauses to be applied to each line
- END
- This section is executed once, after executing the body of the script
For example:
root@debian8:~# cat > awkscript BEGIN { print "List of the currently mounted file systems"} {print $0} END { print "=========================================="} [^D]
root@ubuntu1604:~# cat > awkscript BEGIN { print "List of the currently mounted file systems"} {print $0} END { print "=========================================="} [^D]
[root@centos7 ~]# cat > awkscript BEGIN { print "List of the currently mounted file systems"} {print $0} END { print "=========================================="} [^D]
SLES12SP1:~ # cat > awkscript BEGIN { print "List of the currently mounted file systems"} {print $0} END { print "=========================================="} [^D]
Now apply the awk script to /etc/fstab :
root@debian8:~# awk -f awkscript /etc/fstab List of the currently mounted file systems # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda1 during installation UUID=4a230056-285f-42f4-bfe0-5a73dbc5b745 / ext4 errors=remount-ro 0 1 # swap was on /dev/sda5 during installation UUID=da5a77e9-344d-42aa-aed6-a38d381ba436 none swap sw 0 0 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0 ==========================================
root@ubuntu1604:~# awk -f awkscript /etc/fstab List of the currently mounted file systems # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda1 during installation UUID=c27fce7f-cc8a-4c6f-b19b-d929a4d570f2 / ext4 errors=remount-ro 0 1 # swap was on /dev/sda5 during installation UUID=68f67549-63f1-4833-b792-3566455bbe95 none swap sw 0 0 ==========================================
[root@centos7 tmp]# awk -f awkscript /etc/fstab Liste des systèmes de fichiers montés # # /etc/fstab # Created by anaconda on Sun Mar 8 12:38:10 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=b35de665-5ec8-4226-a533-58a1b567ac91 / xfs defaults 1 1 UUID=e8d3bd48-1386-411c-9675-41c3f8f1a309 /boot xfs defaults 1 2 UUID=11a4d11d-81e4-46a7-82e0-7796cd597dc9 swap swap defaults 0 0 =====================================
SLES12SP1:~ # awk -f awkscript /etc/fstab List of the currently mounted file systems UUID=9e0e4497-5e47-419a-8ff4-9e2dd7d6a11b swap swap defaults 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 / btrfs defaults 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /boot/grub2/i386-pc btrfs subvol=@/boot/grub2/i386-pc 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /boot/grub2/x86_64-efi btrfs subvol=@/boot/grub2/x86_64-efi 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /home btrfs subvol=@/home 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /opt btrfs subvol=@/opt 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /srv btrfs subvol=@/srv 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /tmp btrfs subvol=@/tmp 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /usr/local btrfs subvol=@/usr/local 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/crash btrfs subvol=@/var/crash 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/lib/libvirt/images btrfs subvol=@/var/lib/libvirt/images 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/lib/mailman btrfs subvol=@/var/lib/mailman 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/lib/mariadb btrfs subvol=@/var/lib/mariadb 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/lib/mysql btrfs subvol=@/var/lib/mysql 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/lib/named btrfs subvol=@/var/lib/named 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/lib/pgsql btrfs subvol=@/var/lib/pgsql 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/log btrfs subvol=@/var/log 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/opt btrfs subvol=@/var/opt 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/spool btrfs subvol=@/var/spool 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /var/tmp btrfs subvol=@/var/tmp 0 0 UUID=65337196-2d6b-4c8b-b917-30c3867bf265 /.snapshots btrfs subvol=@/.snapshots 0 0 ==========================================
Important: Note the use of the -f switch which instructs awk to use the script.
The printf function
The integrated function printf is used to format output and has the following syntax:
printf ("string",expression1,expression2,...,expressionn)
string contains as many formats as there are expressions.
Examples of formats commonly used are:
Format | Description |
---|---|
%30s | Displays a right-justified string of 30 characters |
%-30s | Displays a left-justified string of 30 characters |
%4d | Displays a right-justified decimal number of 4 digits |
%-4d | Displays a left-justified decimal number of 4 digits |
Control Statements
awk can use the following control statements:
if
if condition { command command ... } else { command command ... }
or:
if condition command else command
for
for variable in list { command command ... }
or:
for variable in list command
or in the case of a table:
for key in table { print key , table[key] }
while
while condition { command command ... }
do-while
do { command command ... } while condition
Command Line Switches
To do : Use the –help option of the awk command to view the command line switches.
LAB #3 - Using awk
Download the file sales.txt by clicking on the title below:
- sales
# FenestrOs.com # Annual sales by French department # 83 Desktops§100 Portables§50 Servers§21 Ipads§4 # 06 Desktops§99 Portables§60 Servers§8 Ipads§16 # 13 Desktops§130 Portables§65 Servers§12 Ipads§56
Now download the awk script sales.awk by clicking on the title below:
- sales.awk
# BEGIN BEGIN { FS="§" } # TABLE $1 !~ /^#/ && $1 !~ /^$/ { sales[$1]+=$2 } # END END { for (pc in sales) printf("PC Type : %s \t Sales (06+13+83) : %10d\n",pc,sales[pc]); }
This script contains 13 lines. The purpose of this script is to calculate the total number of computers sold in the three French departments from the data present in the sales file:
1 # BEGIN 2 BEGIN { 3 FS="§" 4 } 5 # TABLE 6 $1 !~ /^#/ && $1 !~ /^$/ { 7 sales[$1]+=$2 8 } 9 # END 10 END { 11 for (pc in sales) 12 printf("PC Type : %s \t Sales (06+13+83) : %10d\n",pc,sales[pc]); 13 }
It is important that you understand the key lines in the above script:
- Line 3,
- Defines a new field seperator in a BEGIN section.
- Line 6,
- Discards all commented and empty lines.
- Line 7,
- The table's key is $1, in other words the different types of computers. Against each key, the number of each type of computer sold is stored in $2. The += characters indicate that the value stored in $2 is incremental.
- Line 12,
- Uses printf to format the output of each line in the table.
Now execute the script and check the output is correct:
root@debian8:~# awk -f /home/trainee/Downloads/sales.awk /home/trainee/Downloads/sales.txt PC Type : Portables Sales (06+13+83) : 175 PC Type : Ipads Sales (06+13+83) : 76 PC Type : Desktops Sales (06+13+83) : 329 PC Type : Servers Sales (06+13+83) : 41
root@ubuntu1604:~# awk -f /home/trainee/Downloads/sales.awk /home/trainee/Downloads/sales.txt PC Type : Servers Sales (06+13+83) : 41 PC Type : Portables Sales (06+13+83) : 175 PC Type : Ipads Sales (06+13+83) : 76 PC Type : Desktops Sales (06+13+83) : 329
[root@centos7 ~]# awk -f /home/trainee/Downloads/sales.awk /home/trainee/Downloads/sales.txt PC Type : Portables Sales (06+13+83) : 175 PC Type : Ipads Sales (06+13+83) : 76 PC Type : Desktops Sales (06+13+83) : 329 PC Type : Servers Sales (06+13+83) : 41
SLES12SP1:~ # awk -f /home/trainee/Downloads/sales.awk /home/trainee/Downloads/sales.txt PC Type : Portables Sales (06+13+83) : 175 PC Type : Ipads Sales (06+13+83) : 76 PC Type : Desktops Sales (06+13+83) : 329 PC Type : Servers Sales (06+13+83) : 41
Other Useful Commands
The expand Command
The expand command converts tabulations in a file to spaces and prints the results to STDOUT. With no file as an argument or with the - character as an argument, the command takes it's input from STDIN.
Download the following file:
- expand
un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq
Move the file to the /root folder:
root@debian8:~# mv /home/trainee/Downloads/expand.txt /root/expand
root@ubuntu1604:~# mv /home/trainee/Downloads/expand.txt /root/expand
[root@centos7 ~]# mv /home/trainee/Downloads/expand.txt /root/expand
SLES12SP1:~ # mv /home/trainee/Downloads/expand.txt /root/expand
Use the cat command to view the contents of the file:
root@debian8:~# cat expand un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq
root@ubuntu1604:~# cat expand un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq
[root@centos7 ~]# cat expand un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq
SLES12SP1:~ # cat expand un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq un deux trois quatre cinq
Now use the -vet switches of the cat command to view the non-printable characters:
root@debian8:~# cat -vet expand un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
root@ubuntu1604:~# cat -vet expand un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
[root@centos7 ~]# cat -vet expand un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
SLES12SP1:~ # cat -vet expand un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
Important : As you can see the tabulations are shown as ^I and the end of each line as a $.
Now use the expand command to convert the tabulations into spaces and send the result to the expand1 file:
root@debian8:~# expand expand > expand1
root@ubuntu1604:~# expand expand > expand1
[root@centos7 ~]# expand expand > expand1
SLES12SP1:~ # expand expand > expand1
View the resulting expand1 file with the cat command and the -vet switches:
root@debian8:~# cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$
root@ubuntu1604:~# cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$
[root@centos7 ~]# cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$
SLES12SP1:~ # cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$
Important : As you can see, the tabulations have been changed into spaces.
Command Line Switches
To do : Use the –help option of the expand command to view the command line switches.
La Commande unexpand
The expand command converts spaces in a file to tabulations and prints the results to STDOUT. With no file as an argument or with the - character as an argument, the command takes it's input from STDIN.
Now use the expand command to convert the spaces in the expand1 file into tabulations and send the result to the expand2 file:
root@debian8:~# cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ root@debian8:~# unexpand -a expand1 > expand2 root@debian8:~# cat -vet expand2 un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
root@ubuntu1604:~# cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ root@ubuntu1604:~# unexpand -a expand1 > expand2 root@ubuntu1604:~# cat -vet expand2 un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
[root@centos7 ~]# cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ [root@centos7 ~]# unexpand -a expand1 > expand2 [root@centos7 ~]# cat -vet expand2 un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
SLES12SP1:~ # cat -vet expand1 un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ un deux trois quatre cinq$ SLES12SP1:~ # unexpand -a expand1 > expand2 SLES12SP1:~ # cat -vet expand2 un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$ un^Ideux^Itrois^Iquatre^Icinq$
Important : Note that the spaces have been replaced by tabulations.
Command Line Switches
To do : Use the –help option of the unexpand command to view the command line switches.
The cut command
The cut command splits each line of a file into columns starting with column 1. Each column contains one character. The command can also be used to split lines into fields where the default seperator is a tablulation. The default seperator can be changed by using the -d switch.
Select the first 7 columns of the /etc/passwd file:
root@debian8:~# cut -c1-7 /etc/passwd root:x: daemon: bin:x:2 sys:x:3 sync:x: games:x man:x:6 lp:x:7: mail:x: news:x: uucp:x: proxy:x www-dat backup: list:x: irc:x:3 gnats:x nobody: systemd systemd systemd systemd trainee sshd:x: Debian- message statd:x avahi-a avahi:x colord: dnsmasq speech- pulse:x rtkit:x saned:x usbmux: lightdm
root@ubuntu1604:~# cut -c1-7 /etc/passwd root:x: daemon: bin:x:2 sys:x:3 sync:x: games:x man:x:6 lp:x:7: mail:x: news:x: uucp:x: proxy:x www-dat backup: list:x: irc:x:3 gnats:x nobody: systemd systemd systemd systemd syslog: _apt:x: message uuidd:x lightdm whoopsi avahi-a avahi:x dnsmasq colord: speech- hplip:x kernoop pulse:x rtkit:x saned:x usbmux: trainee sshd:x:
[root@centos7 ~]# cut -c1-7 /etc/passwd root:x: bin:x:1 daemon: adm:x:3 lp:x:4: sync:x: shutdow halt:x: mail:x: operato games:x ftp:x:1 nobody: dbus:x: polkitd unbound colord: usbmuxd avahi:x avahi-a saslaut qemu:x: libstor rpc:x:3 rpcuser nfsnobo rtkit:x radvd:x ntp:x:3 chrony: abrt:x: pulse:x gdm:x:4 gnome-i postfix sshd:x: tcpdump trainee vboxadd tss:x:5
SLES12SP1:~ # cut -c1-7 /etc/passwd at:x:25 bin:x:1 daemon: ftp:x:4 ftpsecu games:x gdm:x:4 lp:x:4: mail:x: man:x:1 message news:x: nobody: nscd:x: ntp:x:7 openslp polkitd postfix pulse:x root:x: rpc:x:4 rtkit:x scard:x sshd:x: statd:x usbmux: uucp:x: vnc:x:4 wwwrun: trainee
In order to select columns 1 to 5, columns 10 to 15 and columns 30 and higher, us the following command:
root@debian8:~# cut -c1-5,10-15,30- /etc/passwd root:0:rootsh daemo1:1:da:/usr/sbin/nologin bin:x:bin:/nologin sys:x:sys:/nologin sync:65534:/sync games:60:ga:/usr/sbin/nologin man:x2:man::/usr/sbin/nologin lp:x:lp:/vasr/sbin/nologin mail:8:mailr/sbin/nologin news:9:newsws:/usr/sbin/nologin uucp::10:uuuucp:/usr/sbin/nologin proxy3:13:p/sbin/nologin www-dx:33:3r/www:/usr/sbin/nologin backu34:34:ckups:/usr/sbin/nologin list::38:Maager:/var/list:/usr/sbin/nologin irc:x39:ircd:/usr/sbin/nologin gnats1:41:Gting System (admin):/var/lib/gnats:/usr/sbin/nologin nobod65534:nonexistent:/usr/sbin/nologin systeimesynstemd Time Synchronization,,,:/run/systemd:/bin/false systeetworktemd Network Management,,,:/run/systemd/netif:/bin/false systeesolvetemd Resolver,,,:/run/systemd/resolve:/bin/false systeus-proystemd Bus Proxy,,,:/run/systemd:/bin/false train:1000:,:/home/trainee:/bin/bash sshd:4:6553hd:/usr/sbin/nologin Debiaim:x:1pool/exim4:/bin/false messas:x:10n/dbus:/bin/false statd07:655fs:/bin/false avahioipd:x autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi09:115emon,,,:/var/run/avahi-daemon:/bin/false color110:11r management daemon,,,:/var/lib/colord:/bin/false dnsma:111:6,:/var/lib/misc:/bin/false speecspatcheech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse13:119emon,,,:/var/run/pulse:/bin/false rtkit14:121,:/proc:/bin/false saned15:122ed:/bin/false usbmu116:46,,,:/var/lib/usbmux:/bin/false light:117:1ay Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:~# cut -c1-5,10-15,30- /etc/passwd root:0:rootsh daemo1:1:da:/usr/sbin/nologin bin:x:bin:/nologin sys:x:sys:/nologin sync:65534:/sync games:60:ga:/usr/sbin/nologin man:x2:man::/usr/sbin/nologin lp:x:lp:/vasr/sbin/nologin mail:8:mailr/sbin/nologin news:9:newsws:/usr/sbin/nologin uucp::10:uuuucp:/usr/sbin/nologin proxy3:13:p/sbin/nologin www-dx:33:3r/www:/usr/sbin/nologin backu34:34:ckups:/usr/sbin/nologin list::38:Maager:/var/list:/usr/sbin/nologin irc:x39:ircd:/usr/sbin/nologin gnats1:41:Gting System (admin):/var/lib/gnats:/usr/sbin/nologin nobod65534:nonexistent:/usr/sbin/nologin systeimesynstemd Time Synchronization,,,:/run/systemd:/bin/false systeetworktemd Network Management,,,:/run/systemd/netif:/bin/false systeesolvetemd Resolver,,,:/run/systemd/resolve:/bin/false systeus-proystemd Bus Proxy,,,:/run/systemd:/bin/false syslo104:10g:/bin/false _apt:5:6553t:/bin/false messas:x:10n/dbus:/bin/false uuidd07:111bin/false light:108:1ay Manager:/var/lib/lightdm:/bin/false whoopx:109:ent:/bin/false avahioipd:x autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi11:120emon,,,:/var/run/avahi-daemon:/bin/false dnsma:112:6,:/var/lib/misc:/bin/false color113:12r management daemon,,,:/var/lib/colord:/bin/false speecspatcheech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip15:7:Her,,,:/var/run/hplip:/bin/false kernox:116:ops Tracking Daemon,,,:/:/bin/false pulse17:124emon,,,:/var/run/pulse:/bin/false rtkit18:126,:/proc:/bin/false saned19:127ed:/bin/false usbmu120:46,,,:/var/lib/usbmux:/bin/false train:1000:,:/home/trainee:/bin/bash sshd:1:6553hd:/usr/sbin/nologin
[root@centos7 ~]# cut -c1-5,10-15,30- /etc/passwd root:0:rootsh bin:x:bin:/gin daemo2:2:dain/nologin adm:x:adm:/nologin lp:x:lp:/vabin/nologin sync:0:syncnc shutdx:6:0::/sbin/shutdown halt:0:haltalt mail:12:maiail:/sbin/nologin operax:11:0t:/sbin/nologin games2:100:es:/sbin/nologin ftp:x50:FTP:/sbin/nologin nobod99:99:/nologin dbus::81:Syus:/:/sbin/nologin polki:999:9lkitd:/:/sbin/nologin unbou:998:9 resolver:/etc/unbound:/sbin/nologin color997:99ord:/var/lib/colord:/sbin/nologin usbmu:113:1r:/:/sbin/nologin avahi0:70:ASD Stack:/var/run/avahi-daemon:/sbin/nologin avahioipd:x IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin saslax:996:user":/run/saslauthd:/sbin/nologin qemu:7:107:bin/nologin libstemgmt:on account for libstoragemgmt:/var/run/lsm:/sbin/nologin rpc:x32:Rpcar/lib/rpcbind:/sbin/nologin rpcus:29:29ser:/var/lib/nfs:/sbin/nologin nfsno:x:655mous NFS User:/var/lib/nfs:/sbin/nologin rtkit72:172proc:/sbin/nologin radvd5:75:rbin/nologin ntp:x38::/eologin chron994:99rony:/sbin/nologin abrt:3:173:in/nologin pulse71:171stem Daemon:/var/run/pulse:/sbin/nologin gdm:x42::/vin/nologin gnometial-s::/run/gnome-initial-setup/:/sbin/nologin postf:89:89ostfix:/sbin/nologin sshd::74:Prted SSH:/var/empty/sshd:/sbin/nologin tcpdu:72:72gin train:1000:home/trainee:/bin/bash vboxa:992:1xadd:/bin/false tss:x59:Acche trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:~ # cut -c1-5,10-15,30- /etc/passwd at:x:5:Batc/var/spool/atjobs:/bin/bash bin:x:bin:/ daemo2:2:Dan/bash ftp:x49:FTPftp:/bin/bash ftpse:x:488FTP User:/var/lib/empty:/bin/false games2:100:/var/games:/bin/bash gdm:x:485:Ganager daemon:/var/lib/gdm:/bin/false lp:x:Printi/spool/lpd:/bin/bash mail:12:Mair/spool/clientmqueue:/bin/false man:x62:Maner:/var/cache/man:/bin/bash messas:x:49 D-Bus:/var/run/dbus:/bin/false news:13:Newnews:/bin/bash nobod65534:var/lib/nobody:/bin/bash nscd:6:495:/run/nscd:/sbin/nologin ntp:x492:NTlib/ntp:/bin/false opens:494:2n:/var/lib/empty:/sbin/nologin polki:497:4lkitd:/var/lib/polkit:/sbin/nologin postf:51:51n:/var/spool/postfix:/bin/false pulse90:489emon:/var/lib/pulseaudio:/sbin/nologin root:0:rootsh rpc:x:65534ind:/var/lib/empty:/sbin/nologin rtkit91:490proc:/bin/false scard87:487ader:/var/run/pcscd:/usr/sbin/nologin sshd:8:498:r/lib/sshd:/bin/false statd89:655aemon:/var/lib/nfs:/sbin/nologin usbmu493:65emon:/var/lib/usbmuxd:/sbin/nologin uucp::14:Uny system:/etc/uucp:/bin/bash vnc:x:491:uar/lib/empty:/sbin/nologin wwwru30:8:Whe:/var/lib/wwwrun:/bin/false train:1000:ome/trainee:/bin/bash
In order to select the 2nd, 4th and 6th column, use the following command:
root@debian8:~# cut -d: -f2,4,6 /etc/passwd x:0:/root x:1:/usr/sbin x:2:/bin x:3:/dev x:65534:/bin x:60:/usr/games x:12:/var/cache/man x:7:/var/spool/lpd x:8:/var/mail x:9:/var/spool/news x:10:/var/spool/uucp x:13:/bin x:33:/var/www x:34:/var/backups x:38:/var/list x:39:/var/run/ircd x:41:/var/lib/gnats x:65534:/nonexistent x:103:/run/systemd x:104:/run/systemd/netif x:105:/run/systemd/resolve x:106:/run/systemd x:1000:/home/trainee x:65534:/var/run/sshd x:110:/var/spool/exim4 x:111:/var/run/dbus x:65534:/var/lib/nfs x:113:/var/lib/avahi-autoipd x:115:/var/run/avahi-daemon x:117:/var/lib/colord x:65534:/var/lib/misc x:29:/var/run/speech-dispatcher x:119:/var/run/pulse x:121:/proc x:122:/var/lib/saned x:46:/var/lib/usbmux x:124:/var/lib/lightdm
root@ubuntu1604:~# cut -d: -f2,4,6 /etc/passwd x:0:/root x:1:/usr/sbin x:2:/bin x:3:/dev x:65534:/bin x:60:/usr/games x:12:/var/cache/man x:7:/var/spool/lpd x:8:/var/mail x:9:/var/spool/news x:10:/var/spool/uucp x:13:/bin x:33:/var/www x:34:/var/backups x:38:/var/list x:39:/var/run/ircd x:41:/var/lib/gnats x:65534:/nonexistent x:102:/run/systemd x:103:/run/systemd/netif x:104:/run/systemd/resolve x:105:/run/systemd x:108:/home/syslog x:65534:/nonexistent x:110:/var/run/dbus x:111:/run/uuidd x:114:/var/lib/lightdm x:116:/nonexistent x:119:/var/lib/avahi-autoipd x:120:/var/run/avahi-daemon x:65534:/var/lib/misc x:123:/var/lib/colord x:29:/var/run/speech-dispatcher x:7:/var/run/hplip x:65534:/ x:124:/var/run/pulse x:126:/proc x:127:/var/lib/saned x:46:/var/lib/usbmux x:1000:/home/trainee x:65534:/var/run/sshd
[root@centos7 ~]# cut -d: -f2,4,6 /etc/passwd x:0:/root x:1:/bin x:2:/sbin x:4:/var/adm x:7:/var/spool/lpd x:0:/sbin x:0:/sbin x:0:/sbin x:12:/var/spool/mail x:0:/root x:100:/usr/games x:50:/var/ftp x:99:/ x:81:/ x:998:/ x:997:/etc/unbound x:996:/var/lib/colord x:113:/ x:70:/var/run/avahi-daemon x:170:/var/lib/avahi-autoipd x:76:/run/saslauthd x:107:/ x:994:/var/run/lsm x:32:/var/lib/rpcbind x:29:/var/lib/nfs x:65534:/var/lib/nfs x:172:/proc x:75:/ x:38:/etc/ntp x:993:/var/lib/chrony x:173:/etc/abrt x:171:/var/run/pulse x:42:/var/lib/gdm x:991:/run/gnome-initial-setup/ x:89:/var/spool/postfix x:74:/var/empty/sshd x:72:/ x:1000:/home/trainee x:1:/var/run/vboxadd x:59:/dev/null
SLES12SP1:~ # cut -d: -f2,4,6 /etc/passwd x:25:/var/spool/atjobs x:1:/bin x:2:/sbin x:49:/srv/ftp x:65534:/var/lib/empty x:100:/var/games x:485:/var/lib/gdm x:7:/var/spool/lpd x:12:/var/spool/clientmqueue x:62:/var/cache/man x:499:/var/run/dbus x:13:/etc/news x:65533:/var/lib/nobody x:495:/run/nscd x:492:/var/lib/ntp x:2:/var/lib/empty x:496:/var/lib/polkit x:51:/var/spool/postfix x:489:/var/lib/pulseaudio x:0:/root x:65534:/var/lib/empty x:490:/proc x:487:/var/run/pcscd x:498:/var/lib/sshd x:65534:/var/lib/nfs x:65534:/var/lib/usbmuxd x:14:/etc/uucp x:491:/var/lib/empty x:8:/var/lib/wwwrun x:100:/home/trainee
Important: Note the use of the -d switch to change the default seperator.
Command Line Switches
To do : Use the –help option of the cut command to view the command line switches.
The uniq Command
The following command is used to extract the Primary Group GIDs from the /etc/passwd file:
root@debian8:~# cut -d: -f4 /etc/passwd | sort -n | uniq 0 1 2 3 7 8 9 10 12 13 29 33 34 38 39 41 46 60 103 104 105 106 110 111 113 115 117 119 121 122 124 1000 65534
root@ubuntu1604:~# cut -d: -f4 /etc/passwd | sort -n | uniq 0 1 2 3 7 8 9 10 12 13 29 33 34 38 39 41 46 60 102 103 104 105 108 110 111 114 116 119 120 123 124 126 127 1000 65534
[root@centos7 ~]# cut -d: -f4 /etc/passwd | sort -n | uniq 0 1 2 4 7 12 29 32 38 42 50 59 70 72 74 75 76 81 89 99 100 107 113 170 171 172 173 991 993 994 996 997 998 1000 65534
SLES12SP1:~ # cut -d: -f4 /etc/passwd | sort -n | uniq 0 1 2 7 8 12 13 14 25 49 51 62 100 485 487 489 490 491 492 495 496 498 499 65533 65534
Important: Note the use of the uniq command to remove duplicates from the list.
Command Line Switches
To do : Use the –help option of the uniq command to view the command line switches.
The tr Command
The tr command is used to substitute certain characters by other characters. This command only accepts data from standard input (hence the pipe):
root@debian8:~# cat /etc/passwd | tr "[a-z]" "[A-Z]" ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH DAEMON:X:1:1:DAEMON:/USR/SBIN:/USR/SBIN/NOLOGIN BIN:X:2:2:BIN:/BIN:/USR/SBIN/NOLOGIN SYS:X:3:3:SYS:/DEV:/USR/SBIN/NOLOGIN SYNC:X:4:65534:SYNC:/BIN:/BIN/SYNC GAMES:X:5:60:GAMES:/USR/GAMES:/USR/SBIN/NOLOGIN MAN:X:6:12:MAN:/VAR/CACHE/MAN:/USR/SBIN/NOLOGIN LP:X:7:7:LP:/VAR/SPOOL/LPD:/USR/SBIN/NOLOGIN MAIL:X:8:8:MAIL:/VAR/MAIL:/USR/SBIN/NOLOGIN NEWS:X:9:9:NEWS:/VAR/SPOOL/NEWS:/USR/SBIN/NOLOGIN UUCP:X:10:10:UUCP:/VAR/SPOOL/UUCP:/USR/SBIN/NOLOGIN PROXY:X:13:13:PROXY:/BIN:/USR/SBIN/NOLOGIN WWW-DATA:X:33:33:WWW-DATA:/VAR/WWW:/USR/SBIN/NOLOGIN BACKUP:X:34:34:BACKUP:/VAR/BACKUPS:/USR/SBIN/NOLOGIN LIST:X:38:38:MAILING LIST MANAGER:/VAR/LIST:/USR/SBIN/NOLOGIN IRC:X:39:39:IRCD:/VAR/RUN/IRCD:/USR/SBIN/NOLOGIN GNATS:X:41:41:GNATS BUG-REPORTING SYSTEM (ADMIN):/VAR/LIB/GNATS:/USR/SBIN/NOLOGIN NOBODY:X:65534:65534:NOBODY:/NONEXISTENT:/USR/SBIN/NOLOGIN SYSTEMD-TIMESYNC:X:100:103:SYSTEMD TIME SYNCHRONIZATION,,,:/RUN/SYSTEMD:/BIN/FALSE SYSTEMD-NETWORK:X:101:104:SYSTEMD NETWORK MANAGEMENT,,,:/RUN/SYSTEMD/NETIF:/BIN/FALSE SYSTEMD-RESOLVE:X:102:105:SYSTEMD RESOLVER,,,:/RUN/SYSTEMD/RESOLVE:/BIN/FALSE SYSTEMD-BUS-PROXY:X:103:106:SYSTEMD BUS PROXY,,,:/RUN/SYSTEMD:/BIN/FALSE TRAINEE:X:1000:1000:TRAINEE,,,:/HOME/TRAINEE:/BIN/BASH SSHD:X:104:65534::/VAR/RUN/SSHD:/USR/SBIN/NOLOGIN DEBIAN-EXIM:X:105:110::/VAR/SPOOL/EXIM4:/BIN/FALSE MESSAGEBUS:X:106:111::/VAR/RUN/DBUS:/BIN/FALSE STATD:X:107:65534::/VAR/LIB/NFS:/BIN/FALSE AVAHI-AUTOIPD:X:108:113:AVAHI AUTOIP DAEMON,,,:/VAR/LIB/AVAHI-AUTOIPD:/BIN/FALSE AVAHI:X:109:115:AVAHI MDNS DAEMON,,,:/VAR/RUN/AVAHI-DAEMON:/BIN/FALSE COLORD:X:110:117:COLORD COLOUR MANAGEMENT DAEMON,,,:/VAR/LIB/COLORD:/BIN/FALSE DNSMASQ:X:111:65534:DNSMASQ,,,:/VAR/LIB/MISC:/BIN/FALSE SPEECH-DISPATCHER:X:112:29:SPEECH DISPATCHER,,,:/VAR/RUN/SPEECH-DISPATCHER:/BIN/SH PULSE:X:113:119:PULSEAUDIO DAEMON,,,:/VAR/RUN/PULSE:/BIN/FALSE RTKIT:X:114:121:REALTIMEKIT,,,:/PROC:/BIN/FALSE SANED:X:115:122::/VAR/LIB/SANED:/BIN/FALSE USBMUX:X:116:46:USBMUX DAEMON,,,:/VAR/LIB/USBMUX:/BIN/FALSE LIGHTDM:X:117:124:LIGHT DISPLAY MANAGER:/VAR/LIB/LIGHTDM:/BIN/FALSE
root@ubuntu1604:~# cat /etc/passwd | tr "[a-z]" "[A-Z]" ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH DAEMON:X:1:1:DAEMON:/USR/SBIN:/USR/SBIN/NOLOGIN BIN:X:2:2:BIN:/BIN:/USR/SBIN/NOLOGIN SYS:X:3:3:SYS:/DEV:/USR/SBIN/NOLOGIN SYNC:X:4:65534:SYNC:/BIN:/BIN/SYNC GAMES:X:5:60:GAMES:/USR/GAMES:/USR/SBIN/NOLOGIN MAN:X:6:12:MAN:/VAR/CACHE/MAN:/USR/SBIN/NOLOGIN LP:X:7:7:LP:/VAR/SPOOL/LPD:/USR/SBIN/NOLOGIN MAIL:X:8:8:MAIL:/VAR/MAIL:/USR/SBIN/NOLOGIN NEWS:X:9:9:NEWS:/VAR/SPOOL/NEWS:/USR/SBIN/NOLOGIN UUCP:X:10:10:UUCP:/VAR/SPOOL/UUCP:/USR/SBIN/NOLOGIN PROXY:X:13:13:PROXY:/BIN:/USR/SBIN/NOLOGIN WWW-DATA:X:33:33:WWW-DATA:/VAR/WWW:/USR/SBIN/NOLOGIN BACKUP:X:34:34:BACKUP:/VAR/BACKUPS:/USR/SBIN/NOLOGIN LIST:X:38:38:MAILING LIST MANAGER:/VAR/LIST:/USR/SBIN/NOLOGIN IRC:X:39:39:IRCD:/VAR/RUN/IRCD:/USR/SBIN/NOLOGIN GNATS:X:41:41:GNATS BUG-REPORTING SYSTEM (ADMIN):/VAR/LIB/GNATS:/USR/SBIN/NOLOGIN NOBODY:X:65534:65534:NOBODY:/NONEXISTENT:/USR/SBIN/NOLOGIN SYSTEMD-TIMESYNC:X:100:102:SYSTEMD TIME SYNCHRONIZATION,,,:/RUN/SYSTEMD:/BIN/FALSE SYSTEMD-NETWORK:X:101:103:SYSTEMD NETWORK MANAGEMENT,,,:/RUN/SYSTEMD/NETIF:/BIN/FALSE SYSTEMD-RESOLVE:X:102:104:SYSTEMD RESOLVER,,,:/RUN/SYSTEMD/RESOLVE:/BIN/FALSE SYSTEMD-BUS-PROXY:X:103:105:SYSTEMD BUS PROXY,,,:/RUN/SYSTEMD:/BIN/FALSE SYSLOG:X:104:108::/HOME/SYSLOG:/BIN/FALSE _APT:X:105:65534::/NONEXISTENT:/BIN/FALSE MESSAGEBUS:X:106:110::/VAR/RUN/DBUS:/BIN/FALSE UUIDD:X:107:111::/RUN/UUIDD:/BIN/FALSE LIGHTDM:X:108:114:LIGHT DISPLAY MANAGER:/VAR/LIB/LIGHTDM:/BIN/FALSE WHOOPSIE:X:109:116::/NONEXISTENT:/BIN/FALSE AVAHI-AUTOIPD:X:110:119:AVAHI AUTOIP DAEMON,,,:/VAR/LIB/AVAHI-AUTOIPD:/BIN/FALSE AVAHI:X:111:120:AVAHI MDNS DAEMON,,,:/VAR/RUN/AVAHI-DAEMON:/BIN/FALSE DNSMASQ:X:112:65534:DNSMASQ,,,:/VAR/LIB/MISC:/BIN/FALSE COLORD:X:113:123:COLORD COLOUR MANAGEMENT DAEMON,,,:/VAR/LIB/COLORD:/BIN/FALSE SPEECH-DISPATCHER:X:114:29:SPEECH DISPATCHER,,,:/VAR/RUN/SPEECH-DISPATCHER:/BIN/FALSE HPLIP:X:115:7:HPLIP SYSTEM USER,,,:/VAR/RUN/HPLIP:/BIN/FALSE KERNOOPS:X:116:65534:KERNEL OOPS TRACKING DAEMON,,,:/:/BIN/FALSE PULSE:X:117:124:PULSEAUDIO DAEMON,,,:/VAR/RUN/PULSE:/BIN/FALSE RTKIT:X:118:126:REALTIMEKIT,,,:/PROC:/BIN/FALSE SANED:X:119:127::/VAR/LIB/SANED:/BIN/FALSE USBMUX:X:120:46:USBMUX DAEMON,,,:/VAR/LIB/USBMUX:/BIN/FALSE TRAINEE:X:1000:1000:TRAINEE,,,:/HOME/TRAINEE:/BIN/BASH SSHD:X:121:65534::/VAR/RUN/SSHD:/USR/SBIN/NOLOGIN
[root@centos7 ~]# cat /etc/passwd | tr "[a-z]" "[A-Z]" ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN DAEMON:X:2:2:DAEMON:/SBIN:/SBIN/NOLOGIN ADM:X:3:4:ADM:/VAR/ADM:/SBIN/NOLOGIN LP:X:4:7:LP:/VAR/SPOOL/LPD:/SBIN/NOLOGIN SYNC:X:5:0:SYNC:/SBIN:/BIN/SYNC SHUTDOWN:X:6:0:SHUTDOWN:/SBIN:/SBIN/SHUTDOWN HALT:X:7:0:HALT:/SBIN:/SBIN/HALT MAIL:X:8:12:MAIL:/VAR/SPOOL/MAIL:/SBIN/NOLOGIN OPERATOR:X:11:0:OPERATOR:/ROOT:/SBIN/NOLOGIN GAMES:X:12:100:GAMES:/USR/GAMES:/SBIN/NOLOGIN FTP:X:14:50:FTP USER:/VAR/FTP:/SBIN/NOLOGIN NOBODY:X:99:99:NOBODY:/:/SBIN/NOLOGIN DBUS:X:81:81:SYSTEM MESSAGE BUS:/:/SBIN/NOLOGIN POLKITD:X:999:998:USER FOR POLKITD:/:/SBIN/NOLOGIN UNBOUND:X:998:997:UNBOUND DNS RESOLVER:/ETC/UNBOUND:/SBIN/NOLOGIN COLORD:X:997:996:USER FOR COLORD:/VAR/LIB/COLORD:/SBIN/NOLOGIN USBMUXD:X:113:113:USBMUXD USER:/:/SBIN/NOLOGIN AVAHI:X:70:70:AVAHI MDNS/DNS-SD STACK:/VAR/RUN/AVAHI-DAEMON:/SBIN/NOLOGIN AVAHI-AUTOIPD:X:170:170:AVAHI IPV4LL STACK:/VAR/LIB/AVAHI-AUTOIPD:/SBIN/NOLOGIN SASLAUTH:X:996:76:"SASLAUTHD USER":/RUN/SASLAUTHD:/SBIN/NOLOGIN QEMU:X:107:107:QEMU USER:/:/SBIN/NOLOGIN LIBSTORAGEMGMT:X:995:994:DAEMON ACCOUNT FOR LIBSTORAGEMGMT:/VAR/RUN/LSM:/SBIN/NOLOGIN RPC:X:32:32:RPCBIND DAEMON:/VAR/LIB/RPCBIND:/SBIN/NOLOGIN RPCUSER:X:29:29:RPC SERVICE USER:/VAR/LIB/NFS:/SBIN/NOLOGIN NFSNOBODY:X:65534:65534:ANONYMOUS NFS USER:/VAR/LIB/NFS:/SBIN/NOLOGIN RTKIT:X:172:172:REALTIMEKIT:/PROC:/SBIN/NOLOGIN RADVD:X:75:75:RADVD USER:/:/SBIN/NOLOGIN NTP:X:38:38::/ETC/NTP:/SBIN/NOLOGIN CHRONY:X:994:993::/VAR/LIB/CHRONY:/SBIN/NOLOGIN ABRT:X:173:173::/ETC/ABRT:/SBIN/NOLOGIN PULSE:X:171:171:PULSEAUDIO SYSTEM DAEMON:/VAR/RUN/PULSE:/SBIN/NOLOGIN GDM:X:42:42::/VAR/LIB/GDM:/SBIN/NOLOGIN GNOME-INITIAL-SETUP:X:993:991::/RUN/GNOME-INITIAL-SETUP/:/SBIN/NOLOGIN POSTFIX:X:89:89::/VAR/SPOOL/POSTFIX:/SBIN/NOLOGIN SSHD:X:74:74:PRIVILEGE-SEPARATED SSH:/VAR/EMPTY/SSHD:/SBIN/NOLOGIN TCPDUMP:X:72:72::/:/SBIN/NOLOGIN TRAINEE:X:1000:1000:TRAINEE:/HOME/TRAINEE:/BIN/BASH VBOXADD:X:992:1::/VAR/RUN/VBOXADD:/BIN/FALSE TSS:X:59:59:ACCOUNT USED BY THE TROUSERS PACKAGE TO SANDBOX THE TCSD DAEMON:/DEV/NULL:/SBIN/NOLOGIN
SLES12SP1:~ # cat /etc/passwd | tr "[a-z]" "[A-Z]" AT:X:25:25:BATCH JOBS DAEMON:/VAR/SPOOL/ATJOBS:/BIN/BASH BIN:X:1:1:BIN:/BIN:/BIN/BASH DAEMON:X:2:2:DAEMON:/SBIN:/BIN/BASH FTP:X:40:49:FTP ACCOUNT:/SRV/FTP:/BIN/BASH FTPSECURE:X:488:65534:SECURE FTP USER:/VAR/LIB/EMPTY:/BIN/FALSE GAMES:X:12:100:GAMES ACCOUNT:/VAR/GAMES:/BIN/BASH GDM:X:486:485:GNOME DISPLAY MANAGER DAEMON:/VAR/LIB/GDM:/BIN/FALSE LP:X:4:7:PRINTING DAEMON:/VAR/SPOOL/LPD:/BIN/BASH MAIL:X:8:12:MAILER DAEMON:/VAR/SPOOL/CLIENTMQUEUE:/BIN/FALSE MAN:X:13:62:MANUAL PAGES VIEWER:/VAR/CACHE/MAN:/BIN/BASH MESSAGEBUS:X:499:499:USER FOR D-BUS:/VAR/RUN/DBUS:/BIN/FALSE NEWS:X:9:13:NEWS SYSTEM:/ETC/NEWS:/BIN/BASH NOBODY:X:65534:65533:NOBODY:/VAR/LIB/NOBODY:/BIN/BASH NSCD:X:496:495:USER FOR NSCD:/RUN/NSCD:/SBIN/NOLOGIN NTP:X:74:492:NTP DAEMON:/VAR/LIB/NTP:/BIN/FALSE OPENSLP:X:494:2:OPENSLP DAEMON:/VAR/LIB/EMPTY:/SBIN/NOLOGIN POLKITD:X:497:496:USER FOR POLKITD:/VAR/LIB/POLKIT:/SBIN/NOLOGIN POSTFIX:X:51:51:POSTFIX DAEMON:/VAR/SPOOL/POSTFIX:/BIN/FALSE PULSE:X:490:489:PULSEAUDIO DAEMON:/VAR/LIB/PULSEAUDIO:/SBIN/NOLOGIN ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH RPC:X:495:65534:USER FOR RPCBIND:/VAR/LIB/EMPTY:/SBIN/NOLOGIN RTKIT:X:491:490:REALTIMEKIT:/PROC:/BIN/FALSE SCARD:X:487:487:SMART CARD READER:/VAR/RUN/PCSCD:/USR/SBIN/NOLOGIN SSHD:X:498:498:SSH DAEMON:/VAR/LIB/SSHD:/BIN/FALSE STATD:X:489:65534:NFS STATD DAEMON:/VAR/LIB/NFS:/SBIN/NOLOGIN USBMUX:X:493:65534:USBMUXD DAEMON:/VAR/LIB/USBMUXD:/SBIN/NOLOGIN UUCP:X:10:14:UNIX-TO-UNIX COPY SYSTEM:/ETC/UUCP:/BIN/BASH VNC:X:492:491:USER FOR VNC:/VAR/LIB/EMPTY:/SBIN/NOLOGIN WWWRUN:X:30:8:WWW DAEMON APACHE:/VAR/LIB/WWWRUN:/BIN/FALSE TRAINEE:X:1000:100:TRAINEE:/HOME/TRAINEE:/BIN/BASH
Command Line Switches
To do : Use the –help option of the tr command to view the command line switches.
The paste Command
The paste command concatenates lines from n files. For example:
root@debian8:~# paste -d: /etc/passwd /etc/shadow root:x:0:0:root:/root:/bin/bash:root:$6$jxZolPSj$yHWmlcj8imvAXDzAoxZG3KEILb3ITQJgTPhqqLsUqjIuUrfc5Yhzrfl9KrVARr16U0MZWTdqhb.FaSsRpfRRC1:16922:0:99999:7::: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin:daemon:*:16922:0:99999:7::: bin:x:2:2:bin:/bin:/usr/sbin/nologin:bin:*:16922:0:99999:7::: sys:x:3:3:sys:/dev:/usr/sbin/nologin:sys:*:16922:0:99999:7::: sync:x:4:65534:sync:/bin:/bin/sync:sync:*:16922:0:99999:7::: games:x:5:60:games:/usr/games:/usr/sbin/nologin:games:*:16922:0:99999:7::: man:x:6:12:man:/var/cache/man:/usr/sbin/nologin:man:*:16922:0:99999:7::: lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin:lp:*:16922:0:99999:7::: mail:x:8:8:mail:/var/mail:/usr/sbin/nologin:mail:*:16922:0:99999:7::: news:x:9:9:news:/var/spool/news:/usr/sbin/nologin:news:*:16922:0:99999:7::: uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin:uucp:*:16922:0:99999:7::: proxy:x:13:13:proxy:/bin:/usr/sbin/nologin:proxy:*:16922:0:99999:7::: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin:www-data:*:16922:0:99999:7::: backup:x:34:34:backup:/var/backups:/usr/sbin/nologin:backup:*:16922:0:99999:7::: list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin:list:*:16922:0:99999:7::: irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin:irc:*:16922:0:99999:7::: gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin:gnats:*:16922:0:99999:7::: nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin:nobody:*:16922:0:99999:7::: systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false:systemd-timesync:*:16922:0:99999:7::: systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false:systemd-network:*:16922:0:99999:7::: systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false:systemd-resolve:*:16922:0:99999:7::: systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false:systemd-bus-proxy:*:16922:0:99999:7::: trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash:trainee:$6$7S6OreWb$t92JjORxWDcNyF.DtQVAotCxsWfRsvIQUaWjcNfKX3OoFh2GlX2dhtx.oeA0xEjqbff2OPb51VeVjBgwdPU4R0:16922:0:99999:7::: sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin:sshd:*:16922:0:99999:7::: Debian-exim:x:105:110::/var/spool/exim4:/bin/false:Debian-exim:!:16922:0:99999:7::: messagebus:x:106:111::/var/run/dbus:/bin/false:messagebus:*:16922:0:99999:7::: statd:x:107:65534::/var/lib/nfs:/bin/false:statd:*:16922:0:99999:7::: avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false:avahi-autoipd:*:16922:0:99999:7::: avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false:avahi:*:16922:0:99999:7::: colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false:colord:*:16922:0:99999:7::: dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false:dnsmasq:*:16922:0:99999:7::: speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh:speech-dispatcher:!:16922:0:99999:7::: pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false:pulse:*:16922:0:99999:7::: rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false:rtkit:*:16922:0:99999:7::: saned:x:115:122::/var/lib/saned:/bin/false:saned:*:16922:0:99999:7::: usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false:usbmux:*:16922:0:99999:7::: lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false:lightdm:*:16922:0:99999:7:::
root@ubuntu1604:~# paste -d: /etc/passwd /etc/shadow root:x:0:0:root:/root:/bin/bash:root:!:16924:0:99999:7::: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin:daemon:*:16911:0:99999:7::: bin:x:2:2:bin:/bin:/usr/sbin/nologin:bin:*:16911:0:99999:7::: sys:x:3:3:sys:/dev:/usr/sbin/nologin:sys:*:16911:0:99999:7::: sync:x:4:65534:sync:/bin:/bin/sync:sync:*:16911:0:99999:7::: games:x:5:60:games:/usr/games:/usr/sbin/nologin:games:*:16911:0:99999:7::: man:x:6:12:man:/var/cache/man:/usr/sbin/nologin:man:*:16911:0:99999:7::: lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin:lp:*:16911:0:99999:7::: mail:x:8:8:mail:/var/mail:/usr/sbin/nologin:mail:*:16911:0:99999:7::: news:x:9:9:news:/var/spool/news:/usr/sbin/nologin:news:*:16911:0:99999:7::: uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin:uucp:*:16911:0:99999:7::: proxy:x:13:13:proxy:/bin:/usr/sbin/nologin:proxy:*:16911:0:99999:7::: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin:www-data:*:16911:0:99999:7::: backup:x:34:34:backup:/var/backups:/usr/sbin/nologin:backup:*:16911:0:99999:7::: list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin:list:*:16911:0:99999:7::: irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin:irc:*:16911:0:99999:7::: gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin:gnats:*:16911:0:99999:7::: nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin:nobody:*:16911:0:99999:7::: systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false:systemd-timesync:*:16911:0:99999:7::: systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false:systemd-network:*:16911:0:99999:7::: systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false:systemd-resolve:*:16911:0:99999:7::: systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false:systemd-bus-proxy:*:16911:0:99999:7::: syslog:x:104:108::/home/syslog:/bin/false:syslog:*:16911:0:99999:7::: _apt:x:105:65534::/nonexistent:/bin/false:_apt:*:16911:0:99999:7::: messagebus:x:106:110::/var/run/dbus:/bin/false:messagebus:*:16911:0:99999:7::: uuidd:x:107:111::/run/uuidd:/bin/false:uuidd:*:16911:0:99999:7::: lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false:lightdm:*:16911:0:99999:7::: whoopsie:x:109:116::/nonexistent:/bin/false:whoopsie:*:16911:0:99999:7::: avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false:avahi-autoipd:*:16911:0:99999:7::: avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false:avahi:*:16911:0:99999:7::: dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false:dnsmasq:*:16911:0:99999:7::: colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false:colord:*:16911:0:99999:7::: speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false:speech-dispatcher:!:16911:0:99999:7::: hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false:hplip:*:16911:0:99999:7::: kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false:kernoops:*:16911:0:99999:7::: pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false:pulse:*:16911:0:99999:7::: rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false:rtkit:*:16911:0:99999:7::: saned:x:119:127::/var/lib/saned:/bin/false:saned:*:16911:0:99999:7::: usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false:usbmux:*:16911:0:99999:7::: trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash:trainee:$6$cloNcVp0$4BFXvmH./lvuhem.pWND1.XgChp/BuT4tHukwvFR9ykdQM1Yt.WbMO60lHdUR/E6D2bqUJ/n.BwX4gCMle/671:16924:0:99999:7::: sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin:sshd:*:16924:0:99999:7:::
[root@centos7 ~]# paste -d: /etc/passwd /etc/shadow root:x:0:0:root:/root:/bin/bash:root:$6$r4px/s9L2uwGSFnI$NkK5mzNF.CMAFFqMcO.i.tnrMZQDkriDLYwICsimsPaDWKFwUHS3NhDwZY5e7P3glIu.gTBtaOE.SOOW/D.AU/:16502:0:99999:7::: bin:x:1:1:bin:/bin:/sbin/nologin:bin:*:16231:0:99999:7::: daemon:x:2:2:daemon:/sbin:/sbin/nologin:daemon:*:16231:0:99999:7::: adm:x:3:4:adm:/var/adm:/sbin/nologin:adm:*:16231:0:99999:7::: lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin:lp:*:16231:0:99999:7::: sync:x:5:0:sync:/sbin:/bin/sync:sync:*:16231:0:99999:7::: shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown:shutdown:*:16231:0:99999:7::: halt:x:7:0:halt:/sbin:/sbin/halt:halt:*:16231:0:99999:7::: mail:x:8:12:mail:/var/spool/mail:/sbin/nologin:mail:*:16231:0:99999:7::: operator:x:11:0:operator:/root:/sbin/nologin:operator:*:16231:0:99999:7::: games:x:12:100:games:/usr/games:/sbin/nologin:games:*:16231:0:99999:7::: ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin:ftp:*:16231:0:99999:7::: nobody:x:99:99:Nobody:/:/sbin/nologin:nobody:*:16231:0:99999:7::: dbus:x:81:81:System message bus:/:/sbin/nologin:dbus:!!:16502:::::: polkitd:x:999:998:User for polkitd:/:/sbin/nologin:polkitd:!!:16502:::::: unbound:x:998:997:Unbound DNS resolver:/etc/unbound:/sbin/nologin:unbound:!!:16502:::::: colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin:colord:!!:16502:::::: usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin:usbmuxd:!!:16502:::::: avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin:avahi:!!:16502:::::: avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin:avahi-autoipd:!!:16502:::::: saslauth:x:996:76:"Saslauthd user":/run/saslauthd:/sbin/nologin:saslauth:!!:16502:::::: qemu:x:107:107:qemu user:/:/sbin/nologin:qemu:!!:16502:::::: libstoragemgmt:x:995:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin:libstoragemgmt:!!:16502:::::: rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin:rpc:!!:16502:0:99999:7::: rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin:rpcuser:!!:16502:::::: nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin:nfsnobody:!!:16502:::::: rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin:rtkit:!!:16502:::::: radvd:x:75:75:radvd user:/:/sbin/nologin:radvd:!!:16502:::::: ntp:x:38:38::/etc/ntp:/sbin/nologin:ntp:!!:16502:::::: chrony:x:994:993::/var/lib/chrony:/sbin/nologin:chrony:!!:16502:::::: abrt:x:173:173::/etc/abrt:/sbin/nologin:abrt:!!:16502:::::: pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin:pulse:!!:16502:::::: gdm:x:42:42::/var/lib/gdm:/sbin/nologin:gdm:!!:16502:::::: gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin:gnome-initial-setup:!!:16502:::::: postfix:x:89:89::/var/spool/postfix:/sbin/nologin:postfix:!!:16502:::::: sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin:sshd:!!:16502:::::: tcpdump:x:72:72::/:/sbin/nologin:tcpdump:!!:16502:::::: trainee:x:1000:1000:trainee:/home/trainee:/bin/bash:trainee:$6$tMd44tmmFiitAS7.$sJSua3jhyKm2k0mIifYuTpUO0d6q6/gS3PDyuxbHadHVYLsoVslZ3Pn8m5X93rr64oj.KK8OL6J.gvhxbQBrZ1:16502:0:99999:7::: vboxadd:x:992:1::/var/run/vboxadd:/bin/false:vboxadd:!!:16691:::::: tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin:tss:!!:16723::::::
SLES12SP1:~ # paste -d: /etc/passwd /etc/shadow at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash:at:!:16922:::::: bin:x:1:1:bin:/bin:/bin/bash:bin:*:16765:::::: daemon:x:2:2:Daemon:/sbin:/bin/bash:daemon:*:16765:::::: ftp:x:40:49:FTP account:/srv/ftp:/bin/bash:ftp:*:16765:::::: ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false:ftpsecure:!:16922:::::: games:x:12:100:Games account:/var/games:/bin/bash:games:*:16765:::::: gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false:gdm:!:16922:::::: lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash:lp:*:16765:::::: mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false:mail:*:16765:::::: man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash:man:*:16765:::::: messagebus:x:499:499:User for D-Bus:/var/run/dbus:/bin/false:messagebus:!:16765:::::: news:x:9:13:News system:/etc/news:/bin/bash:news:*:16765:::::: nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash:nobody:*:16765:::::: nscd:x:496:495:User for nscd:/run/nscd:/sbin/nologin:nscd:!:16765:::::: ntp:x:74:492:NTP daemon:/var/lib/ntp:/bin/false:ntp:!:16922:::::: openslp:x:494:2:openslp daemon:/var/lib/empty:/sbin/nologin:openslp:!:16765:::::: polkitd:x:497:496:User for polkitd:/var/lib/polkit:/sbin/nologin:polkitd:!:16765:::::: postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false:postfix:!:16922:::::: pulse:x:490:489:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin:pulse:!:16922:::::: root:x:0:0:root:/root:/bin/bash:root:$6$g0tHJ9vyIfFt$rbm.rf7p6XZMxMqbqa/BGDeA7E7RkC9n89w8cWdpAxkUmwk7BPcMv7Zy9nVAn7f/7zQJzcRcsIqp5bRx1e8iX/:16922:::::: rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin:rpc:!:16765:::::: rtkit:x:491:490:RealtimeKit:/proc:/bin/false:rtkit:!:16922:::::: scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin:scard:!:16922:::::: sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false:sshd:!:16765:::::: statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin:statd:!:16922:::::: usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin:usbmux:!:16922:::::: uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash:uucp:*:16765:::::: vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin:vnc:!:16922:::::: wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false:wwwrun:*:16765:::::: trainee:x:1000:100:trainee:/home/trainee:/bin/bash:trainee:$6$OZyVqj4ekgmu$Cw0T.n6gNv.vTdAT6dFxrrSeHW/V3r43jWFczPG0lxg5SB9iMUcQ6MFLz9NuTTas289xe/ULsJhE2HdJbraGA.:16922:0:99999:7:::
Important: Note that you need to be root to be able to execute this command. The reason is that normal users do not have the right to read the /etc/shadow file.
Command Line Switches
To do : Use the –help option of the paste command to view the command line switches.
The split Command
The split command is used to divide a large file into smaller segments. Create an empty 250 MB file as follows:
root@debian8:~# dd if=/dev/zero of=/file bs=1024k count=250 250+0 records in 250+0 records out 262144000 bytes (262 MB) copied, 0.57181 s, 458 MB/s
root@ubuntu1604:~# dd if=/dev/zero of=/file bs=1024k count=250 250+0 records in 250+0 records out 262144000 bytes (262 MB, 250 MiB) copied, 2,57217 s, 102 MB/s
[root@centos7 ~]# dd if=/dev/zero of=/file bs=1024k count=250 250+0 records in 250+0 records out 262144000 bytes (262 MB) copied, 0.215447 s, 1.2 GB/s
SLES12SP1:~ # dd if=/dev/zero of=/file bs=1024k count=250 250+0 records in 250+0 records out 262144000 bytes (262 MB) copied, 3.50609 s, 74.8 MB/s
Now use the split command to divide the file into 5 smaller files each of 50 MB:
root@debian8:~# split -b 50m /file filepart root@debian8:~# ls -l | grep filepart -rw-r--r-- 1 root root 52428800 Nov 30 18:41 filepartaa -rw-r--r-- 1 root root 52428800 Nov 30 18:41 filepartab -rw-r--r-- 1 root root 52428800 Nov 30 18:41 filepartac -rw-r--r-- 1 root root 52428800 Nov 30 18:41 filepartad -rw-r--r-- 1 root root 52428800 Nov 30 18:41 filepartae
root@ubuntu1604:~# split -b 50m /file filepart root@ubuntu1604:~# ls -l | grep filepart -rw-r--r-- 1 root root 52428800 déc. 17 11:31 filepartaa -rw-r--r-- 1 root root 52428800 déc. 17 11:31 filepartab -rw-r--r-- 1 root root 52428800 déc. 17 11:31 filepartac -rw-r--r-- 1 root root 52428800 déc. 17 11:31 filepartad -rw-r--r-- 1 root root 52428800 déc. 17 11:31 filepartae
[root@centos7 ~]# split -b 50m /file filepart [root@centos7 ~]# ls -l | grep filepart -rw-r--r--. 1 root root 52428800 Oct 19 15:31 filepartaa -rw-r--r--. 1 root root 52428800 Oct 19 15:31 filepartab -rw-r--r--. 1 root root 52428800 Oct 19 15:31 filepartac -rw-r--r--. 1 root root 52428800 Oct 19 15:31 filepartad -rw-r--r--. 1 root root 52428800 Oct 19 15:31 filepartae
SLES12SP1:~ # split -b 50m /file filepart SLES12SP1:~ # ls -l | grep filepart -rw-r--r-- 1 root root 52428800 Dec 14 15:10 filepartaa -rw-r--r-- 1 root root 52428800 Dec 14 15:10 filepartab -rw-r--r-- 1 root root 52428800 Dec 14 15:10 filepartac -rw-r--r-- 1 root root 52428800 Dec 14 15:10 filepartad -rw-r--r-- 1 root root 52428800 Dec 14 15:10 filepartae
Important: Note that the 5 files were created in the current working directory.
You can re-construct the original file by using the cat command:
root@debian8:~# cat fileparta* > newfile root@debian8:~# ls -l | grep newf -rw-r--r-- 1 root root 262144000 Nov 30 18:42 newfile
root@ubuntu1604:~# cat fileparta* > newfile root@ubuntu1604:~# ls -l | grep newf -rw-r--r-- 1 root root 262144000 déc. 17 11:32 newfile
[root@centos7 ~]# cat fileparta* > newfile [root@centos7 ~]# ls -l | grep newf -rw-r--r--. 1 root root 262144000 Oct 19 15:31 newfile
SLES12SP1:~ # cat fileparta* > newfile SLES12SP1:~ # ls -l | grep newf -rw-r--r-- 1 root root 262144000 Dec 14 15:11 newfile
Command Line Switches
To do : Use the –help option of the split command to view the command line switches.
The diff Command
The diff command compares two fles and indicates what changes need to be made to the first file in order that it be identical to the second file.
Copy the /etc/passwd file to the /root directory:
root@debian8:~# cp /etc/passwd /root
root@ubuntu1604:~# cp /etc/passwd /root
[root@centos ~]# cp /etc/passwd /root
SLES12SP1:~ # cp /etc/passwd /root
Debian
Edit the */root/passwd file as shown:
... trainee10:x:1000:1000:trainee:/home/trainee:/bin/bash ...
Delete the lp entry and add the following line to the end of /root/passwd:
... Linux is great!
Now compare the two files:
root@debian8:~# diff /etc/passwd /root/passwd 8d7 < lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin 23c22 < trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash --- > trainee10:x:1000:1000:trainee,,,:/home/trainee:/bin/bash 37a37 > Linux is great!
In this output you will notice the < and > characters. The first makes reference to the first file, /etc/passwd, whist the second makes reference to the second file, /root/passwd.
The output 8d7 means that line 8 needs to be deleted in /etc/passwd because it is missing in /root/passwd.
The output 23c22 means that at line 23 in /etc/passwd needs to be modified in order to be the same as line 22 in /root/passwd.
The output 37a37 means that line 37 in /root/passwd needs to be added after line 37 in /etc/passwd.
Ubuntu
Edit the */root/passwd file as shown:
... trainee10:x:1000:1000:trainee:/home/trainee:/bin/bash ...
Delete the lp entry and add the following line to the end of /root/passwd:
... Linux is great!
Now compare the two files:
root@ubuntu1604:~# diff /etc/passwd /root/passwd 8d7 < lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin 40c39 < trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash --- > trainee10:x:1000:1000:trainee,,,:/home/trainee:/bin/bash 41a41 > Linux is great!
In this output you will notice the < and > characters. The first makes reference to the first file, /etc/passwd, whist the second makes reference to the second file, /root/passwd.
The output 8d7 means that line 8 needs to be deleted in /etc/passwd because it is missing in /root/passwd.
The output 40c39 means that at line 40 in /etc/passwd needs to be modified in order to be the same as line 39 in /root/passwd.
The output 41a41 means that at line 41 in /root/passwd line 41 in /etc/passwd needs to be added because it is missing.
RHEL/CentOS
Edit the */root/passwd file as shown:
... trainee10:x:1000:1000:trainee:/home/trainee:/bin/bash ...
Delete the tcpdump entry and add the following line to the end of /root/passwd:
... Linux est super!
Now compare the two files:
[root@centos7 ~]# diff /etc/passwd /root/passwd 38,39c38 < trainee:x:1000:1000:trainee:/home/trainee:/bin/bash < vboxadd:x:992:1::/var/run/vboxadd:/bin/false --- > trainee10:x:1000:1000:trainee:/home/trainee:/bin/bash 40a40 > Linux est super!
In this output you will notice the < and > characters. The first makes reference to the first file, /etc/passwd, whist the second makes reference to the second file, /root/passwd.
The output 38,39c38 means that line 39 needs to be changed in /etc/passwd so that is the same as line 38 in /root/passwd.
The output 40a40 means that at line 40 in /etc/passwd line 40 from /root/passwd needs to be added.
SLES
Edit the */root/passwd file as shown:
... trainee10:x:1000:1000:trainee:/home/trainee:/bin/bash ...
Delete the uucp entry and add the following line to the end of /root/passwd:
... Linux est super!
Now compare the two files:
SLES12SP1:~ # diff /etc/passwd /root/passwd 27d26 < uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash 30c29,30 < trainee:x:1000:100:trainee:/home/trainee:/bin/bash --- > trainee10:x:1000:100:trainee:/home/trainee:/bin/bash > Linux est super
In this output you will notice the < and > characters. The first makes reference to the first file, /etc/passwd, whist the second makes reference to the second file, /root/passwd.
The output 27d26 means that line 27 needs to be deleted form /etc/passwd because it does not exist in /root/passwd.
The output 30c29,30 means that line 30 needs to be changed in /etc/passwd so that is the same as line 29 in /root/passwd.
Command Line Switches
To do : Use the –help option of the diff command to view the command line switches.
The cmp Command
The cmp command compares two files character by character. By default, the command stops after finding the first difference:
root@debian8:~# cmp /root/passwd /etc/passwd /root/passwd /etc/passwd differ: byte 286, line 8
root@ubuntu1604:~# cmp /root/passwd /etc/passwd /root/passwd /etc/passwd differ: byte 286, line 8
[root@centos7 ~]# cmp /root/passwd /etc/passwd /root/passwd /etc/passwd differ: byte 1873, line 38
SLES12SP1:~ # cmp /root/passwd /etc/passwd /root/passwd /etc/passwd differ: char 1413, line 27
The -l switch shows all of the differences in a three column format:
root@debian8:~# cmp -l /root/passwd /etc/passwd | more cmp: EOF on /root/passwd 286 155 154 287 141 160 288 151 72 289 154 170 291 170 67 293 70 67 295 70 154 296 72 160 297 155 72 298 141 57 299 151 166 300 154 141 301 72 162 303 166 163 304 141 160 305 162 157 306 57 157 307 155 154 308 141 57 309 151 154 310 154 160 311 72 144 312 57 72 --More--
root@ubuntu1604:~# cmp -l /root/passwd /etc/passwd | more cmp: EOF on /root/passwd 286 155 154 287 141 160 288 151 72 289 154 170 291 170 67 293 70 67 295 70 154 296 72 160 297 155 72 298 141 57 299 151 166 300 154 141 301 72 162 303 166 163 304 141 160 305 162 157 306 57 157 307 155 154 308 141 57 309 151 154 310 154 160 311 72 144 312 57 72 --More--
[root@centos7 ~]# cmp -l /root/passwd /etc/passwd | more cmp: EOF on /root/passwd 1873 61 72 1874 60 170 1876 170 61 1877 72 60 1878 61 60 1880 60 72 1881 60 61 1882 72 60 1883 61 60 1885 60 72 1886 60 164 1887 72 162 1888 164 141 1889 162 151 1890 141 156 1891 151 145 1892 156 145 1893 145 72 1894 145 57 1895 72 150 1896 57 157 1897 150 155 1898 157 145 1899 155 57 1900 145 164 1901 57 162 1902 164 141 1903 162 151 --More--
SLES12SP1:~ # cmp -l /root/passwd /etc/passwd | more cmp: EOF on /root/passwd 1413 166 165 1414 156 165 1416 72 160 1417 170 72 1418 72 170 1419 64 72 1420 71 61 1421 62 60 1423 64 61 1424 71 64 1425 61 72 1426 72 125 1427 165 156 1428 163 151 1429 145 170 1430 162 55 1431 40 164 1432 146 157 1433 157 55 1434 162 125 1435 40 156 1436 126 151 1437 116 170 --More--
The first column represents the character number, the second column represents the ASCII octal value of the character in the /root/passwd file and the third column represents the ASCII octal value of the character in the /etc/passwd file.
Command Line Switches
To do : Use the –help option of the cmp command to view the command line switches.
The patch Command
The patch command is used to apply modifications contained within a patch file to an older version of a file so that it becomes the newer version of the file.
Debian
If you recall, you made some changes to the original greptest file that you downloaded:
root@debian8:~# cat /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
You also used egrep to remove all the comments and empty lines and save the result to /tmp/greptest1:
[root@centos ~]# cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
Now create a patch file containing the modifications that need to be applied to /tmp/greptest in order for it to be identical to /tmp/greptest1:
root@debian8:~# cd /tmp root@debian8:/tmp# diff -u greptest greptest1 > greptest.patch
A look at the patch file shows the chnages that need to be made to the greptest file:
root@debian8:/tmp# cat /tmp/greptest.patch --- greptest 2016-11-30 18:54:52.732000000 +0000 +++ greptest1 2016-11-30 18:55:28.392000000 +0000 @@ -1,14 +1,7 @@ -# Starting comment -^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros -# Another comment 555-5555 f - .fenestros - .fe - £ -# End comment
Now apply the patch file:
root@debian8:/tmp# patch < greptest.patch patching file greptest
Finally, check the contents of the patched greptest file:
root@debian8:/tmp# cat greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
Ubuntu
If you recall, you made some changes to the original greptest file that you downloaded:
root@ubuntu1604:~# cat /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
You also used egrep to remove all the comments and empty lines and save the result to /tmp/greptest1:
root@ubuntu1604:~# cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
Now create a patch file containing the modifications that need to be applied to /tmp/greptest in order for it to be identical to /tmp/greptest1:
root@ubuntu1604:~# cd /tmp root@ubuntu1604:/tmp# diff -u greptest greptest1 > greptest.patch
A look at the patch file shows the chnages that need to be made to the greptest file:
root@ubuntu1604:/tmp# cat /tmp/greptest.patch --- greptest 2016-12-09 15:47:38.836983792 +0100 +++ greptest1 2016-12-09 15:46:15.976860968 +0100 @@ -1,14 +1,7 @@ -# Starting comment -^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros -# Another comment 555-5555 f - .fenestros - .fe - £ -# End comment
Now apply the patch file:
root@ubuntu1604:/tmp# patch < greptest.patch patching file greptest
Finally, check the contents of the patched greptest file:
root@ubuntu1604:/tmp# cat greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
RHEL/CentOS
The patch command is not installed by default in RHEL/CentOS 7:
[root@centos7 ~]# yum install patch Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.ibcp.fr * extras: mirrors.atosworldline.com * updates: mirror.ibcp.fr Resolving Dependencies --> Running transaction check ---> Package patch.x86_64 0:2.7.1-8.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================================================== Package Arch Version Repository Size ====================================================================================================================================================== Installing: patch x86_64 2.7.1-8.el7 base 110 k Transaction Summary ====================================================================================================================================================== Install 1 Package Total download size: 110 k Installed size: 210 k Is this ok [y/d/N]: y Downloading packages: patch-2.7.1-8.el7.x86_64.rpm | 110 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : patch-2.7.1-8.el7.x86_64 1/1 Verifying : patch-2.7.1-8.el7.x86_64 1/1 Installed: patch.x86_64 0:2.7.1-8.el7 Complete!
If you recall, you made some changes to the original greptest file that you downloaded:
[root@centos7 ~]# cat /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
You also used egrep to remove all the comments and empty lines and save the result to /tmp/greptest1:
[root@centos ~]# cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
Now create a patch file containing the modifications that need to be applied to /tmp/greptest in order for it to be identical to /tmp/greptest1:
[root@centos7 ~]# cd /tmp [root@centos7 tmp]# diff -u greptest greptest1 > greptest.patch
A look at the patch file shows the changes that need to be made to the greptest file:
[root@centos tmp]# cat /tmp/greptest.patch --- greptest 2013-01-07 15:14:03.646565259 +0100 +++ greptest1 2013-01-07 15:07:05.657375635 +0100 @@ -1,14 +1,7 @@ -# Starting comment -^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros -# Another comment 555-5555 f - .fenestros - .fe - £ -# End comment
Now apply the patch file:
[root@centos7 tmp]# patch < greptest.patch patching file greptest
Finally, check the contents of the patched greptest file:
[root@centos7 tmp]# cat greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
SLES
If you recall, you made some changes to the original greptest file that you downloaded:
SLES12SP1:~ # cat /tmp/greptest # Starting comment ^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros # Another comment 555-5555 f .fenestros .fe £ # End comment
You also used egrep to remove all the comments and empty lines and save the result to /tmp/greptest1:
SLES12SP1:~ # cat /tmp/greptest1 fenestrOS fenestros 555-5555 f .fenestros .fe £
Now create a patch file containing the modifications that need to be applied to /tmp/greptest in order for it to be identical to /tmp/greptest1:
SLES12SP1:~ # cd /tmp SLES12SP1:/tmp # diff -u greptest greptest1 > greptest.patch
A look at the patch file shows the chnages that need to be made to the greptest file:
SLES12SP1:/tmp # cat /tmp/greptest.patch --- greptest 2016-12-14 14:00:32.987471124 +0100 +++ greptest1 2016-12-14 13:59:12.319471124 +0100 @@ -1,14 +1,7 @@ -# Starting comment -^ This line will be used to demonstrate the use of fgrep fenestrOS fenestros -# Another comment 555-5555 f - .fenestros - .fe - £ -# End comment
Now apply the patch file:
SLES12SP1:/tmp # patch < greptest.patch patching file greptest
Finally, check the contents of the patched greptest file:
SLES12SP1:/tmp # cat greptest fenestrOS fenestros 555-5555 f .fenestros .fe £
Command Line Switches
To do : Use the –help option of the patch command to view the command line switches.
The strings Command
The strings Command is used to extract any printable string in one or more object files or executables. An object fie is an intermediary file used when compiling.
The format of an object file is ELF (Executable and Linkable Format). This same format is also used for:
- executables,
- shared libraries,
- core dumps.
Debian
The strings command is not installed by default in Debian 8 :
root@debian8:/tmp# apt-get install binutils Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: binutils-doc The following NEW packages will be installed: binutils 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 3,516 kB of archives. After this operation, 21.1 MB of additional disk space will be used. Get:1 http://ftp.fr.debian.org/debian/ jessie/main binutils amd64 2.25-5 [3,516 kB] Fetched 3,516 kB in 0s (7,674 kB/s) Selecting previously unselected package binutils. (Reading database ... 82508 files and directories currently installed.) Preparing to unpack .../binutils_2.25-5_amd64.deb ... Unpacking binutils (2.25-5) ... Processing triggers for man-db (2.7.0.2-5) ... Setting up binutils (2.25-5) ... Processing triggers for libc-bin (2.19-18+deb8u4) ... root@debian8:/tmp# which strings /usr/bin/strings
Used as is, the command extracts all strings greater than 4 characters in length:
root@debian8:/tmp# strings /usr/bin/passwd | more /lib64/ld-linux-x86-64.so.2 libpam.so.0 _ITM_deregisterTMCloneTable __gmon_start__ _Jv_RegisterClasses _ITM_registerTMCloneTable pam_start pam_strerror pam_chauthtok pam_end libpam_misc.so.0 misc_conv libaudit.so.1 _fini _init libselinux.so.1 is_selinux_enabled security_getenforce context_user_get security_compute_av matchpathcon freecon context_free --More--
Print the offset within the file before each string:
root@debian8:/tmp# strings -t d /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 3985 libpam.so.0 3997 _ITM_deregisterTMCloneTable 4025 __gmon_start__ 4040 _Jv_RegisterClasses 4060 _ITM_registerTMCloneTable 4086 pam_start 4096 pam_strerror 4109 pam_chauthtok 4123 pam_end 4131 libpam_misc.so.0 4148 misc_conv 4158 libaudit.so.1 4172 _fini 4178 _init 4184 libselinux.so.1 4200 is_selinux_enabled 4219 security_getenforce 4239 context_user_get 4256 security_compute_av 4276 matchpathcon 4289 freecon 4297 context_free --More--
The -t switch can take one of three arguments that specify the numbering system to use:
Argument | Numbering System |
---|---|
d | Decimal |
o | Octal |
x | Hexadecimal |
The -n switch prints sequences of characters that are at least min-len characters long, instead of the default 4:
root@debian8:/tmp# strings -t d -n 15 /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 3997 _ITM_deregisterTMCloneTable 4040 _Jv_RegisterClasses 4060 _ITM_registerTMCloneTable 4131 libpam_misc.so.0 4184 libselinux.so.1 4200 is_selinux_enabled 4219 security_getenforce 4239 context_user_get 4256 security_compute_av 4532 __stack_chk_fail 4693 __errno_location 5150 __libc_start_main 5246 LIBPAM_MISC_1.0 34104 Usage: %s [options] [LOGIN] 34144 -a, --all report password status on all accounts 34216 -d, --delete delete the password for the named accoun t 34296 -e, --expire force expire the password for the named account 34384 -h, --help display this help message and exit 34456 -k, --keep-tokens change password only if expired 34528 -i, --inactive INACTIVE set password inactive after expiration --More--
The -f switch prints the name of the file before each string:
root@debian8:/tmp# strings -f /bin/* | grep "(c)" /bin/ntfscat: Copyright (c) 2003-2005 Richard Russon /bin/ntfscat: Copyright (c) 2003-2005 Anton Altaparmakov /bin/ntfscat: Copyright (c) 2003-2005 Szabolcs Szakacsits /bin/ntfscat: Copyright (c) 2007 Yura Pakhuchiy /bin/ntfscluster: Copyright (c) 2002-2003 Richard Russon /bin/ntfscluster: Copyright (c) 2005 Anton Altaparmakov /bin/ntfscluster: Copyright (c) 2005-2006 Szabolcs Szakacsits /bin/ntfsfallocate: Copyright (c) 2013-2014 Jean-Pierre Andre /bin/ntfsfix: Copyright (c) 2000-2006 Anton Altaparmakov /bin/ntfsfix: Copyright (c) 2002-2006 Szabolcs Szakacsits /bin/ntfsfix: Copyright (c) 2007 Yura Pakhuchiy /bin/ntfsfix: Copyright (c) 2011-2014 Jean-Pierre Andre /bin/ntfsinfo: Copyright (c) /bin/ntfsls: Copyright (c) 2003-2005 Anton Altaparmakov /bin/ntfsls: Copyright (c) 2003 Richard Russon /bin/ntfsls: Copyright (c) 2004 Carmelo Kintana /bin/ntfsls: Copyright (c) 2004 Giang Nguyen /bin/ntfsls: Copyright (c) 2003 Lode Leroy /bin/ntfsmove: Copyright (c) 2003 Richard Russon /bin/ntfstruncate: Copyright (c) 2002-2005 Anton Altaparmakov /bin/ntfstruncate: Copyright (c) 2003 Richard Russon /bin/ntfswipe: Copyright (c) 2002-2005 Richard Russon /bin/ntfswipe: Copyright (c) 2004 Yura Pakhuchiy /bin/ping: @(#) Copyright (c) 1989 The Regents of the University of California. /bin/ping6: @(#) Copyright (c) 1989 The Regents of the University of California.
Ubuntu
Used as is, the command extracts all strings greater than 4 characters in length:
root@ubuntu1604:/tmp# strings /usr/bin/passwd | more /lib64/ld-linux-x86-64.so.2 kgUa libpam.so.0 _ITM_deregisterTMCloneTable __gmon_start__ _Jv_RegisterClasses _ITM_registerTMCloneTable pam_start pam_strerror pam_chauthtok pam_end libpam_misc.so.0 misc_conv libselinux.so.1 _init is_selinux_enabled security_getenforce context_user_get security_compute_av matchpathcon freecon context_free setfscreatecon --More--
Print the offset within the file before each string:
root@ubuntu1604:/tmp# strings -t d /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 823 kgUa 4241 libpam.so.0 4253 _ITM_deregisterTMCloneTable 4281 __gmon_start__ 4296 _Jv_RegisterClasses 4316 _ITM_registerTMCloneTable 4342 pam_start 4352 pam_strerror 4365 pam_chauthtok 4379 pam_end 4387 libpam_misc.so.0 4404 misc_conv 4414 libselinux.so.1 4430 _init 4436 is_selinux_enabled 4455 security_getenforce 4475 context_user_get 4492 security_compute_av 4512 matchpathcon 4525 freecon 4533 context_free 4546 setfscreatecon --More--
The -t switch can take one of three arguments that specify the numbering system to use:
Argument | Numbering System |
---|---|
d | Decimal |
o | Octal |
x | Hexadecimal |
The -n switch prints sequences of characters that are at least min-len characters long, instead of the default 4:
root@ubuntu1604:/tmp# strings -t d -n 15 /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 4253 _ITM_deregisterTMCloneTable 4296 _Jv_RegisterClasses 4316 _ITM_registerTMCloneTable 4387 libpam_misc.so.0 4414 libselinux.so.1 4436 is_selinux_enabled 4455 security_getenforce 4475 context_user_get 4492 security_compute_av 4774 __stack_chk_fail 4942 __errno_location 5405 __libc_start_main 5537 LIBPAM_MISC_1.0 34456 Usage: %s [options] [LOGIN] 34496 -a, --all report password status on all accounts 34568 -d, --delete delete the password for the named accoun t 34648 -e, --expire force expire the password for the named account 34736 -h, --help display this help message and exit 34808 -k, --keep-tokens change password only if expired 34880 -i, --inactive INACTIVE set password inactive after expiration --More--
The -f switch prints the name of the file before each string:
root@ubuntu1604:/tmp# strings -f /bin/* | grep "(c)" /bin/ntfscat: Copyright (c) 2003-2005 Richard Russon /bin/ntfscat: Copyright (c) 2003-2005 Anton Altaparmakov /bin/ntfscat: Copyright (c) 2003-2005 Szabolcs Szakacsits /bin/ntfscat: Copyright (c) 2007 Yura Pakhuchiy /bin/ntfscluster: Copyright (c) 2002-2003 Richard Russon /bin/ntfscluster: Copyright (c) 2005 Anton Altaparmakov /bin/ntfscluster: Copyright (c) 2005-2006 Szabolcs Szakacsits /bin/ntfsfallocate: Copyright (c) 2013-2014 Jean-Pierre Andre /bin/ntfsfix: Copyright (c) 2000-2006 Anton Altaparmakov /bin/ntfsfix: Copyright (c) 2002-2006 Szabolcs Szakacsits /bin/ntfsfix: Copyright (c) 2007 Yura Pakhuchiy /bin/ntfsfix: Copyright (c) 2011-2015 Jean-Pierre Andre /bin/ntfsinfo: Copyright (c) /bin/ntfsls: Copyright (c) 2003-2005 Anton Altaparmakov /bin/ntfsls: Copyright (c) 2003 Richard Russon /bin/ntfsls: Copyright (c) 2004 Carmelo Kintana /bin/ntfsls: Copyright (c) 2004 Giang Nguyen /bin/ntfsls: Copyright (c) 2003 Lode Leroy /bin/ntfsmove: Copyright (c) 2003 Richard Russon /bin/ntfstruncate: Copyright (c) 2002-2005 Anton Altaparmakov /bin/ntfstruncate: Copyright (c) 2003 Richard Russon /bin/ntfswipe: Copyright (c) 2002-2005 Richard Russon /bin/ntfswipe: Copyright (c) 2004 Yura Pakhuchiy /bin/ping: @(#) Copyright (c) 1989 The Regents of the University of California. /bin/ping6: @(#) Copyright (c) 1989 The Regents of the University of California..
RHEL/CentOS
Used as is, the command extracts all strings greater than 4 characters in length:
[root@centos7 tmp]# strings /usr/bin/passwd | more /lib64/ld-linux-x86-64.so.2 {1~` libuser.so.1 g_value_get_int64 is_selinux_enabled _ITM_deregisterTMCloneTable g_free g_value_array_get_nth __gmon_start__ g_value_get_string g_type_check_value_holds g_value_get_long _Jv_RegisterClasses freecon _ITM_registerTMCloneTable lu_ent_set_string lu_ent_get_first_value_strdup lu_error_free lu_user_lock _fini _init lu_strerror lu_ent_free lu_ent_new lu_user_modify lu_prompt_console lu_start lu_user_lookup_name --More--
Print the offset within the file before each string:
[root@centos7 tmp]# strings -t d /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 648 {1~` 2833 libuser.so.1 2846 g_value_get_int64 2864 is_selinux_enabled 2883 _ITM_deregisterTMCloneTable 2911 g_free 2918 g_value_array_get_nth 2940 __gmon_start__ 2955 g_value_get_string 2974 g_type_check_value_holds 2999 g_value_get_long 3016 _Jv_RegisterClasses 3036 freecon 3044 _ITM_registerTMCloneTable 3070 lu_ent_set_string 3088 lu_ent_get_first_value_strdup 3118 lu_error_free 3132 lu_user_lock 3145 _fini 3151 _init 3157 lu_strerror 3169 lu_ent_free 3181 lu_ent_new 3192 lu_user_modify 3207 lu_prompt_console 3225 lu_start 3234 lu_user_lookup_name --More--
The -t switch can take one of three arguments that specify the numbering system to use:
Argument | Numbering System |
---|---|
d | Decimal |
o | Octal |
x | Hexadecimal |
The -n switch prints sequences of characters that are at least min-len characters long, instead of the default 4:
[root@centos7 tmp]# strings -t d -n 15 /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 2846 g_value_get_int64 2864 is_selinux_enabled 2883 _ITM_deregisterTMCloneTable 2918 g_value_array_get_nth 2955 g_value_get_string 2974 g_type_check_value_holds 2999 g_value_get_long 3016 _Jv_RegisterClasses 3044 _ITM_registerTMCloneTable 3070 lu_ent_set_string 3088 lu_ent_get_first_value_strdup 3207 lu_prompt_console 3234 lu_user_lookup_name 3261 lu_ent_set_long 3303 lu_user_removepass 3322 libgobject-2.0.so.0 3342 libglib-2.0.so.0 3372 poptSetOtherOptionHelp 3464 poptHelpOptions 3503 audit_log_acct_message 3599 libpam_misc.so.0 3640 audit_log_user_avc_message 3667 audit_log_user_message 3690 libselinux.so.1 3706 selinux_set_callback 3727 selinux_check_access 3759 libpthread.so.0 --More--
The -f switch prints the name of the file before each string:
[root@centos7 tmp]# strings -f /bin/* | grep "(c)" /bin/btrace: # Copyright (c) 2005 Silicon Graphics, Inc. /bin/cdda-player: (c) 1997,98 Gerd Knorr <kraxel@goldbach.in-berlin.de> /bin/cdda-player: (c) 2005, 2006 Rocky Bernstein <rocky@gnu.org> /bin/cd-drive: Copyright (c) 2003-2005, 2007-2008, 2011-2013 R. Bernstein /bin/cd-info: Copyright (c) 2003-2005, 2007-2008, 2011-2013 R. Bernstein /bin/cd-read: Copyright (c) 2003-2005, 2007-2008, 2011-2013 R. Bernstein /bin/chcat: if len(c) > 0 and ( c[0] == "+" or c[0] == "-" ): /bin/chcat: if len(c) > 0 and c[0] == "+": /bin/chcat: if len(c) > 0 and c[0] == "-": /bin/crash: (c) a pointer to the first item pointed to by the start address. /bin/crash: (c) a list_head that is embedded within a data structure that is /bin/crash: switch(c) /bin/csh: @(#) Copyright (c) 1991 The Regents of the University of California. /bin/diffpp: # Copyright (c) 1996-1998 Markku Rossi /bin/drill: Copyright (c) 2004-2008 NLnet Labs. /bin/festival_server: ## Copyright (c) 1996 ## /bin/festival_server_control: ## Copyright (c) 1996 ## /bin/gcm-calibrate: Copyright (c) /bin/gprof: @(#) Copyright (c) 1983 Regents of the University of California. /bin/hpijs: Copyright (c) 2001-2004, Hewlett-Packard Co. /bin/ibus-setup: # Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com> /bin/ibus-setup: # Copyright (c) 2007-2010 Red Hat, Inc. /bin/ibus-table-createdb: # Copyright (c) 2008-2009 Yu Yuwei <acevery@gmail.com> /bin/iso-info: Copyright (c) 2003-2005, 2007-2008, 2011-2013 R. Bernstein /bin/iso-read: Copyright (c) 2003-2005, 2007-2008, 2011-2013 R. Bernstein /bin/lsusb.py: # (c) Kurt Garloff <garloff@suse.de>, 2/2009, GPL v2 or v3. /bin/mmc-tool: Copyright (c) 2003-2005, 2007-2008, 2011-2013 R. Bernstein /bin/orca: __copyright__ = "Copyright (c) 2010-2012 The Orca Team" \ /bin/orca: "Copyright (c) 2012 Igalia, S.L." /bin/pinentry: # Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany. /bin/pinentry: # Copyright (c) 2009 Fedora Project /bin/ping: @(#) Copyright (c) 1989 The Regents of the University of California. /bin/ping6: @(#) Copyright (c) 1989 The Regents of the University of California. /bin/pod2usage: # Copyright (c) 1996-2000 by Bradford Appleton. All rights reserved. /bin/qemu-img: qemu-img version 1.5.3, Copyright (c) 2004-2008 Fabrice Bellard /bin/repoclosure: # seth vidal 2005 (c) etc etc /bin/repodiff: # (c) 2007 Red Hat. Written by skvidal@fedoraproject.org /bin/repo-graph: # (c) 2005 Panu Matilainen <pmatilai@laiskiainen.org> /bin/repomanage: # (c) Copyright Seth Vidal 2004 /bin/repoquery: # (c) pmatilai@laiskiainen.org /bin/repo-rss: # seth vidal 2005 (c) etc etc /bin/repotrack: # (c) 2005 seth vidal skvidal at phy.duke.edu /bin/rngtest: Copyright (c) 2004 by Henrique de Moraes Holschuh /bin/saytime: ;; Copyright (c) 1996,1997 ;; /bin/sbcdec: Copyright (c) 2004-2010 Marcel Holtmann /bin/sbcenc: Copyright (c) 2004-2010 Marcel Holtmann /bin/screen: Copyright (c) 2010 Juergen Weigert, Sadrul Habib Chowdhury /bin/screen: Copyright (c) 2008, 2009 Juergen Weigert, Michael Schroeder, Micah Cowan, Sadrul Habib Chowdhury /bin/screen: Copyright (c) 1993-2002, 2003, 2005, 2006, 2007 Juergen Weigert, Michael Schroeder /bin/screen: Copyright (c) 1987 Oliver Laumann /bin/sliceprint: # Copyright (c) 1996-1999 Markku Rossi /bin/soundstretch: Copyright (c) Olli Parviainen /bin/ssh-copy-id: # Copyright (c) 1999-2013 Philip Hands <phil@hands.com> /bin/tcptraceroute: # Copyright (c) 2007 Dmitry Butskoy /bin/tcsh: @(#) Copyright (c) 1991 The Regents of the University of California. /bin/text2wave: ;; Copyright (c) 1996,1997 ;; /bin/traceroute: Copyright (c) 2008 Dmitry Butskoy, License: GPL v2 or any later /bin/traceroute6: Copyright (c) 2008 Dmitry Butskoy, License: GPL v2 or any later /bin/verifytree: # copyright (c) 2008 Red Hat, Inc - written by Seth Vidal and Will Woods /bin/wavpack: Copyright (c) 1998 - 2009 Conifer Software. All Rights Reserved. /bin/wvdial: Copyright (c) 1997-2005 Net Integration Technologies, Inc. /bin/wvdialconf: Copyright (c) 1997-2005 Net Integration Technologies, Inc. /bin/wvgain: Copyright (c) 2005 - 2009 Conifer Software. All Rights Reserved. /bin/wvunpack: Copyright (c) 1998 - 2009 Conifer Software. All Rights Reserved. /bin/yum-debug-dump: ## (c) 2008 Red Hat. Written by skvidal@fedoraproject.org /bin/yum-debug-restore: ## (c) 2008 Red Hat. Written by skvidal@fedoraproject.org /bin/zip: ight (c)H /bin/zip: Copyright (c) 1990-2008 Info-ZIP. All rights reserved. /bin/zip: Copyright (c) 1990-2008 Info-ZIP - Type '%s "-L"' for software license. /bin/zipcloak: Copyright (c) 1990-2008 Info-ZIP. All rights reserved. /bin/zipcloak: Copyright (c) 1990-2008 Info-ZIP - Type '%s "-L"' for software license. /bin/zipnote: Copyright (c) 1990-2008 Info-ZIP. All rights reserved. /bin/zipnote: Copyright (c) 1990-2008 Info-ZIP - Type '%s "-L"' for software license. /bin/zipsplit: Copyright (c) 1990-2008 Info-ZIP. All rights reserved. /bin/zipsplit: Copyright (c) 1990-2008 Info-ZIP - Type '%s "-L"' for software license.
SLES
Used as is, the command extracts all strings greater than 4 characters in length:
SLES12SP1:/tmp # strings /usr/bin/passwd | more /lib64/ld-linux-x86-64.so.2 cHc` libpam.so.0 _ITM_deregisterTMCloneTable __gmon_start__ _Jv_RegisterClasses _ITM_registerTMCloneTable pam_start pam_strerror pam_chauthtok pam_end libpam_misc.so.0 misc_conv libselinux.so.1 _init is_selinux_enabled security_getenforce context_user_get security_compute_av matchpathcon freecon context_free setfscreatecon --More--
Print the offset within the file before each string:
SLES12SP1:/tmp # strings -t d /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 650 cHc` 4977 libpam.so.0 4989 _ITM_deregisterTMCloneTable 5017 __gmon_start__ 5032 _Jv_RegisterClasses 5052 _ITM_registerTMCloneTable 5078 pam_start 5088 pam_strerror 5101 pam_chauthtok 5115 pam_end 5123 libpam_misc.so.0 5140 misc_conv 5150 libselinux.so.1 5166 _init 5172 is_selinux_enabled 5191 security_getenforce 5211 context_user_get 5228 security_compute_av 5248 matchpathcon 5261 freecon 5269 context_free 5282 setfscreatecon --More--
The -t switch can take one of three arguments that specify the numbering system to use:
Argument | Numbering System |
---|---|
d | Decimal |
o | Octal |
x | Hexadecimal |
The -n switch prints sequences of characters that are at least min-len characters long, instead of the default 4:
SLES12SP1:/tmp # strings -t d -n 15 /usr/bin/passwd | more 568 /lib64/ld-linux-x86-64.so.2 4989 _ITM_deregisterTMCloneTable 5032 _Jv_RegisterClasses 5052 _ITM_registerTMCloneTable 5123 libpam_misc.so.0 5150 libselinux.so.1 5172 is_selinux_enabled 5191 security_getenforce 5211 context_user_get 5228 security_compute_av 5510 __stack_chk_fail 5671 __errno_location 6106 __libc_start_main 6202 LIBPAM_MISC_1.0 34104 Usage: %s [options] [LOGIN] 34144 -a, --all report password status on all accounts 34216 -d, --delete delete the password for the named account 34296 -e, --expire force expire the password for the named account 34384 -h, --help display this help message and exit 34456 -k, --keep-tokens change password only if expired 34528 -i, --inactive INACTIVE set password inactive after expiration --More--
The -f switch prints the name of the file before each string:
SLES12SP1:/tmp # strings -f /bin/* | grep "(c)" /bin/btrace: # Copyright (c) 2005 Silicon Graphics, Inc. /bin/csh: @(#) Copyright (c) 1991 The Regents of the University of California. /bin/ping: @(#) Copyright (c) 1989 The Regents of the University of California. /bin/ping6: @(#) Copyright (c) 1989 The Regents of the University of California. /bin/tcsh: @(#) Copyright (c) 1991 The Regents of the University of California.
Command Line Switches
To do : Use the –help option of the strings command to view the command line switches.
The comm Command
This command compares two text files and prints the differences to standard output:
root@debian8:/tmp# comm /etc/passwd /root/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin comm: file 1 is not in sorted order comm: file 2 is not in sorted order proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false trainee10:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin Debian-exim:x:105:110::/var/spool/exim4:/bin/false messagebus:x:106:111::/var/run/dbus:/bin/false statd:x:107:65534::/var/lib/nfs:/bin/false avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin Debian-exim:x:105:110::/var/spool/exim4:/bin/false messagebus:x:106:111::/var/run/dbus:/bin/false statd:x:107:65534::/var/lib/nfs:/bin/false avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false Linux is great!
root@ubuntu1604:/tmp# comm /etc/passwd /root/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin comm: file 1 is not in sorted order comm: file 2 is not in sorted order proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false syslog:x:104:108::/home/syslog:/bin/false _apt:x:105:65534::/nonexistent:/bin/false messagebus:x:106:110::/var/run/dbus:/bin/false uuidd:x:107:111::/run/uuidd:/bin/false lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false whoopsie:x:109:116::/nonexistent:/bin/false avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee10:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin Linux is great! trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin
[root@centos7 tmp]# comm /etc/passwd /root/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin unbound:x:998:997:Unbound DNS resolver:/etc/unbound:/sbin/nologin colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin saslauth:x:996:76:"Saslauthd user":/run/saslauthd:/sbin/nologin qemu:x:107:107:qemu user:/:/sbin/nologin libstoragemgmt:x:995:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin radvd:x:75:75:radvd user:/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin chrony:x:994:993::/var/lib/chrony:/sbin/nologin abrt:x:173:173::/etc/abrt:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee10:x:1000:1000:trainee:/home/trainee:/bin/bash trainee:x:1000:1000:trainee:/home/trainee:/bin/bash tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin comm: file 2 is not in sorted order Linux est super! vboxadd:x:992:1::/var/run/vboxadd:/bin/false comm: file 1 is not in sorted order tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:/tmp # comm /etc/passwd /root/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash messagebus:x:499:499:User for D-Bus:/var/run/dbus:/bin/false news:x:9:13:News system:/etc/news:/bin/bash nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash nscd:x:496:495:User for nscd:/run/nscd:/sbin/nologin ntp:x:74:492:NTP daemon:/var/lib/ntp:/bin/false openslp:x:494:2:openslp daemon:/var/lib/empty:/sbin/nologin polkitd:x:497:496:User for polkitd:/var/lib/polkit:/sbin/nologin postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false pulse:x:490:489:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin root:x:0:0:root:/root:/bin/bash rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin rtkit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false comm: file 1 is not in sorted order comm: file 2 is not in sorted order trainee10:x:1000:100:trainee:/home/trainee:/bin/bash Linux est super trainee:x:1000:100:trainee:/home/trainee:/bin/bash
Important: The lines to the left are those that only appear in the first file. The lines on the right are those that exist in both files. The lines in the middle are those that only exist in the second file.
If you only want to see the lines common to both files, use the following command:
root@debian8:/tmp# comm -12 /etc/passwd /root/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin comm: file 1 is not in sorted order comm: file 2 is not in sorted order proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:/tmp# comm -12 /etc/passwd /root/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin comm: file 1 is not in sorted order comm: file 2 is not in sorted order proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false syslog:x:104:108::/home/syslog:/bin/false _apt:x:105:65534::/nonexistent:/bin/false messagebus:x:106:110::/var/run/dbus:/bin/false uuidd:x:107:111::/run/uuidd:/bin/false lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false whoopsie:x:109:116::/nonexistent:/bin/false avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false
[root@centos7 tmp]# comm -12 /etc/passwd /root/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin unbound:x:998:997:Unbound DNS resolver:/etc/unbound:/sbin/nologin colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin saslauth:x:996:76:"Saslauthd user":/run/saslauthd:/sbin/nologin qemu:x:107:107:qemu user:/:/sbin/nologin libstoragemgmt:x:995:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin radvd:x:75:75:radvd user:/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin chrony:x:994:993::/var/lib/chrony:/sbin/nologin abrt:x:173:173::/etc/abrt:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin comm: file 2 is not in sorted order comm: file 1 is not in sorted order
SLES12SP1:/tmp # comm -12 /etc/passwd /root/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash messagebus:x:499:499:User for D-Bus:/var/run/dbus:/bin/false news:x:9:13:News system:/etc/news:/bin/bash nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash nscd:x:496:495:User for nscd:/run/nscd:/sbin/nologin ntp:x:74:492:NTP daemon:/var/lib/ntp:/bin/false openslp:x:494:2:openslp daemon:/var/lib/empty:/sbin/nologin polkitd:x:497:496:User for polkitd:/var/lib/polkit:/sbin/nologin postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false pulse:x:490:489:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin root:x:0:0:root:/root:/bin/bash rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin rtkit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false comm: file 1 is not in sorted order comm: file 2 is not in sorted order
Command Line Switches
To do : Use the –help option of the comm command to view the command line switches.
The head Command
The head command is used to display the first x lines of a file. The default value of x is 10:
root@debian8:/tmp# head /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
root@ubuntu1604:/tmp# head /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
[root@centos7 tmp]# head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin
SLES12SP1:/tmp # head /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash
You can change the default value of x by using the -n switch:
root@debian8:/tmp# head -n 15 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
root@ubuntu1604:/tmp# head -n 15 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
[root@centos7 tmp]# head -n 15 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin
SLES12SP1:/tmp # head -n 15 /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash messagebus:x:499:499:User for D-Bus:/var/run/dbus:/bin/false news:x:9:13:News system:/etc/news:/bin/bash nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash nscd:x:496:495:User for nscd:/run/nscd:/sbin/nologin ntp:x:74:492:NTP daemon:/var/lib/ntp:/bin/false
The command can also be used to display the first y bytes of a file by using the -c switch:
root@debian8:/tmp# head -c 150 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/noloroot@debian8:/tmp#
root@ubuntu1604:/tmp# head -c 150 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/noloroot@ubuntu1604:/tmp#
[root@centos7 tmp]# head -c 150 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7[root@centos7 tmp]#
SLES12SP1:/tmp # head -c 150 /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srvSLES12SP1:/tmp #
If the value of y is negative, head displays all bytes in the file except the last y bytes:
root@debian8:/tmp# head -c -150 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin Debian-exim:x:105:110::/var/spool/exim4:/bin/false messagebus:x:106:111::/var/run/dbus:/bin/false statd:x:107:65534::/var/lib/nfs:/bin/false avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false
root@ubuntu1604:/tmp# head -c 150 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/noloroot@ubuntu1604:/tmp# root@ubuntu1604:/tmp# head -c -150 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false syslog:x:104:108::/home/syslog:/bin/false _apt:x:105:65534::/nonexistent:/bin/false messagebus:x:106:110::/var/run/dbus:/bin/false uuidd:x:107:111::/run/uuidd:/bin/false lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false whoopsie:x:109:116::/nonexistent:/bin/false avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46root@ubuntu1604:/tmp#
lp:x:4:7[root@centos7 tmp]# head -c -150 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin unbound:x:998:997:Unbound DNS resolver:/etc/unbound:/sbin/nologin colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin saslauth:x:996:76:"Saslauthd user":/run/saslauthd:/sbin/nologin qemu:x:107:107:qemu user:/:/sbin/nologin libstoragemgmt:x:995:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin radvd:x:75:75:radvd user:/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin chrony:x:994:993::/var/lib/chrony:/sbin/nologin abrt:x:173:173::/etc/abrt:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee:x:1000:1000:trainee:/home/trainee:/bin/[root@centos7 tmp]#
SLES12SP1:/tmp # head -c -150 /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash messagebus:x:499:499:User for D-Bus:/var/run/dbus:/bin/false news:x:9:13:News system:/etc/news:/bin/bash nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash nscd:x:496:495:User for nscd:/run/nscd:/sbin/nologin ntp:x:74:492:NTP daemon:/var/lib/ntp:/bin/false openslp:x:494:2:openslp daemon:/var/lib/empty:/sbin/nologin polkitd:x:497:496:User for polkitd:/var/lib/polkit:/sbin/nologin postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false pulse:x:490:489:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin root:x:0:0:root:/root:/bin/bash rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin rtkit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash vnc:x:492:491:usSLES12SP1:/tmp #
Both x and y can accept multipliers:
root@debian8:/tmp# head -c 1b /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nroot@debian8:/tmp# root@debian8:/tmp# root@debian8:/tmp# head -c 512 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nroot@debian8:/tmp#
root@ubuntu1604:/tmp# head -c 1b /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nroot@ubuntu1604:/tmp# root@ubuntu1604:/tmp# root@ubuntu1604:/tmp# head -c 512 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nroot@ubuntu1604:/tmp
[root@centos7 tmp]# head -c 1b /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin[root@centos7 tmp]# [root@centos7 tmp]# head -c 512 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin[root@centos7 tmp]#
SLES12SP1:/tmp # head -c 1b /etc/passwd at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/basSLES12SP1:/tmp #
The common multipliers are:
Multiplier | Number of bytes |
---|---|
b | 512 |
KB | 1000 |
K | 1024 |
MB | 1000*1000 |
M | 1024*1024 |
GB | 1000*1000*1000 |
G | 1024*1024*1024 |
Command Line Switches
To do : Use the –help option of the head command to view the command line switches.
The tail Command
The tail command is used to display the last x lines of a file. The default value of x is 10:
root@debian8:/tmp# tail /etc/passwd avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:/tmp# tail /etc/passwd colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nolog
[root@centos7 tmp]# tail /etc/passwd abrt:x:173:173::/etc/abrt:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee:x:1000:1000:trainee:/home/trainee:/bin/bash vboxadd:x:992:1::/var/run/vboxadd:/bin/false tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:/tmp # tail /etc/passwd rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin rtkit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false trainee:x:1000:100:trainee:/home/trainee:/bin/bash
You can change the default value of x by using the -n switch:
root@debian8:/tmp# tail -n 15 /etc/passwd trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin Debian-exim:x:105:110::/var/spool/exim4:/bin/false messagebus:x:106:111::/var/run/dbus:/bin/false statd:x:107:65534::/var/lib/nfs:/bin/false avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:/tmp# tail -n 15 /etc/passwd lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false whoopsie:x:109:116::/nonexistent:/bin/false avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin
[root@centos7 tmp]# tail -n 15 /etc/passwd nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin radvd:x:75:75:radvd user:/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin chrony:x:994:993::/var/lib/chrony:/sbin/nologin abrt:x:173:173::/etc/abrt:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee:x:1000:1000:trainee:/home/trainee:/bin/bash vboxadd:x:992:1::/var/run/vboxadd:/bin/false tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:/tmp # tail -n 15 /etc/passwd openslp:x:494:2:openslp daemon:/var/lib/empty:/sbin/nologin polkitd:x:497:496:User for polkitd:/var/lib/polkit:/sbin/nologin postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false pulse:x:490:489:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin root:x:0:0:root:/root:/bin/bash rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin rtkit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false trainee:x:1000:100:trainee:/home/trainee:/bin/bash
The command can also be used to display the last y bytes of a file by using the -c switch:
root@debian8:/tmp# tail -c 150 /etc/passwd /lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:/tmp# tail -c 150 /etc/passwd :usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin
[root@centos7 tmp]# tail -c 150 /etc/passwd bash vboxadd:x:992:1::/var/run/vboxadd:/bin/false tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:/tmp # tail -c 150 /etc/passwd er for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false trainee:x:1000:100:trainee:/home/trainee:/bin/bash
If the value of y is positive, tail displays all bytes in the file after the yth byte:
root@debian8:/tmp# tail -c +150 /etc/passwd ogin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin Debian-exim:x:105:110::/var/spool/exim4:/bin/false messagebus:x:106:111::/var/run/dbus:/bin/false statd:x:107:65534::/var/lib/nfs:/bin/false avahi-autoipd:x:108:113:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:109:115:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:/tmp# tail -c +150 /etc/passwd ogin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false syslog:x:104:108::/home/syslog:/bin/false _apt:x:105:65534::/nonexistent:/bin/false messagebus:x:106:110::/var/run/dbus:/bin/false uuidd:x:107:111::/run/uuidd:/bin/false lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false whoopsie:x:109:116::/nonexistent:/bin/false avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin
[root@centos7 tmp]# tail -c +150 /etc/passwd 7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin unbound:x:998:997:Unbound DNS resolver:/etc/unbound:/sbin/nologin colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin saslauth:x:996:76:"Saslauthd user":/run/saslauthd:/sbin/nologin qemu:x:107:107:qemu user:/:/sbin/nologin libstoragemgmt:x:995:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin radvd:x:75:75:radvd user:/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin chrony:x:994:993::/var/lib/chrony:/sbin/nologin abrt:x:173:173::/etc/abrt:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee:x:1000:1000:trainee:/home/trainee:/bin/bash vboxadd:x:992:1::/var/run/vboxadd:/bin/false tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:/tmp # tail -c 150 /etc/passwd er for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false trainee:x:1000:100:trainee:/home/trainee:/bin/bash SLES12SP1:/tmp # tail -c +150 /etc/passwd v/ftp:/bin/bash ftpsecure:x:488:65534:Secure FTP User:/var/lib/empty:/bin/false games:x:12:100:Games account:/var/games:/bin/bash gdm:x:486:485:Gnome Display Manager daemon:/var/lib/gdm:/bin/false lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash messagebus:x:499:499:User for D-Bus:/var/run/dbus:/bin/false news:x:9:13:News system:/etc/news:/bin/bash nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash nscd:x:496:495:User for nscd:/run/nscd:/sbin/nologin ntp:x:74:492:NTP daemon:/var/lib/ntp:/bin/false openslp:x:494:2:openslp daemon:/var/lib/empty:/sbin/nologin polkitd:x:497:496:User for polkitd:/var/lib/polkit:/sbin/nologin postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false pulse:x:490:489:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin root:x:0:0:root:/root:/bin/bash rpc:x:495:65534:user for rpcbind:/var/lib/empty:/sbin/nologin rtkit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false trainee:x:1000:100:trainee:/home/trainee:/bin/bash
Both x and y can accept multipliers:
root@debian8:/tmp# tail -c 1b /etc/passwd :/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false root@debian8:/tmp# root@debian8:/tmp# tail -c 512 /etc/passwd :/bin/false colord:x:110:117:colord colour management daemon,,,:/var/lib/colord:/bin/false dnsmasq:x:111:65534:dnsmasq,,,:/var/lib/misc:/bin/false speech-dispatcher:x:112:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh pulse:x:113:119:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:114:121:RealtimeKit,,,:/proc:/bin/false saned:x:115:122::/var/lib/saned:/bin/false usbmux:x:116:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false lightdm:x:117:124:Light Display Manager:/var/lib/lightdm:/bin/false
root@ubuntu1604:/tmp# tail -c 1b /etc/passwd :114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin root@ubuntu1604:/tmp# root@ubuntu1604:/tmp# tail -c 512 /etc/passwd :114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false trainee:x:1000:1000:trainee,,,:/home/trainee:/bin/bash sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin
[root@centos7 tmp]# tail -c 1b /etc/passwd PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee:x:1000:1000:trainee:/home/trainee:/bin/bash vboxadd:x:992:1::/var/run/vboxadd:/bin/false tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin [root@centos7 tmp]# [root@centos7 tmp]# tail -c 512 /etc/passwd PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin trainee:x:1000:1000:trainee:/home/trainee:/bin/bash vboxadd:x:992:1::/var/run/vboxadd:/bin/false tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
SLES12SP1:/tmp # tail -c 1b /etc/passwd kit:x:491:490:RealtimeKit:/proc:/bin/false scard:x:487:487:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin sshd:x:498:498:SSH daemon:/var/lib/sshd:/bin/false statd:x:489:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin usbmux:x:493:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash vnc:x:492:491:user for VNC:/var/lib/empty:/sbin/nologin wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false trainee:x:1000:100:trainee:/home/trainee:/bin/bash
The common multipliers are:
Multiplier | Number of bytes |
---|---|
b | 512 |
KB | 1000 |
K | 1024 |
MB | 1000*1000 |
M | 1024*1024 |
GB | 1000*1000*1000 |
G | 1024*1024*1024 |
A useful switch to use with the tail command is -f. This switch continually updates the output:
root@debian8:/tmp# tail -f /var/log/messages Nov 30 16:19:14 debian8 kernel: [182064.453711] usb 2-1: new full-speed USB device number 4 using ohci-pci Nov 30 16:19:14 debian8 kernel: [182064.716207] usb 2-1: New USB device found, idVendor=80ee, idProduct=0021 Nov 30 16:19:14 debian8 kernel: [182064.716213] usb 2-1: New USB device strings: Mfr=1, Product=3, SerialNumber=0 Nov 30 16:19:14 debian8 kernel: [182064.716215] usb 2-1: Product: USB Tablet Nov 30 16:19:14 debian8 kernel: [182064.716217] usb 2-1: Manufacturer: VirtualBox Nov 30 16:19:14 debian8 kernel: [182064.732384] input: VirtualBox USB Tablet as /devices/pci0000:00/0000:00:06.0/usb2/2-1/2-1:1.0/0003:80EE:0021.0003/input/input9 Nov 30 16:19:14 debian8 mtp-probe: checking bus 2, device 4: "/sys/devices/pci0000:00/0000:00:06.0/usb2/2-1" Nov 30 16:19:14 debian8 mtp-probe: bus: 2, device: 4 was not an MTP device Nov 30 16:19:14 debian8 kernel: [182064.734594] hid-generic 0003:80EE:0021.0003: input,hidraw0: USB HID v1.10 Mouse [VirtualBox USB Tablet] on usb-0000:00:06.0-1/input0 Nov 30 16:19:20 debian8 kernel: [182070.401997] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX ^C
root@ubuntu1604:/tmp# tail -f /var/log/syslog Dec 17 13:22:35 ubuntu1604 sh[870]: Sleeping '888' '888' Dec 17 14:16:59 ubuntu1604 sh[870]: message repeated 465 times: [ Sleeping '888' '888'] Dec 17 14:17:01 ubuntu1604 CRON[17224]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly) Dec 17 14:17:06 ubuntu1604 sh[870]: Sleeping '888' '888' Dec 17 15:17:00 ubuntu1604 sh[870]: message repeated 512 times: [ Sleeping '888' '888'] Dec 17 15:17:01 ubuntu1604 CRON[30516]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly) Dec 17 15:17:07 ubuntu1604 sh[870]: Sleeping '888' '888' Dec 17 15:30:00 ubuntu1604 sh[870]: message repeated 110 times: [ Sleeping '888' '888'] Dec 17 15:30:00 ubuntu1604 systemd[1]: snapd.refresh.timer: Adding 4h 29min 43.172868s random time. Dec 17 15:30:07 ubuntu1604 sh[870]: Sleeping '888' '888' ^C
[root@centos7 tmp]# tail -f /var/log/messages Oct 19 15:58:06 centos7 dbus-daemon: dbus[542]: [system] Activating service name='org.freedesktop.PackageKit' (using servicehelper) Oct 19 15:58:06 centos7 dbus[542]: [system] Activating service name='org.freedesktop.PackageKit' (using servicehelper) Oct 19 15:58:06 centos7 dbus-daemon: dbus[542]: [system] Successfully activated service 'org.freedesktop.PackageKit' Oct 19 15:58:06 centos7 dbus[542]: [system] Successfully activated service 'org.freedesktop.PackageKit' Oct 19 16:00:01 centos7 systemd: Created slice user-0.slice. Oct 19 16:00:01 centos7 systemd: Starting Session 17 of user root. Oct 19 16:00:01 centos7 systemd: Started Session 17 of user root. Oct 19 16:01:01 centos7 systemd: Created slice user-0.slice. Oct 19 16:01:01 centos7 systemd: Starting Session 18 of user root. Oct 19 16:01:01 centos7 systemd: Started Session 18 of user root. ^C
SLES12SP1:/tmp # tail -f /var/log/messages 2016-12-14T20:45:01.238708+01:00 SLES12SP1 systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0) 2016-12-14T20:45:01.275146+01:00 SLES12SP1 CRON[17392]: pam_unix(crond:session): session closed for user root 2016-12-14T20:45:01.288315+01:00 SLES12SP1 systemd: pam_unix(systemd-user:session): session closed for user root 2016-12-14T20:45:41.689270+01:00 SLES12SP1 sh[1320]: Sleeping '' '' 2016-12-14T20:58:07.757988+01:00 SLES12SP1 sh[1320]: message repeated 4 times: [ Sleeping '' ''] 2016-12-14T21:00:01.284105+01:00 SLES12SP1 cron[23239]: pam_unix(crond:session): session opened for user root by (uid=0) 2016-12-14T21:00:01.291722+01:00 SLES12SP1 systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0) 2016-12-14T21:00:01.338305+01:00 SLES12SP1 CRON[23239]: pam_unix(crond:session): session closed for user root 2016-12-14T21:00:01.351426+01:00 SLES12SP1 systemd: pam_unix(systemd-user:session): session closed for user root 2016-12-14T21:01:14.285113+01:00 SLES12SP1 sh[1320]: Sleeping '' '' ^C
Command Line Switches
To do : Use the –help option of the head command to view the command line switches.
LAB #4 - Use the grep, tr and cut to extract your IP address from the output of ifconfig
root@debian8:/tmp# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 08:00:27:c4:c9:56 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fec4:c956/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:68601 errors:0 dropped:0 overruns:0 frame:0 TX packets:140516 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8392325 (8.0 MiB) TX bytes:10525989 (10.0 MiB) root@debian8:/tmp# ifconfig eth0 | grep "inet" inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fec4:c956/64 Scope:Link root@debian8:/tmp# ifconfig eth0 | grep "inet" | grep -v "inet6" inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 root@debian8:/tmp# ifconfig eth0 | grep "inet" | grep -v "inet6" | tr -s " " ":" :inet:addr:10.0.2.15:Bcast:10.0.2.255:Mask:255.255.255.0 root@debian8:/tmp# ifconfig eth0 | grep "inet" | grep -v "inet6" | tr -s " " ":" | cut -d: -f4 10.0.2.15
root@ubuntu1604:/tmp# ifconfig enp0s3 enp0s3 Link encap:Ethernet HWaddr 08:00:27:20:4b:97 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::c4db:2b29:aedd:e7ed/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:230127 errors:0 dropped:0 overruns:0 frame:0 TX packets:149877 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:238004530 (238.0 MB) TX bytes:10864892 (10.8 MB) root@ubuntu1604:/tmp# ifconfig enp0s3 | grep "inet" inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::c4db:2b29:aedd:e7ed/64 Scope:Link root@ubuntu1604:/tmp# ifconfig enp0s3 | grep "inet" | grep -v "inet6" inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 root@ubuntu1604:/tmp# ifconfig enp0s3 | grep "inet" | grep -v "inet6" | tr -s " " ":" :inet:addr:10.0.2.15:Bcast:10.0.2.255:Mask:255.255.255.0 root@ubuntu1604:/tmp# ifconfig enp0s3 | grep "inet" | grep -v "inet6" | tr -s " " ":" | cut -d: -f4 10.0.2.15
[root@centos7 tmp]# ifconfig enp0s3 enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:febd:f523 prefixlen 64 scopeid 0x20<link> ether 08:00:27:bd:f5:23 txqueuelen 1000 (Ethernet) RX packets 7462 bytes 6158140 (5.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4130 bytes 555287 (542.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@centos7 tmp]# ifconfig enp0s3 | grep "inet" inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:febd:f523 prefixlen 64 scopeid 0x20<link> [root@centos7 tmp]# ifconfig enp0s3 | grep "inet" | grep -v "inet6" inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 [root@centos7 tmp]# ifconfig enp0s3 | grep "inet" | grep -v "inet6" | tr -s " " ":" :inet:10.0.2.15:netmask:255.255.255.0:broadcast:10.0.2.255 [root@centos7 tmp]# ifconfig enp0s3 | grep "inet" | grep -v "inet6" | tr -s " " ":" | cut -d: -f3 10.0.2.15
SLES12SP1:/tmp # ifconfig eth0 eth0 Link encap:Ethernet HWaddr 08:00:27:10:B5:86 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe10:b586/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8226 errors:0 dropped:0 overruns:0 frame:0 TX packets:16490 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:588832 (575.0 Kb) TX bytes:1303594 (1.2 Mb) SLES12SP1:/tmp # ifconfig eth0 | grep "inet" inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe10:b586/64 Scope:Link SLES12SP1:/tmp # ifconfig eth0 | grep "inet" | grep -v "inet6" inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 SLES12SP1:/tmp # ifconfig eth0 | grep "inet" | grep -v "inet6" | tr -s " " ":" :inet:addr:10.0.2.15:Bcast:10.0.2.255:Mask:255.255.255.0 SLES12SP1:/tmp # ifconfig eth0 | grep "inet" | grep -v "inet6" | tr -s " " ":" | cut -d: -f4 10.0.2.15
Important : Note the use of the -s switch with the tr command. This switch replaces a string of x identical characters with a single character.
<html>
Copyright © 2011-2017 Hugh Norris.<br><br> <a rel=“license” href=“http://creativecommons.org/licenses/by-nc-nd/3.0/”><img alt=“Creative Commons License” style=“border-width:0” src=“https://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png” /></a><br />This work is licensed under a <a rel=“license” href=“http://creativecommons.org/licenses/by-nc-nd/3.0/”>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>
</html>