lsコマンドの結果を1ファイル1行で表示する
$ ls > ./tmp_$$ && grep -v "tmp_$$" ./tmp_$$ && rm -f ./tmp_$$
もしくは
$ ls -1
後者のほうがエレガント
unexpandコマンド(スペースをtabに変換する)
こんなコマンドもあった。
$ unexpand -a -t 1 sample2.txt 1 2 3
オプションの-aはall blanks、-tはタブに置き換えるスペースの数? みたいだけどちょっと動作がよくわからない……。
- 結論
sed, tr, awkという便利なコマンドがあります
expandコマンド(tabをスペースに変換する)
これブログ上じゃ差が判らないけど、
$ cat sample.txt 1 2 3
(数字がタブ区切りで書かれている)
というファイルに対して、expandコマンドを実行すると
$ expand sample.txt > sample2.txt $ cat sample2.txt 1 2 3 $ ll sample* -rw-rw-r-- 1 yasuhiro_kawai yasuhiro_kawai 19 Nov 28 14:55 sample2.txt -rw-rw-r-- 1 yasuhiro_kawai yasuhiro_kawai 7 Nov 28 14:51 sample.txt
と、半角スペース区切りに変換される。
なので、
$ expand sample.txt |tr -s [:space:] > sample3.txt $ cat sample3.txt 1 2 3
とすれば、タブを半角スペース1つに変換できる。
追記:
と思ったら、
$ expand -1 sample.txt 1 2 3
と、引数に1を渡すことでタブを1つのスペースに変更するか指定できるみたい。
と、思ったらこれも違って、引数に指定したn-1個のスペースに変換するみたい
$ expand -1 sample.txt 1 2 3 $ expand -2 sample.txt 1 2 3 $ expand -3 sample.txt 1 2 3 $ expand -4 sample.txt 1 2 3 $ cat samplex.txt 11 12 31 $ expand -1 samplex.txt 11 12 31 $ expand -2 samplex.txt 11 12 31 $ expand -3 samplex.txt 11 12 31 $ expand -4 samplex.txt 11 12 31
む……?
どうやらタブ幅を指定しているみたいだ。ということは正確には
$ expand -t 1 sample.txt $ expand --tabs=1 sample.txt
とするのが正しいらしい
Linuxコマンドラインで10000を10,000と表示する方法
小ネタ。かつて社内でこんなこと訊かれて答えたっけなぁなどと思いつつ……。
$ printf "%'d\n" 10000 10,000
まぁ、*nixのprintfコマンドなんてめったに使うことないですけどね……。
install.shがそのままでは動かないので修正する
redisの初期構築をやってくれるスクリプト、/path/to/src/util/install.sh、そのまま実行すると、
# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#; Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... ./install_server.sh: line 178: update-rc.d: コマンドが見つかりません exists, process is already running or crashed Installation successful!
と、いやいや"Installation successful!"じゃねぇよという出力が出る。というかchkconfigの登録に失敗する。
これを避けるためには、install.sh実行前に
# sed -i -e "s/\!\`which chkconfig\`/\! \`which chkconfig\`/g" ./install_server.sh
を実行する必要がある。
sed実行後、install.shを実行すると、
# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#; Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
と、"./install_server.sh: line 178: update-rc.d: コマンドが見つかりません"が出力されなくなり、代わりにchkconfigの登録が成功する
ターミナル上でtabを入力する
http://memo-off.blogspot.jp/2011/04/linuxsort.html
↑ここにあるとおり、Ctrl + Vの後にTabキーを押せば入力できる。もちろんsort以外でも使える。
echoだと、
$ echo -e "a\tb"
みたいに-eと\t使っちゃうけど。
Fedra18入れた
メディアからFedra18(いや今なら19入れろよ、と言うのはおいておいて)を入れたので、メモ
まず注意。Scientific Linux6.4でいうserviceやchkconfigの代わりにsystemctlというコマンドを使う。主なコマンドの比較は以下のとおり。
# | Scientific Linux6 | Fedora18 | 意味 |
---|---|---|---|
1 | service hoge start | systemctl start hoge.service | サービスhogeの起動 |
2 | service hoge stop | systemctl stop hoge.service | サービスhogeの停止 |
3 | service hoge status | systemctl status hoge.service | サービスhogeの起動状態の確認 |
4 | service hoge restart | systemctl restart hoge.service | サービスhogeの再起動 |
5 | service hoge reload | systemctl reload hoge.service | サービスhogeの設定再読み込み |
6 | service hoge condrestart | systemctl condrestart hoge.service | サービスhogeが起動中の場合再起動 |
7 | chkconfig --list | systemctl list-unit-files | サービス自動起動設定の表示 |
8 | chkconfig hoge on | systemctl enable hoge.service | サービスhogeの自動起動設定 |
9 | chkconfig hoge off | systemctl disable hoge.service | サービスhogeの自動起動設定の削除 |
10 | chkconfig --add hoge | systemctl daemon-reload | サービスhogeの自動起動設定リストへの追加 |
※ 実際にはchkconfigも併用しているみたいだ。後日調べて追記する。
システムアップデート
# yum -y upgrade
Firewallの停止
# systemctl status firewalld.service firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) Active: active (running) since Mon, 2013-09-23 22:39:22 JST; 54min ago Main PID: 588 (firewalld) CGroup: name=systemd:/system/firewalld.service m 588 /usr/bin/python -Es /usr/sbin/firewalld --nofork Sep 23 22:39:22 localhost.localdomain systemd[1]: Started firewalld - dynamic... # systemctl stop firewalld.service # systemctl status firewalld.service firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) Active: inactive (dead) since Mon, 2013-09-23 23:33:31 JST; 881ms ago Main PID: 588 (code=exited, status=0/SUCCESS) CGroup: name=systemd:/system/firewalld.service Sep 23 22:39:22 localhost.localdomain systemd[1]: Started firewalld - dynamic... Sep 23 23:33:30 localhost.localdomain systemd[1]: Stopping firewalld - dynami... Sep 23 23:33:31 localhost.localdomain systemd[1]: Stopped firewalld - dynamic... # systemctl disable firewalld.service rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service' rm '/etc/systemd/system/basic.target.wants/firewalld.service'
固定IPの設定と、IPV6非使用の設定
デフォルトではNetworkManagerが有効になっているので、コイツを止める
# vi /etc/sysconfig/network-scripts/ifcfg-em1
TYPE=Ethernet
BOOTPROTO=static
IPADDR=xx.xx.xx.xx
PREFIX=24
GATEWAY=xx.xx.xx.xy
DNS1=1xx.xx.xx.yy
DEVICE=em1
ONBOOT=yes
# systemctl disable NetworkManager.servcice rm '/etc/systemd/system/network.target.wants/NetworkManager-wait-online.service' rm '/etc/systemd/system/multi-user.target.wants/NetworkManager.service' rm '/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service'
で、代わりにnetworkを利用する
# systemctl enable network.service
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network on
え? 逆にchkconfig使えってか。
# chkconfig network on # init 6
アンチウイルスソフトの導入とかVNCの設定とかはまた別の機会に。