blog

あまり知られていない10のLinuxコマンド - パート3

10個のあまり知られていないLinuxコマンドシリーズ」第3弾の続きです。もしこれらのコマンドを既に知っているなら、あなたは間違いなく探索好きの経験豊富なLinuxユーザーです。...

Apr 2, 2014 · 8 min. read
シェア

10個のあまり知られていないLinuxコマンドシリーズ」の第3弾の続きです。もしこれらのコマンドを既に知っているなら、あなたは間違いなく探索好きの経験豊富なLinuxユーザーです。

22.^フー^バーオーダー

最後に修正したコマンドを例として実行します。例えば、'Desktop'ディレクトリの内容を詳しく調べるために、'ls -l'というコマンドを実行する必要があるとします。間違って、'ls -l'とタイプしてしまったとします。そのため、コマンド全体を入力し直すか、ナビゲーションキーを使って前のコマンドを編集する必要があります。コマンドが長い場合、これは面倒です。

avi@localhost:~/Desktop$ lls -l  
bash: lls: command not found 
 
avi@localhost:~/Desktop$ ^lls^ls  
 
ls -l  
total 7489440  
 
drwxr-xr-x 2 avi  avi       36864 Nov 13  2012 101MSDCF  
-rw-r--r-- 1 avi  avi      206833 Nov  5 15:27 1.jpg  
-rw-r--r-- 1 avi  avi      158951 Nov  5 15:27 2.jpg  
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc 

注:上記の置換には「typo (replaced) original_command」を使用してください。警告このコマンドは非常に危険です!システムコマンドやrm -rfのような危険なコマンドを故意または無意識にタイプミスした場合!

23. > file.txt コマンド

このコマンドは、同じファイルを削除して作成することなく、ファイルの内容を更新します。このコマンドは、何度も出力する必要がある場合や、同じファイルにログを残しておきたい場合に便利です。

avi@localhost:~/Desktop$ cat test.txt  
 
Linux  
GNU  
Debian  
Fedora  
kali  
ubuntu  
git  
Linus  
Torvalds 
 
 
avi@localhost:~/Desktop$ > test.txt  
avi@localhost:~/Desktop$ cat test.txt 

注意:繰り返しますが、このコマンドは危険です!システムファイルや特定のログファイルの内容をリフレッシュしようとしてはいけません。実行すると、深刻な問題が発生する可能性があります!

24.注文時

at'コマンドはcronコマンドに似ていて、特定の時間にタスクをスケジュールしたり、コマンドを実行したりするのに使うことができます。

avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 14:012 

もしかしたら

avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 2:12 PM 

サンプル出力(コンピューティング)

-rw-r--r-- 1 avi  avi      220492 Nov  1 13:49 Screenshot-1.png  
-rw-r--r-- 1 root root        358 Oct 17 10:11 sources.list  
-rw-r--r-- 1 avi  avi  4695982080 Oct 10 20:29 squeeze.iso  
.. 
.. 
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc  
-rw-r--r-- 1 avi  avi       96206 Nov  5 12:56 Untitled 1.odt  
-rw-r--r-- 1 avi  avi        9405 Nov 12 23:22 Untitled.png 

注意:echo 'ls -l' は、コマンドの文字列が標準端末に出力されることを意味します。ls -l'を必要なコマンドに置き換えたり、選択することができます。

>出力のリダイレクト

/dev/pts/0:指定された場所への出力デバイスおよび/またはファイルです。

avi@localhost:~/Desktop$ tty  
 
/dev/pts/0 

注意:'at'はシステム時刻が特定の時刻に一致した時点で実行されます。

25. du -h -max-depth=1 コマンド

以下のコマンドは、カレント・ディレクトリのサブディレクトリのサイズを人間が読める形式で出力します。

avi@localhost:/home/avi/Desktop# du -h --max-depth=1  
 
38M     ./test  
1.1G    ./shivji  
42M     ./drupal  
6.9G    ./101MSDCF  
16G . 

注:上記のコマンドは、システムの使用状況を確認するのに非常に便利です。

26. exprコマンド

expr」はあまり知られていないコマンドです。このコマンドはターミナルで簡単な計算をするときにとても便利です。

avi@localhost:/home/avi/Desktop# expr 2 + 3  
5 
 
