linux sudo

$ sudo -V
Display the version of sudo command currently used.

[vagrant@localhost ~]$ sudo -V
Sudo バージョン 1.8.6p3
Sudoers policy plugin version 1.8.6p3
Sudoers file grammar version 42
Sudoers I/O plugin version 1.8.6p3
ん、なんだこれ?

$ sudo -l
Display command that the user can (or cannot) do on the current host by using the sudo command.

[vagrant@localhost ~]$ sudo -l
このホスト上でユーザー vagrant
に一致したデフォルト項目:
!visiblepw, always_set_home, env_reset, env_keep=”COLORS DISPLAY
HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS”, env_keep+=”MAIL PS1 PS2
QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE”, env_keep+=”LC_COLLATE
LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES”,
env_keep+=”LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE”,
env_keep+=”LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY”,
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin

ユーザー vagrant
は次のコマンドをこのホスト上で実行できます:
(ALL) NOPASSWD: ALL

$ sudo -h
Display help for sudo command.

$ sudo -u username hoge
Execute hoge command as a username

なんか、この辺は知らんとモグリと思われるな。

linuxでの操作

[vagrant@localhost test]$ WORK_DIR=work/$(date +%Y)/$(date +%m%d)_crontab
[vagrant@localhost test]$ ls
[vagrant@localhost test]$ mkdir -p ${WORK_DIR}
[vagrant@localhost test]$ ls
work
[vagrant@localhost test]$ ls
work
[vagrant@localhost test]$ cd work
[vagrant@localhost work]$ ls
2019
[vagrant@localhost work]$ cd 2019
[vagrant@localhost 2019]$ ls
0327_crontab
[vagrant@localhost 2019]$ cd 0327_crontab
[vagrant@localhost 0327_crontab]$ ls
[vagrant@localhost 0327_crontab]$ crontab -l > crontab.old
no crontab for vagrant

なるほど、コマンドラインでも変数として扱えるのね。ほう。

dateコマンド

[vagrant@localhost ~]$ date
2019年 3月 26日 火曜日 09:15:51 JST
[vagrant@localhost ~]$ date “+%Y%m%d-%H%M%S”
20190326-091709

ふむ。

ps -aef

ps: Check the processes currently running on Linux

a: display the process of terminal operation
f(option -h, option-forest): display processes in a hierarchy
e: display the command name and environment, variables being executed.

