Unix “ln” command

“ln” is a command to create a file link. Although you can create a hard link with “in file name link name”, it is more general to use a “-s” option and create a symbolic link as “ln -s file name link name”.

With “ln -s”, you can create a “symbolic link” of the file. A symbolic link is a so-colled “alias” of a file, giving a different name to a long file name or making it easier to handle a file in a place where it is difficult to specify a path name.

[vagrant@localhost symbolic]$ ls
mylist01.txt mylist02.txt

The “-l” option is a frequently used command. “L” means a long format. Just as long as it displays details, it becomes landscape.

[vagrant@localhost symbolic]$ ls -l
合計 0
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist01.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist02.txt

Create a symbolic link named “latest” in “mylist02.txt” with “ln -s” command.
[vagrant@localhost symbolic]$ ln -s mylist02.txt latest
[vagrant@localhost symbolic]$ ls -l
合計 0
lrwxrwxrwx 1 vagrant vagrant 12 1月 27 16:47 2019 latest -> mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist01.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist02.txt

[vagrant@localhost symbolic]$ ls -l
合計 0
lrwxrwxrwx 1 vagrant vagrant 12 1月 27 16:47 2019 latest -> mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist01.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:50 2019 mylist03.txt

[vagrant@localhost symbolic]$ ln -sb text03.txt latest
[vagrant@localhost symbolic]$ ls -l
合計 0
lrwxrwxrwx 1 vagrant vagrant 10 1月 27 16:51 2019 latest -> text03.txt
lrwxrwxrwx 1 vagrant vagrant 12 1月 27 16:47 2019 latest~ -> mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist01.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:50 2019 mylist03.txt

In “ln -s” you can also create a link to nonexistent file.
[vagrant@localhost symbolic]$ ls
backupdir latest latest~ mylist01.txt mylist02.txt mylist03.txt
[vagrant@localhost symbolic]$ cd backupdir
[vagrant@localhost backupdir]$ ln -s ../.bashrc bashrc0518
[vagrant@localhost backupdir]$ ls
bashrc0518

What is dat file?

If dat is an extension, it is somewhat a data file, but don’t know what the data is, because “dat” has no fixed format.

In unix you can use “file command”. Since this command actually judges by looking at the contents of the file, it gets a little better answer.

data1.dat

data1

[vagrant@localhost app]$ file data1.dat
data1.dat: ASCII text, with no line terminators

Linux grep option -e

What is linux grep option -e

The -e option is used to search for “or”.
Let’s look at example below.

command

sudo cat cron | grep 'Jan 12 11:0[0-9]' | grep -e run-parts -e anacron
[vagrant@localhost log]$ sudo cat cron | grep 'Jan 12 11:0[0-9]' | grep -e run-parts -e anacron
Jan 12 11:01:01 localhost CROND[8441]: (root) CMD (run-parts /etc/cron.hourly)
Jan 12 11:01:01 localhost run-parts(/etc/cron.hourly)[8441]: starting 0anacron
Jan 12 11:01:01 localhost anacron[8450]: Anacron started on 2019-01-12
Jan 12 11:01:01 localhost run-parts(/etc/cron.hourly)[8452]: finished 0anacron
Jan 12 11:01:01 localhost anacron[8450]: Will run job `cron.daily' in 7 min.
Jan 12 11:01:01 localhost anacron[8450]: Jobs will be executed sequentially
Jan 12 11:08:01 localhost anacron[8450]: Job `cron.daily' started
Jan 12 11:08:01 localhost run-parts(/etc/cron.daily)[8453]: starting logrotate
Jan 12 11:08:01 localhost run-parts(/etc/cron.daily)[8461]: finished logrotate
Jan 12 11:08:01 localhost run-parts(/etc/cron.daily)[8453]: starting makewhatis.cron
Jan 12 11:08:03 localhost run-parts(/etc/cron.daily)[8585]: finished makewhatis.cron
Jan 12 11:08:03 localhost anacron[8450]: Job `cron.daily' terminated
Jan 12 11:08:03 localhost anacron[8450]: Normal exit (1 job run)

/etc/hostsとは

/etc/hosts って、中身何が入っているか?

etc/hostsの中身

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

ipとlocalhostのドメインでしょうか??

1. hostsとは?
-hosts(ホスト)とは? TCP/IPを利用するコンピュータにおけるホスト名のデータベースで、IPアドレスとホスト名の対応を記述したテキストファイル
-簡単に言えば、ホスト名からIPアドレス変換を行うファイル。

host名とは、localhostから、IPアドレス 127.0.0.1へ変換を行っている。

2. etc/hostsを編集
[vagrant@localhost ~]$ sudo vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.111.111 hpscript.com

3. pingを打つ
[vagrant@localhost ~]$ ping hpscript.com
PING hpscript.com (192.168.111.111) 56(84) bytes of data.
From 172.31.6.113 icmp_seq=24 Destination Net Unreachable

ぬおおおおおおおおおおおおお

psコマンドの見方

psコマンドとは?

psコマンドは、Linux上で現在動作しているプロセスを表示するコマンド。
とりあえずコマンドラインで叩いてみよう。

[vagrant@localhost test]$ ps
PID TTY TIME CMD
15686 pts/3 00:00:00 bash
17690 pts/3 00:00:00 ps

PID:実行しているプロセスの番号
CMD:コマンド

Linuxのシンボリックリンクとは?

シンボリックリンク(symbolic link)って何?
イメージ的にはこんな感じ?

それはシンプルリングやねん。

シンボリックリンクとは、ファイルやフォルダの代理ファイルのことです。
よく分からないので、作ってみましょう。

[vagrant@localhost test]$ ls
test.php
[vagrant@localhost test]$ ln -s test.php ./test.php
ln: creating symbolic link `./test.php': ファイルが存在します

