$ openssl rand -hex [n]
$ openssl rand -hex 18
e18b92943506f49460d912a9044c3024f7e6
$ openssl rand -hex 10
543ee563c5890d915236
$ openssl rand -hex 10
84c4f0c6e72f3e14e1b9
$ ${variable:0:5}
$ TEXT="linux-shell-tips"; echo ${TEXT:0:5}
linux
$ TEXT="linux-shell-tips"; echo ${TEXT:0:11}
linux-shell
$ mkdir -p /home/user/{test,test1,test2}
$ ls /home/user/
test test1 test2
$ cp some_file_name{,.bak}
$ ls
README
$ cp README{,.bak}
$ ls
README README.bak
$ ps axwef
9548 ? Ss 0:05 /usr/sbin/httpd -k start
9549 ? S 0:00 \_ /usr/sbin/rotatelogs /var/log/httpd/error_log.%Y%m%d 86400 540
9552 ? S 0:00 \_ /usr/sbin/rotatelogs /var/log/httpd/access_log.%Y%m%d 86400 540
9553 ? S 0:02 \_ /usr/sbin/httpd -k start
9554 ? S 0:02 \_ /usr/sbin/httpd -k start
9555 ? S 0:02 \_ /usr/sbin/httpd -k start
9556 ? S 0:02 \_ /usr/sbin/httpd -k start
$ pstree
$ pstree
init─┬─abrt-dump-oops
├─crond
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─httpd─┬─15*[httpd]
│ └─4*[rotatelogs]
├─master─┬─pickup
│ └─qmgr
├─ntpd
├─rsyslogd───3*[{rsyslogd}]
├─ruby─┬─ruby───18*[{ruby}]
│ └─{ruby}
├─snmpd
├─sshd───sshd───sshd───bash───pstree
└─udevd
$ echo -n "text" | md5sum
$ echo -n "text" | md5sum
1cb251ec0d568de6a929b520c4aed8d1 -
$ xmllint --noout file.xml
※エラーが無ければ、何も出力されない
# 構文エラーがあった場合
$ xmllint --noout file.xml
file.xml:89: parser error : Opening and ending tag mismatch: packagerel line 89 and packagereq
<packagerel type="mandatory">perl-Math-Calc-Units</packagereq>
^
$ tar zxvf package.tar.gz -C [new_dir]
$ tar zxvf package.tar.gz -C /tmp/
$ curl -I http://www.example.com
$ curl --head http://www.example.com
$ curl -I http://www.example.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Thu, 28 Nov 2013 02:18:11 GMT
Etag: "359670651"
Expires: Thu, 05 Dec 2013 02:18:11 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (cpm/F858)
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270
$ openssl rand -base64 [n]
$ openssl rand -base64 8
spcYQD8PzTM=
$ openssl rand -base64 16
9rRXEgG1m32RRYMO/D0osQ==
$ LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
$ LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
7Zt4aqJsTyBw4i_O
$ LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-25};echo;
8HEkaCDL8KoO4NSwpmXXn4L_g
$ > test.txt
$ ll
total 4
-rw-r--r-- 1 user group 2132 Nov 28 11:25 test.txt
$ > test.txt
$ ll
total 0
-rw-r--r-- 1 user group 0 Nov 28 11:31 test.txt
$ watch [command]
$ watch uptime
※抜けるには、Ctrl+C
while で無限ループ作ってやる方法
$ while :;do echo '----------'; uptime; sleep 2; done
----------
11:44:03 up 110 days, 19:43, 1 user, load average: 0.00, 0.00, 0.00
----------
11:44:05 up 110 days, 19:43, 1 user, load average: 0.00, 0.00, 0.00
----------
11:44:07 up 110 days, 19:43, 1 user, load average: 0.00, 0.00, 0.00
----------
11:44:09 up 110 days, 19:43, 1 user, load average: 0.00, 0.00, 0.00
----------
11:44:11 up 110 days, 19:43, 1 user, load average: 0.00, 0.00, 0.00
----------
11:44:13 up 110 days, 19:43, 1 user, load average: 0.00, 0.00, 0.00
$ lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB "$9 }' | sort -n -u | tail
$ lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB "$9 }' | sort -n -u | tail
0MB NAME
1.83311MB /lib64/libc-2.12.so
94.565MB /usr/lib/locale/locale-archive
例えば、50行目から60行目の部分を表示する
$ sed -n '50,60p' [file_name]
$ sed -n '50,60p' httpd.conf
# NOTE! If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation
# (available at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/httpd"
#
# PidFile: The file in which the server should record its process