[vagrant@localhost ~]$ ps -aef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar24 ? 00:00:00 /sbin/init
root 2 0 0 Mar24 ? 00:00:00 [kthreadd]
root 3 2 0 Mar24 ? 00:00:00 [migration/0]
root 4 2 0 Mar24 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 Mar24 ? 00:00:00 [stopper/0]
root 6 2 0 Mar24 ? 00:00:00 [watchdog/0]
root 7 2 0 Mar24 ? 00:01:54 [events/0]
root 8 2 0 Mar24 ? 00:00:00 [events/0]
root 9 2 0 Mar24 ? 00:00:00 [events_long/0]
root 10 2 0 Mar24 ? 00:00:00 [events_power_ef]
root 11 2 0 Mar24 ? 00:00:00 [cgroup]
root 12 2 0 Mar24 ? 00:00:00 [khelper]
root 13 2 0 Mar24 ? 00:00:00 [netns]
root 14 2 0 Mar24 ? 00:00:00 [async/mgr]
root 15 2 0 Mar24 ? 00:00:00 [pm]
root 16 2 0 Mar24 ? 00:00:00 [sync_supers]
root 17 2 0 Mar24 ? 00:00:00 [bdi-default]
root 18 2 0 Mar24 ? 00:00:00 [kintegrityd/0]
root 19 2 0 Mar24 ? 00:00:03 [kblockd/0]
root 20 2 0 Mar24 ? 00:00:00 [kacpid]
root 21 2 0 Mar24 ? 00:00:00 [kacpi_notify]
root 22 2 0 Mar24 ? 00:00:00 [kacpi_hotplug]
root 23 2 0 Mar24 ? 00:00:00 [ata_aux]
root 24 2 0 Mar24 ? 00:00:00 [ata_sff/0]
root 25 2 0 Mar24 ? 00:00:00 [ksuspend_usbd]
root 26 2 0 Mar24 ? 00:00:00 [khubd]
root 27 2 0 Mar24 ? 00:00:00 [kseriod]
root 28 2 0 Mar24 ? 00:00:00 [md/0]
root 29 2 0 Mar24 ? 00:00:00 [md_misc/0]
root 30 2 0 Mar24 ? 00:00:00 [linkwatch]
root 33 2 0 Mar24 ? 00:00:00 [khungtaskd]
root 34 2 0 Mar24 ? 00:00:00 [lru-add-drain/0]
root 35 2 0 Mar24 ? 00:00:01 [kswapd0]
root 36 2 0 Mar24 ? 00:00:00 [ksmd]
root 37 2 0 Mar24 ? 00:00:00 [aio/0]
root 38 2 0 Mar24 ? 00:00:00 [crypto/0]
root 45 2 0 Mar24 ? 00:00:00 [kthrotld/0]
root 47 2 0 Mar24 ? 00:00:00 [kpsmoused]
root 48 2 0 Mar24 ? 00:00:00 [usbhid_resumer]
root 49 2 0 Mar24 ? 00:00:00 [deferwq]
root 81 2 0 Mar24 ? 00:00:00 [kdmremove]
root 82 2 0 Mar24 ? 00:00:00 [kstriped]
root 186 2 0 Mar24 ? 00:00:00 [scsi_eh_0]
root 188 2 0 Mar24 ? 00:00:00 [scsi_eh_1]
root 214 2 0 Mar24 ? 00:00:00 [scsi_eh_2]
root 262 2 0 Mar24 ? 00:00:00 [kdmflush]
root 264 2 0 Mar24 ? 00:00:00 [kdmflush]
root 332 2 0 Mar24 ? 00:00:02 [jbd2/dm-0-8]
root 333 2 0 Mar24 ? 00:00:00 [ext4-dio-unwrit]
root 338 2 0 Mar24 ? 00:00:01 [flush-253:0]
root 409 1 0 Mar24 ? 00:00:00 /sbin/udevd -d
root 513 2 0 Mar24 ? 00:00:00 [iprt-VBoxWQueue]
root 708 2 0 Mar24 ? 00:00:00 [jbd2/sda1-8]
root 709 2 0 Mar24 ? 00:00:00 [ext4-dio-unwrit]
root 771 2 0 Mar24 ? 00:00:00 [kauditd]
root 963 1 0 Mar24 ? 00:00:00 /sbin/dhclient -1 -q -cf /etc/dh
root 1148 1 0 Mar24 ? 00:00:00 auditd
root 1170 1 0 Mar24 ? 00:00:00 /sbin/rsyslogd -i /var/run/syslo
rpc 1192 1 0 Mar24 ? 00:00:00 rpcbind
rpcuser 1214 1 0 Mar24 ? 00:00:00 rpc.statd
root 1318 1 0 Mar24 ? 00:00:46 /usr/sbin/VBoxService –pidfile
root 1357 1 0 Mar24 ? 00:00:00 /usr/sbin/sshd
root 1392 1 0 Mar24 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe –d
mysql 1632 1392 0 Mar24 ? 00:01:03 /usr/sbin/mysqld –basedir=/usr
root 2246 1 0 Mar24 ? 00:00:00 /usr/libexec/postfix/master
postfix 2250 2246 0 Mar24 ? 00:00:00 qmgr -l -t fifo -u
root 2370 1 0 Mar24 ? 00:00:06 /usr/sbin/httpd
root 2614 1 0 Mar24 ? 00:00:00 crond
jenkins 3741 1 0 Mar24 ? 00:05:14 /etc/alternatives/java -Dcom.sun
root 4085 1 0 Mar24 tty1 00:00:00 /sbin/mingetty /dev/tty1
root 4087 1 0 Mar24 tty2 00:00:00 /sbin/mingetty /dev/tty2
root 4091 1 0 Mar24 tty3 00:00:00 /sbin/mingetty /dev/tty3
root 4096 1 0 Mar24 tty4 00:00:00 /sbin/mingetty /dev/tty4
root 4098 1 0 Mar24 tty5 00:00:00 /sbin/mingetty /dev/tty5
root 4100 1 0 Mar24 tty6 00:00:00 /sbin/mingetty /dev/tty6
root 4132 409 0 Mar24 ? 00:00:00 /sbin/udevd -d
root 4133 409 0 Mar24 ? 00:00:00 /sbin/udevd -d
root 10290 1357 0 18:51 ? 00:00:00 sshd: vagrant [priv]
vagrant 10292 10290 0 18:51 ? 00:00:00 sshd: vagrant@notty
vagrant 10293 10292 0 18:51 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 10300 1357 0 18:53 ? 00:00:00 sshd: vagrant [priv]
vagrant 10302 10300 0 18:53 ? 00:00:00 sshd: vagrant@notty
vagrant 10303 10302 0 18:53 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 10320 1357 0 19:04 ? 00:00:00 sshd: vagrant [priv]
vagrant 10322 10320 0 19:04 ? 00:00:00 sshd: vagrant@pts/0
vagrant 10323 10322 0 19:04 pts/0 00:00:00 -bash
postfix 10798 2246 0 19:47 ? 00:00:00 pickup -l -t fifo -u
apache 10930 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10931 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10932 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10933 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10934 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10935 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10936 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
apache 10937 2370 0 19:54 ? 00:00:00 /usr/sbin/httpd
root 11000 1357 0 20:21 ? 00:00:00 sshd: vagrant [priv]
vagrant 11002 11000 0 20:21 ? 00:00:00 sshd: vagrant@pts/1
vagrant 11003 11002 0 20:21 pts/1 00:00:00 -bash
vagrant 11425 11003 0 20:26 pts/1 00:00:00 ps -aef