あれ!?
lnコマンドは、ディレクトリやファイルへのリンクを登録するコマンド
-sオプションは、シンボリックリンクを作成するオプション

ってことは、再度やり直します。
[vagrant@localhost test]$ ls
test.php
[vagrant@localhost test]$ ln -s test.php s.php
[vagrant@localhost test]$ ls
s.php test.php
[vagrant@localhost test]$

あれ、なんかそれっぽいのが出来ている!?

シンボリックリンクを叩く
なんでもいいですが、catコマンドを使ってみます。


[vagrant@localhost test]$ cat s.php
";
echo "addign git tag!";

?>

test.phpをcatしているのと同じ結果になりました。

やるわねー

bashコマンド

bash は、標準入力やファイルから読み込んだコマンドを実行する、 sh 互換のコマンド言語インタプリタ

[vagrant@localhost app]$ bash helloworl.sh
hello world!

なるほど、シェルを実行するコマンドね。

udevルールの削除

udev ルールとは?
>OSがRed Hat Enterprise Linux 6の場合,サーバ対応の環境設定のscsi_deviceオペランドまたはdmmp_deviceオペランドに指定した共有ディスクのデバイスファイルのオーナー,グループ,およびパーミッションを設定するときは,udevルールファイルで設定

共有ディスクのパーミッションか。

ln -fs /dev/null /etc/udev/rules.d/70-persistent-net.rules

ネットワーク個別設定の削除
[root@localhost git-2.19.1]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-enp0s3 ifdown-ippp ifdown-routes ifup ifup-ipv6 ifup-ppp ifup-tunnel
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-aliases ifup-isdn ifup-routes ifup-wireless
ifdown ifdown-isdn ifdown-Team ifup-bnep ifup-plip ifup-sit init.ipv6-global
ifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ifup-plusb ifup-Team network-functions
ifdown-eth ifdown-ppp ifdown-tunnel ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6

でたーーーーーーーーー ネットワーク。DMMで完膚なきまでやられたからなー

ifcfg-enp0s3をみると、UUIDはあるが、HWADDRはないぞ。

HWADDR=****
UUID=****

box作成の最適化

yum clean all

次にフラグメーションを解消する

dd if=/dev/zero of=/EMPTY bs=1M

[root@localhost network-scripts]# dd if=/dev/zero of=/EMPTY bs=1M
dd: error writing ‘/EMPTY’: No space left on device
4442+0 records in
4441+0 records out
4657184768 bytes (4.7 GB) copied, 15.4136 s, 302 MB/s

いよいよ
boxの作成
boxを作成する。コマンドは以下の通り。これで本当に出来るんか?半信半疑

vagrant package --base CentOS7 --output centOS7

