.bashrc, .bash_profile

When using bash, you can customize the usage environment to your linking.

bash_profile
It is executed once at login. For example, it will be loaded when you start the terminal app. You should set an environment variable(a variable declared by export) to what should be specifically set in this file.

.bashrc
It is executed once at shell startup. If you hit bash on the command line, .bashrc will be read again.(.bash_profile is not read). If you want to set it each time you start the shell, put the settings in this file.

You may want to set aliases, shell functions, and command line completion for what to set specifically in this file.

~/.bash_profile
~/.bashrc

create zip directory with zip command

$ zip -r filename directoryname

[vagrant@localhost test]$ ls
test
[vagrant@localhost test]$ zip -r sample test
-bash: zip: コマンドが見つかりません

あれ、zipが入っていない?!

[vagrant@localhost test]$ sudo yum install zip
インストール:
zip.x86_64 0:3.0-1.el6_7.1

完了しました!

zipファイルを作ります。
[vagrant@localhost test]$ zip -r sample.zip test
adding: test/ (stored 0%)
[vagrant@localhost test]$ ls
sample.zip test

お!?

$ zip -e -v
->オプション
-e: –encrypt: 暗号化する
-v: –verbose: 動作中のメッセージを詳しくする

ああああああああああああああああああ、
まだまだまだまだあるううううううううううううううううううう

Linuxのバージョン確認