avi@localhost:/home/avi/Desktop# expr 6 – 3  
3 
 
avi@localhost:/home/avi/Desktop# expr 12 / 3  
4 
 
avi@localhost:/home/avi/Desktop# expr 2 \* 9  
18 

27.ルックコマンド

混乱を防ぐために、端末にある英語辞書で単語を調べます。例えば、carrierと綴るべきかcarieerと綴るべきか思い出せません。

avi@localhost:/home/avi/Documents# look car 
Cara  
Cara's  
... 
...  
carps  
carpus  
carpus's  
carrel  
carrel's  
carrels  
carriage  
carriage's  
carriages  
carriageway  
carriageway's  
carried  
carrier  
carrier's  
carriers  
carries  
... 
...  
caryatids 

上のコマンドは、辞書に載っている「car」で始まる単語をすべて表示します。探していたものが見つかりました。

28.はいオーダー

もう1つのコマンドは、一般的にはあまり使われませんが、スクリプト言語やシステム管理では非常に便利です。

このコマンドは、割り込みコマンドによって中断されるまで、与えられた文字列を出力し続けます。

avi@localhost:~/Desktop$ yes "Tecmint is one of the best site dedicated to Linux, how to"  
 
Tecmint is one of the best site dedicated to Linux, how to  
Tecmint is one of the best site dedicated to Linux, how to  
Tecmint is one of the best site dedicated to Linux, how to  
Tecmint is one of the best site dedicated to Linux, how to  
... 
... 
... 
Tecmint is one of the best site dedicated to Linux, how to  
Tecmint is one of the best site dedicated to Linux, how to  
Tecmint is one of the best site dedicated to Linux, how to 

29.ファクターオーダー

factor は実は数学から派生したコマンドです。このコマンドは与えられたすべての数値の因数を出力します。

avi@localhost:~/Desktop$ factor 22  
22: 2 11 
 
avi@localhost:~/Desktop$ factor 21  
21: 3 7 
 
avi@localhost:~/Desktop$ factor 11  
11: 11 

30. ping -i 60 -a IP_address

どちらもpingコマンドを使ってサーバーが接続されているかどうかをテストします。私は通常、インターネットに接続されているかどうかを確認するためにgoogleにpingを打ちます。

コマンドの応答を待ったり、サーバーの接続を待ったりしている間、端末を見つめ続けたり、待ち続けたりすると、時には苛立たしいものです。

サーバーが接続されると音が鳴るのはどうですか?

avi@localhost:~/Desktop$ ping -i 60 -a www.google.com  
 
PING www.google.com (74.125.200.103) 56(84) bytes of data.  
64 bytes from www.google.com (74.125.200.103): icmp_req=1 ttl=44 time=105 ms  
64 bytes from 74.125.200.103: icmp_req=2 ttl=44 time=281 ms 

注意:コマンドがサウンドを返さない場合。システムがミュートになっていないか、サウンドが「サウンド環境設定」で有効になっているか、「ウィンドウとウィンドウのサウンドを有効にする」にチェックが入っているかを確認してください。

31.tacコマンド

このコマンドは、テキストファイルの内容を逆順に出力するという点で興味深い。つまり、最後の行から最初の行へ。

avi@localhost:~/Documents$ cat 35.txt 

サンプル出力(コンピューティング)

  1. Linux is built with certain powerful tools, which are unavailable in windows.
  2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart.
  3. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.

次にtacコマンドでファイルの内容を反転させます。

<code>avi@localhost:~/Documents$ tac 35.txt </code> 

サンプル出力(コンピューティング)

  1. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.
  2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart.
  3. Linux is built with certain powerful tools, which are unavailable in windows.

経由:

Read next

人々は喧嘩をしに公園に行き、プログラマーは喧嘩をしにGithubに行く!

3月4日、"Tan Haoqiangのプログラマー界における評判 "についての議論により、2人のプログラマー、Lin XueとLinusは意見が合わず、インターネット上で激しい言葉の戦いになりました。"1つ目はコードを見せること。結局、林は「2人でコードを書く大会に行こう」と提案し、薛は「薛が世界で最も有名なプログラミングSNSのgithubで公開リポジトリを作り、フォークしてから直接書き始めればいい」と提案。

Apr 1, 2014 · 2 min read