ん、なんかできてるっぽい?
>vagrant package –base CentOS7 –output centOS7
==> CentOS7: Clearing any previously set forwarded ports…
==> CentOS7: Exporting VM…
==> CentOS7: Compressing package to: C:/Users/narishige/MyVagrant/centos7/centOS7

これマジ?
2018/10/27 15:04 882,256,211 centOS7

VirtualBox_Guest_Additionsのインストール

Guest Additions CD イメージの挿入は設定済み
デバイスから操作すると、

[root@localhost ~]# mkdir /media/cdrom
[root@localhost ~]# mount -r /dev/cdrom /media/cdrom
[root@localhost ~]# ls-l /media/cdrom
-bash: ls-l: command not found
[root@localhost ~]# ls -l /media/cdrom
total 51462
dr-xr-xr-x 2 root root     2048 Jul 27  2017 32Bit
dr-xr-xr-x 2 root root     2048 Jul 27  2017 64Bit
-r-xr-xr-x 1 root root      647 Aug 17  2016 AUTORUN.INF
-r-xr-xr-x 1 root root     6381 Jul 27  2017 autorun.sh
dr-xr-xr-x 2 root root     2048 Jul 27  2017 cert
dr-xr-xr-x 2 root root     4096 Jul 27  2017 OS2
-r-xr-xr-x 1 root root     4824 Jul 27  2017 runasroot.sh
-r-xr-xr-x 1 root root  8160718 Jul 27  2017 VBoxLinuxAdditions.run
-r-xr-xr-x 1 root root 17789440 Jul 27  2017 VBoxSolarisAdditions.pkg
-r-xr-xr-x 1 root root 16407888 Jul 27  2017 VBoxWindowsAdditions-amd64.exe
-r-xr-xr-x 1 root root   268496 Jul 27  2017 VBoxWindowsAdditions.exe
-r-xr-xr-x 1 root root 10046608 Jul 27  2017 VBoxWindowsAdditions-x86.exe

あれ、なんだこれ。
lsコマンドの-lはリストを縦に表示

/media/は
>一時的なマウント用のディレクトリ。マウントとは接続された装置をOSに認識させて使うといった意味になります。このディレクトリは一時的なマウント用なので、例えば「USBメモリを接続した」とかした場合にここにファイルのような扱いでそのデバイスが置かれます。/mediaとの違いは「一時的な」という部分になりますね。

/dev
>主に記憶デバイスとかを入れておくディレクトリ。UNIXでは「デバイスをファイルのような扱いにして操作する」って設計になっているのでデバイスを追加とかするとここにファイルのような扱いでデバイスが置かれます。

mountコマンド
「mount」は、HDDやUSBメモリ、DVD-ROMなどのフォーマット済みの領域(ファイルシステム)を指定したディレクトリ(マウントポイント)と一時的に結び付けてアクセスできるようにするコマンド

うお、マニアックになってきた。
mount -r は読み取り専用

shコマンド シェルの起動

[root@localhost ~]# sh /media/cdrom/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.26 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.

[root@localhost ~]# cat /var/log/VBoxGuestAdditions.log

vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
chcon: can’t apply partial context to unlabeled file ‘/usr/lib64/VBoxGuestAdditions/mount.vboxsf’
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: modprobe vboxguest failed.

[root@localhost ~]# umount /media/cdrom
[root@localhost ~]# ls -l /media/cdrom
total 0

centos7のiptables無効化(firewalld)

[root@localhost ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.
[root@localhost ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.

なに?
あ、centos7では「iptables」から「firewalld」に変更されている。

[root@localhost ~]# systemctl is-enabled firewalld
enabled

enabledになってます。
firewalldを無効化にします。

systemctl stop firewalld

[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2018-10-27 12:18:33 JST; 9s ago
     Docs: man:firewalld(1)
  Process: 623 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 623 (code=exited, status=0/SUCCESS)

Oct 27 12:01:06 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Oct 27 12:01:09 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Oct 27 12:18:33 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Oct 27 12:18:33 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.

activeがinactive(dead)で無効化されているのでOK
続いて自動起動

[root@localhost ~]# systemctl is-enabled firewalld
enabled

firewalldの自動起動を無効化

[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl is-enabled firewalld
disabled

しゃああああああああああああああああああ