cat /proc/version
[vagrant@localhost ~]$ cat /proc/version
Linux version 2.6.32-754.14.2.el6.x86_64 (mockbuild@x86-01.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #1 SMP Tue May 14 19:35:42 UTC 2019

uname -a
[vagrant@localhost ~]$ uname -a
Linux localhost.localdomain 2.6.32-754.14.2.el6.x86_64 #1 SMP Tue May 14 19:35:42 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

unameだと、usernameが出てきますね。

cat /etc/system-release
[vagrant@localhost ~]$ cat /etc/system-release
CentOS release 6.10 (Final)

これが一般的か。
ちなみに、最新のLinuxはというと、、、

カーネルは4.18.0-80が最新のようですね。

grep -V

The -V option is used to search for non-matching ones.

[vagrant@localhost ses]$ grep gmail sendmail.cgi
$to = ‘hoge@gmail.org’;
[vagrant@localhost ses]$ grep -v print sendmail.cgi

なるほど、一致しないものね。使い勝手がいいですね。

mkdir ${dirname} && cd $_

コマンドラインで「$_」は一つ前の引数

[vagrant@localhost test]$ echo  hoge && echo $_
hoge
hoge

$_でhogeを引っ張てきている
mkdirでやると、

[vagrant@localhost test]$ mkdir ses && cd $_
[vagrant@localhost ses]$

おお、なんか素晴らしいですね。

curl command

What is curl command?
-> A command to transfer data from or to a server.

It supports many protocols such as FTP, SFTP, LDAP, TELNET.
The most basic usage is to use HTTP request and standard output.

curl [options] [url]

# Make an HTTP request and put the result on the standard output
$ curl http://target URL

# You can also specify the range using commas and []
$ curl 'http://{one, two, three}.example.com'
$ curl 'http://[1-3].example.com'

# Output execution result to file
$ curl http://Target URL > Output Destination
$ curl -o output destination PATH http://target URL

# Hide progress on file output(error is also hidden)
$curl -s -o output destionation Path http://target URL

# if you want to display the error above
$curl -sS -o output destination PATH http://target URL

# Display progress rate in progress bar
$curl -# -O http://Target URL

# Skip certificate error on SSL connection
$ curl -k https://target URL

# Download with URL filename(The following is saved as index.html)
$ curl -O http://target URL /index.html

# Access via proxy
$ curl -x proxy server: port number --proxy-user username:password http://target URL

# Enable redirection
$ curl -L http://Target URL

# When you resume the download again when you interrupt the download
$ curl -C -http://target URL

# Specification of HTTP method (-X)
$ curl -X PUT http://Target URL

curl -sS -Hは、エラー標示かつhttpヘッダにheader追加?

[vagrant@localhost ~]$ curl --version
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

[vagrant@localhost ~]$ curl -s -w '%{http_code}\n' http://www.amazon.co.jp/dp/B00JEYPPOE/ -o /dev/null
301
[vagrant@localhost ~]$ curl -s -w '%{http_code}\n' http://www.amazon.co.jp/dp/B00JEYPPOE/ -o /dev/null -A ''
301

ん?

sar -P all? (system admin reporter)

[vagrant@localhost ~]$ sar -q
-bash: sar: コマンドが見つかりません

あれ?インストールされてない?
インストールします。
[vagrant@localhost ~]$ sudo yum install -y sysstat
[vagrant@localhost ~]$ sudo vi /etc/cron.d/sysstat
# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1
# 0 * * * * root /usr/lib64/sa/sa1 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A
え、デフォルトでOK?

[vagrant@localhost ~]$ sudo service sysstat start
Calling the system activity data collector (sadc)…

[vagrant@localhost ~]$ sar
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時42分13秒 LINUX RESTART
[vagrant@localhost ~]$ sar -q
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時42分13秒 LINUX RESTART
おお、なんか来た。

[vagrant@localhost ~]$ sar -P ALL
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時42分13秒 LINUX RESTART
[vagrant@localhost ~]$ sar 1 1 -u -P ALL
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時43分53秒 CPU %user %nice %system %iowait %steal %idle
23時43分54秒 all 0.00 0.00 0.00 0.00 0.00 100.00
23時43分54秒 0 0.00 0.00 0.00 0.00 0.00 100.00

平均値: CPU %user %nice %system %iowait %steal %idle
平均値: all 0.00 0.00 0.00 0.00 0.00 100.00
平均値: 0 0.00 0.00 0.00 0.00 0.00 100.00

お、なんかCPU使用率が見えるっぽいですな。
[vagrant@localhost ~]$ sar 1 1 -q
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時44分46秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
23時44分47秒 0 227 0.04 0.16 0.09
平均値: 0 227 0.04 0.16 0.09

[vagrant@localhost ~]$ sar 1 1 -q
Linux 2.6.32-754.14.2.el6.x86_64 (localhost.localdomain) 2019年06月25日 _x86_64_ (1 CPU)

23時45分04秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
23時45分05秒 0 227 0.03 0.15 0.09
平均値: 0 227 0.03 0.15 0.09
すご。

vmstat

“vmstat” is a command to display statistics of virtual memory, CPU, and disk I/O.

By default, the average value from startup(result) is displayed. You can display the value in real time by specifying the update interval like “vmstat 1”.

[vagrant@localhost ~]$ vmstat
procs ———–memory———- —swap– —–io—- –system– —–cpu—–
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 1 584880 46328 36088 82136 20 21 94 28 46 97 0 0 97 3 0

procs -> process
 r -> 実行中と実行待ち中のプロセス数
 b -> 割り込み不可能なスリープ状態にあるプロセス数
memory -> memory
 swpd -> 仕様中の仮想メモリの量
 free -> 空きメモリの量
 buff -> バッファとして使用しているメモリの量
 cache -> キャッシュに使用している量
swap -> swap
 si -> ディスクからスワップインしているメモリの量
 so -> スワップアウトしている量
io -> input out
 bi -> HDDのようなブロック型デバイスから受けっとたブロック数
 bo -> ブロック型デバイスに送ったブロック数
system -> system
 in -> 1秒あたりの割り込み回数
 cs -> コンテクストスイッチの回数
CPU -> CPU
 us -> カーネルコード以外の実行に使用した時間
 sy -> カーネルコードの実行に使用した時間(システム時間)
 id -> 空転していたアイドル時間
 wa -> I/O待ち時間
 st -> 仮想マシンから盗まれた時間

メモリの単位ってなんだ?kバイト?

proc_open(): fork failed – Cannot allocate memory

[vagrant@localhost test]$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 17.3872 s, 61.8 MB/s
[vagrant@localhost test]$ sudo /sbin/mkswap /var/swap.1
スワップ空間バージョン1を設定します、サイズ = 1048572 KiB
ラベルはありません, UUID=4b1bec65-8ded-4ff2-8ed8-49e83f909f09
[vagrant@localhost test]$ sudo /sbin/swapon /var/swap.1

[vagrant@localhost test]$ free
total used free shared buffers cached
Mem: 501796 493940 7856 4 1184 402464
-/+ buffers/cache: 90292 411504
Swap: 2064376 735636 1328740

で、再度いれます。
php composer.phar require “phpmd/phpmd=~2.0”
今度は上手くいきそうです。
入りましたかね。

linux cp command

[vagrant@localhost test]$ ls
[vagrant@localhost test]$ touch fileA.txt
[vagrant@localhost test]$ ls
fileA.txt
[vagrant@localhost test]$ cp fileA.txt fileA_copy.txt
[vagrant@localhost test]$ ls
fileA.txt fileA_copy.txt

ディレクトリ先にもコピーできる。
[vagrant@localhost test]$ mkdir dir
[vagrant@localhost test]$ ls
dir fileA.txt fileA_copy.txt
[vagrant@localhost test]$ cp fileA.txt dir/fileA_cp.txt
[vagrant@localhost test]$ cd dir
[vagrant@localhost dir]$ ls
fileA_cp.txt

cpコマンドオプション -rでディレクトリごとコピー
[vagrant@localhost test]$ ls
dir fileA.txt fileA_copy.txt
[vagrant@localhost test]$ cp -r dir dir2
[vagrant@localhost test]$ ls
dir dir2 fileA.txt fileA_copy.txt
[vagrant@localhost test]$ cd dir2
[vagrant@localhost dir2]$ ls
fileA_cp.txt

-f:コピー先に同じ名前のファイルがあっても警告なしで上書きをする。
[vagrant@localhost test]$ ls
dir dir2 fileA.txt fileA_copy.txt
[vagrant@localhost test]$ cp -f fileA.txt fileA_copy.txt
[vagrant@localhost test]$ ls
dir dir2 fileA.txt fileA_copy.txt
[vagrant@localhost test]$ cp -rf dir dir2
[vagrant@localhost test]$ ls
dir dir2 fileA.txt fileA_copy.txt

なるほど、ディレクトリのコピーはcp -rfが良さそうですな。