「Dash! C Capital!」
という声が隣から聞こえた。
最初は何のことか分からなかったが、「-Cをつけるとデータ圧縮とscp同時にしてくれて速くなるよ。」ということだった。
$ scp -C source user@server:/path/to/backup
scpが遅い場合は、-Cをつける。今日もまた一つ新しい学びがあった。
$ scp -C source user@server:/path/to/backup
| ディレクトリ名 | 説明 | 中に入っているバイナリ例 |
| /bin | single user modeでも利用できるバイナリ。 | date、cat、ls、bash、cdなど |
| /sbin | single user modeでも利用できるバイナリ。 supervisor権限が必要なもの。 |
fsck、mount、ping、dmesgなど |
| /usr/bin | システム全体で一般的に利用されるバイナリ。 | make、awk、java、ccなど |
| /usr/sbin | システム全体で一般的に利用されるバイナリ。 supervisor権限が必要なもの。 |
sshd、syslogd、httpdなど |
| /usr/local/bin | システム全体で一般的に利用されるバイナリ。 システムパッケージに管理されていないもの。 |
tmux、subl、spark-shellなど |
| /usr/local/sbin | システム全体で一般的に利用されるバイナリ。 supervisor権限が必要なもの。 システムパッケージに管理されていないもの。 |
logrotateなど |
import socket IP = '127.0.0.1' PORT = 5005 BUFFER_SIZE = 1024 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((IP, PORT)) s.listen(1) conn, addr = s.accept() while 1: data = conn.recv(BUFFER_SIZE) if not data: break msg = data.decode('utf-8') msg = msg[::-1] conn.send(msg.encode('utf-8')) conn.close()
import socket IP = '127.0.0.1' PORT = 5005 BUFFER_SIZE = 1024 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((IP, PORT)) msg = "ABCDEFG" s.send(msg.encode('utf-8')) data = s.recv(BUFFER_SIZE) print (data.decode('utf-8')) s.close()
$ ps -ef | grep python 501 9165 2011 0 11:51PM ttys000 0:00.04 python inet_server.py $ lsof -n -i -P | grep 9165 python3.5 9165 kenjih 3u IPv4 0xf27949601620cf2b 0t0 TCP 127.0.0.1:5005 (LISTEN)
import socket import os PATH = '/tmp/sample.sock' BUFFER_SIZE = 1024 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) os.unlink(PATH) s.bind(PATH) s.listen(1) conn, addr = s.accept() while 1: data = conn.recv(BUFFER_SIZE) if not data: break msg = data.decode('utf-8') msg = msg[::-1] conn.send(msg.encode('utf-8')) conn.close()
import socket PATH = '/tmp/sample.sock' BUFFER_SIZE = 1024 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(PATH) msg = "ABCDEFG" s.send(msg.encode('utf-8')) data = s.recv(BUFFER_SIZE) print (data.decode('utf-8')) s.close()
$ ps -ef | grep python 501 11543 2011 0 12:02AM ttys000 0:00.04 python unix_server.py $ lsof -n -P -U | grep 11543 python3.5 11543 kenjih 3u unix 0xf279496017547fcb 0t0 /tmp/sample.sock
$ uptime 0:51 up 1 day, 46 mins, 3 users, load averages: 2.05 1.87 2.10
$ wc -l tmp.log 1000000 tmp.log $ head tmp.log F 61 F 18 A 95 V 98 U 23 C 94 F 47 N 42 I 85 Q 281列目にアルファベット、2列目に数字があるような何らかのログファイルで、行数は100 万行。
$ cat tmp.log | awk '{print $2}' | sort | uniq | wc -l
100
cat tmp.log | awk '!seen[$2]++' | wc -l 100
kenjih$ lscpu Architecture: i686 CPU 操作モード: 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 コアあたりのスレッド数:2 ソケットあたりのコア数:2 Socket(s): 1 ベンダー ID: GenuineIntel CPU ファミリー: 6 モデル: 42 ステッピング: 7 CPU MHz: 800.000 BogoMIPS: 4988.44 仮想化: VT-x L1d キャッシュ: 32K L1i キャッシュ: 32K L2 キャッシュ: 256K L3 キャッシュ: 3072K
#include <iostream> #include <vector> using namespace std; typedef vector<int> vec; typedef vector<vec> mat; const int N = 1024; mat multiply(const mat &x, const mat &y) { int r = x.size(); int m = y.size(); int c = y[0].size(); mat z(r, vec(c)); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { for (int k = 0; k < m; k++) { z[i][j] += x[i][k] * y[k][j]; } } } return z; } int main(int argc, char **argv) { mat x(N, vec(N)); mat y(N, vec(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { x[i][j] = i; y[i][j] = j; } } mat z = multiply(x, y); long long sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum += z[i][j]; } } cout << sum << endl; return 0; }
#include <iostream> #include <vector> using namespace std; typedef vector<int> vec; typedef vector<vec> mat; const int N = 1024; mat multiply(const mat &x, const mat &y) { int r = x.size(); int m = y.size(); int c = y[0].size(); mat z(r, vec(c)); for (int i = 0; i < r; i++) { for (int k = 0; k < m; k++) { for (int j = 0; j < c; j++) { z[i][j] += x[i][k] * y[k][j]; } } } return z; } int main(int argc, char **argv) { mat x(N, vec(N)); mat y(N, vec(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { x[i][j] = i; y[i][j] = j; } } mat z = multiply(x, y); long long sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum += z[i][j]; } } cout << sum << endl; return 0; }
g++ -Wall -O2 a.cpp -std=c++0x -lm -o a
perf stat -e cycles,instructions,cache-references,cache-misses ./a結果は以下のとおり。
Performance counter stats for './a':
27,363,421,784 cycles # 0.000 GHz
11,880,422,836 instructions # 0.43 insns per cycle
71,384,828 cache-references
57,242,356 cache-misses # 80.188 % of all cache refs
Performance counter stats for './b':
3,618,482,791 cycles # 0.000 GHz
6,495,956,182 instructions # 1.80 insns per cycle
9,516,922 cache-references
4,136,614 cache-misses # 43.466 % of all cache refs
#include <iostream> #include <fstream> #include <set> using namespace std; class dictionary { set<string> container; public: void load(const string &path) { ifstream fs(path); string word; while (fs >> word) container.insert(word); } bool contains(const string &word) { return container.count(word); } }; int main(int argc, char **argv) { dictionary dict; dict.load("/usr/share/dict/american-english"); for (string s; cin >> s; ) { if (dict.contains(s)) cout << s << " is in the dictionary." << endl; else cout << s << " is not in the dictionary." << endl; } return 0; }以下実行結果です。固有名詞も辞書に含まれているみたいです。
hello hello is in the dictionary. world world is in the dictionary. soccer soccer is in the dictionary. Linux Linux is in the dictionary. Beatles Beatles is in the dictionary. Fibonacci Fibonacci is in the dictionary. totient totient is not in the dictionary. Yankees Yankees is in the dictionary.
$ sudo netstat -tanp | grep mysql-t: TCPのみ
$ sudo lsof -c mysql -a -i -a -P-c: プロセス名を指定
$ sudo lsof -i:3306
$ locate httpd.conflocateはディスク上のファイルではなく、DBに格納されたファイルパス情報を検索している。 DBはupdatedbというコマンドで最新化できる。updatedbはcronに登録されている。
$ factor 123456789
$ display xxx.jpg
$ basename test.cpp .cpp
$ pkg-config --cflags opencv $ pkg-config --libs opencv
$ g++ -ggdb `pkg-config --cflags opencv` -o `basename opencvtest.cpp .cpp` opencvtest.cpp `pkg-config --libs opencv`
$ xdg-open sample.avi $ xdg-open http://yahoo.co.jp上の例では、それぞれビデオファイル、yahooのページをデフォルトのアプリケーションで開きます。
$ lsb_release -a
$ dpkg -l必要に応じて、パイプとgrepで絞り込みを行う。
$ dpkg -l | grep openssl
$ lscpu | grep opCPU op-mode(s): 32-bit, 64-bit のように表示されれば、64bitのオペレーションモードをサポートしていることが分かる。
$ uname -m # uname -p でもOK.x86_64のように表示されれば64bit。ix86のように表示されれば32bit。
#!/bin/sh
data_backup_file="/home/kenjih/Dropbox/backup/procom/data/dump.sql"
src_backup_file="/home/kenjih/Dropbox/backup/procom/src/app.tar"
src_dir="/home/kenjih/dev/procom/src/app"
log="/home/kenjih/Dropbox/backup/procom/backup.log"
today=`date '+%s'`
updated_date=`stat -c '%y' ${data_backup_file}`
expire_date=`date -d "${updated_date} 3 days" '+%s'`
if [ $today -gt $expire_date ]; then
mysqldump -u usr -ppasswd procom >${data_backup_file}
tar -cf ${src_backup_file} ${src_dir} 2>/dev/null
echo "backup files saved at `date '+%Y/%m/%d %T'`." >>${log}
fi
# m h dom mon dow command 0 23 * * * /home/kenjih/dev/procom/src/app/Console/backup.sh
$ grep TODO *としてみましたが、ヒットせず。
$ grep TODO * $ grep TODO */* $ grep TODO */*/*とかやっていくと出るんですけど、もっと楽にできないかなと思い、
find . -name "*" | grep TODOとかやってみました。
find . -name "*" | xargs grep TODO
でやりたいことができました。ちなみにxargsは、extended argumentsの略らしいです。