なにこれ?こんなに走ってるの? httpdぐらいかと思ったらww

さー今日は225が-700くらい付けてますが、今日も頑張りますかー

Linux “hostname”

“Hostname” is a command to display the host name of the system. If you are the root user(superuser), you can also change the host name.

[vagrant@localhost ~]$ hostname
localhost.localdomain

[vagrant@localhost ~]$ sudo -S “hostname”
localhost.localdomain

egrep i

egrep [option][search string pattern] filename

Search for files with a search string pattern and a command to output matching lines.
Search for [File] with [Search string pattern] and output matching lines.
You can use regular expressions more advanced than grep.

まず適すとファイルを作ります。
yahoo.txt

1	8411	東証1部	(株)みずほフィナンシャルグループ	03/20	175.5	+0.75%	+1.3	106,216,600	掲示板
2	5020	東証1部	JXTGホールディングス(株)	03/20	542.9	+0.37%	+2	42,028,800	掲示板
3	8306	東証1部	(株)三菱UFJフィナンシャル・グループ	03/20	573.3	-0.26%	-1.5	33,412,300	掲示板
4	3765	東証1部	ガンホー・オンライン・エンターテイメント(株)	03/20	405	+5.74%	+22	31,808,200	掲示板
5	4347	東証JQS	ブロードメディア(株)	03/20	94	+9.30%	+8	29,353,800	掲示板
6	4755	東証1部	楽天(株)	03/20	1,011	+4.12%	+40	22,479,800	掲示板
7	9973	東証JQS	(株)小僧寿し	03/20	62	+44.19%	+19	18,652,400	掲示板
8	8604	東証1部	野村ホールディングス(株)	03/20	409.9	-2.24%	-9.4	18,591,800	掲示板
9	3092	東証1部	(株)ZOZO	03/20	2,025	+1.25%	+25	18,435,700	掲示板
10	4565	マザーズ	そーせいグループ(株)	03/20	1,421	+15.91%	+195	18,249,700	掲示板

続いて、egrep -i

[vagrant@localhost tests]$ egrep -i "グループ" yahoo.txt
1       8411    東証1部 (株)みずほフィナンシャルグループ        03/20   175.5  +0.75%   +1.3    106,216,600     掲示板
3       8306    東証1部 (株)三菱UFJフィナンシャル・グループ  03/20   573.3  -0.26%   -1.5    33,412,300      掲示板
10      4565    マザーズ        そーせいグループ(株)    03/20   1,421   +15.91%+195     18,249,700      掲示板

ほう。

pgrep httpd

pgrep
It is a command to search for process ID using a pattern that represents process name, user group, terminal name, etc. among running processes. You can use exetnded regular expression(10th) for patterns.

You can also use the pidof command to find the process ID from the command name.

[vagrant@localhost tests]$ pgrep httpd
1779
2082
2083
2084
2085
2086
2087
2088
2089

この数字はプロセスIDですな。

ls -t

ls -t: Sort and display in time stamp order.

[vagrant@localhost tests]$ touch index.php
[vagrant@localhost tests]$ ls -t
index.php backup beforeinstall.sh codedeploy
[vagrant@localhost tests]$ ls
backup beforeinstall.sh codedeploy index.php

なるほど~
[vagrant@localhost tests]$ ls -l | tail -n+2
drwxrwxr-x 3 vagrant vagrant 4096 3月 17 20:41 2019 backup
-rwxr-xr-x 1 vagrant vagrant 422 3月 17 20:41 2019 beforeinstall.sh
drwxr-xr-x 3 vagrant vagrant 4096 3月 17 11:04 2019 codedeploy
-rw-rw-r– 1 vagrant vagrant 0 3月 18 08:36 2019 index.php

If not specified, 10 lines from the last line will be displayed, but with the -n option, the specified number of lines will be output.

[vagrant@localhost tests]$ ls -t | tail -n+1
index.php
backup
beforeinstall.sh
codedeploy
[vagrant@localhost tests]$ ls -t | tail -n+4
codedeploy
[vagrant@localhost tests]$ ls -t | tail -n+3
beforeinstall.sh
codedeploy
[vagrant@localhost tests]$ ls -t | tail -n+2
backup
beforeinstall.sh
codedeploy

にゃるほどー

umask

Normally, if you create a 0 byte file by specifying “touch ${filename}” etc, the permission should be created as 644(rw-r–r-). If files or directories to be created are 666(rw-rw-rw-) or 777(rwxrwxrwx), all users can write and delete them.

In this way, “umask” controls the permissions of newly created files and directories.

[vagrant@localhost ~]$ umask
0002

時と場合によるが、やはりデフォルトは644で良いように思いますな。

xlib, libX11, libXext, libXi, libXrender, libXtst

Xlib is a library for clients of X window system, written in C language. Includes subroutines that interact with the X server. By using these subroutines, it is possible to write programs without knowing the details of the X protocol.

[vagrant@localhost ~]$ yum list installed | grep xlib
[vagrant@localhost ~]$

[vagrant@localhost ~]$ yum list installed | grep libX11
libX11.x86_64 1.6.4-3.el6 @base
libX11-common.noarch 1.6.4-3.el6 @base

[vagrant@localhost ~]$ yum list installed | grep libXext
libXext.x86_64 1.3.3-1.el6 @base

[vagrant@localhost ~]$ yum list installed | grep libXi
libXi.x86_64 1.7.8-1.el6 @base

[vagrant@localhost ~]$ yum list installed | grep libXrender
libXrender.x86_64 0.9.10-1.el6 @base

[vagrant@localhost ~]$ yum list installed | grep libXtst
libXtst.x86_64 1.2.3-1.el6 @base

[vagrant@localhost ~]$ yum list installed | grep libjpeg-turbo
libjpeg-turbo.x86_64 1.2.1-3.el6_5 @base
[vagrant@localhost ~]$ yum list installed | grep libpng
libpng.x86_64 2:1.2.49-2.el6_7 @base
[vagrant@localhost ~]$ yum list installed | grep tzdata-java
tzdata-java.noarch 2018f-1.el6 @updates