INDEX
[UNIX]覚えておきたい便利なコマンド
1  NI-Lab.  2004/09/10(Fri) 23:07
[UNIX]覚えておきたい便利なコマンド

2  NI-Lab.  2004/09/10(Fri) 23:07
早くファイルを検索できる。
findとの違いはわからない。

$man locate より

>locate - ファイル名データベースからパターンに合うものを表示する

>書式
>locate [-d path] [--database=path] [--version] [--help] pattern...

>locate は与えられたパターンそれぞれに対して、一つまたは複数のファイル名
>デー タベースを検索し、パターンを含むファイル名を表示する。

$ locate locate
/var/spool/up2date/slocate-2.7-3.i386.hdr
/etc/cron.daily/slocate.cron
/usr/share/doc/slocate-2.6
/usr/share/doc/slocate-2.6/ChangeLog
/usr/share/doc/slocate-2.6/INSTALL
/usr/share/doc/slocate-2.6/LICENSE
/usr/share/doc/slocate-2.6/MIRRORS
/usr/share/doc/slocate-2.6/README
/usr/share/doc/rpm-devel-4.2.1/apidocs/html/relocateable.html
/usr/share/doc/openldap-devel-2.0.27/drafts/draft-ietf-ldapext-locate-xx.txt
/usr/share/man/man1/locate.1.gz
/usr/share/man/man1/slocate.1.gz
/usr/share/man/man1/dislocate.1.gz
/usr/share/man/ja/man1/locate.1.gz
/usr/share/man/ja/man5/locatedb.5.gz
/usr/share/emacs/21.3/lisp/locate.elc
/usr/bin/locate
/usr/bin/slocate
/usr/bin/dislocate
/usr/src/linux-2.4.21-4.EL/arch/ppc/boot/common/relocate.S

3  NI-Lab.  2004/09/16(Thu) 19:44
whois

http://www.jp.freebsd.org/cgi/mroff.cgi?subdir=man&dir=jpman-3.3.0%2Fman&man=whois
On-line Manual of "whois"

http://www.nic.ad.jp/ja/whois/
WHOIS

IPアドレスの情報を取得できる。

// 取得例
$ whois 192.168.0.1
[whois.nic.ad.jp]
[ JPNIC & JPRS database provides information on network administration. Its ]
[ use is restricted to network administration purposes. For further infor- ]
[ mation, use 'whois -h whois.nic.ad.jp help'. To suppress Japanese output, ]
[ add'/e' at the end of command, e.g. 'whois -h whois.nic.ad.jp xxx/e'. ]

Network Information: [ネットワーク情報]
a. [IPネットワークアドレス] 192.168.0.1
b. [ネットワーク名] hogenet
f. [組織名] hoge
g. [Organization] Hont Ore Great Eater
m. [運用責任者] HOGE
n. [技術連絡担当者] HAGE
n. [技術連絡担当者] HIGE
p. [ネームサーバ] ns.x.xxx.jp
p. [ネームサーバ] ns.xxx.x.jp
y. [通知アドレス] hogeadmin@xx.xx.jp
[割当年月日] 2003/04/05
[返却年月日]
[最終更新] 2003/04/05 12:34:56 (JST)
ip-alloc@nic.ad.jp

4  NI-Lab.  2004/11/07(Sun) 08:04
lspci - list all PCI devices

PCI機器のリストを出力できる。
# lspci
00:00.0 Host bridge: Intel Corporation 82815 815 Chipset Host Bridge and Memory Controller Hub (rev 04)
00:02.0 VGA compatible controller: Intel Corporation 82815 CGC [Chipset Graphics Controller] (rev 04)
00:1e.0 PCI bridge: Intel Corporation: Unknown device 244e (rev 02)
00:1f.0 ISA bridge: Intel Corporation: Unknown device 2440 (rev 02)
00:1f.1 IDE interface: Intel Corporation: Unknown device 244b (rev 02)
00:1f.2 USB Controller: Intel Corporation: Unknown device 2442 (rev 02)
00:1f.3 SMBus: Intel Corporation: Unknown device 2443 (rev 02)
00:1f.4 USB Controller: Intel Corporation: Unknown device 2444 (rev 02)
00:1f.5 Multimedia audio controller: Intel Corporation: Unknown device 2445 (rev 02)
01:02.0 Ethernet controller: 3Com Corporation 3c905C-TX [Fast Etherlink] (rev 78)

cat /proc/pci でもいろいろな情報を得られる。

5  NI-Lab.  2004/11/07(Sun) 08:06
free  - Display amount of free and used memory in the system

メモリ(RAM)の容量を調べることができる。

$ free -m
total used free shared buffers cached
Mem: 248 240 8 0 14 139
-/+ buffers/cache: 86 162
Swap: 258 12 246

/proc 以下の情報も参考になる

$ cat /proc/meminfo
total: used: free: shared: buffers: cached:
Mem: 261062656 252346368 8716288 0 15474688 147730432
Swap: 271392768 12652544 258740224
MemTotal: 254944 kB
MemFree: 8512 kB
MemShared: 0 kB
Buffers: 15112 kB
Cached: 143156 kB
SwapCached: 1112 kB
Active: 83652 kB
Inactive: 79480 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 254944 kB
LowFree: 8512 kB
SwapTotal: 265032 kB
SwapFree: 252676 kB

6  NI-Lab.  2004/11/07(Sun) 08:08
/proc/meminfo を利用して、
CPUのスペックを調べることができる。

$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Celeron (Coppermine)
stepping : 10
cpu MHz : 908.964
cache size : 128 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse
bogomips : 1815.34

7  NI-Lab.  2004/11/07(Sun) 08:09
>>6

訂正: meminfo ではなくて cpuinfo ね。
8  NI-Lab.  2004/11/07(Sun) 08:10
>>6 は、UNIX というより Linux のみの機能?

9  NI-Lab.  2004/11/13(Sat) 19:19
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/662delfile.html
@IT:ファイルを完全に消去するには

GNU core utils の shred コマンドを利用する。

>$ shred --remove foo.txt

10  NI-Lab.  2005/05/11(Wed) 12:24
top コマンド

http://www.annodex.net/cgi-bin/man/man2html?1+top
Man page of TOP

http://homepage2.nifty.com/cs/linux_command/command/top.html
日経Linux [Linuxコマンド集] top : 現在のシステム状況を表示する

http://www.math.kobe-u.ac.jp/~kodama/tips-free-memory.html
Linux のメモリー管理(メモリ−が足りない?,メモリーリークの検出/防止)(Kodama's tips page)

>top コマンドを起動してから "M"(大文字) すると消費メモリの順に表示される.

http://sel.ics.es.osaka-u.ac.jp/~m-itii/#top
~m-itii - Linuxのtop / CPU番号を出力

>とりあえずtop起動.そしておもむろにfを入力.すると以下のような画面に切り替わります.
>
>Current Fields: AEHIOQTWKNMbcdfgjplrsuvyzX for window 1:Def
>Toggle fields via field letter, type any other key to return
>
>* A: PID = Process Id
>* E: USER = User Name
>* H: PR = Priority
>* I: NI = Nice value
>* O: VIRT = Virtual Image (kb)
>* Q: RES = Resident size (kb)
>* T: SHR = Shared Mem size (kb)
>* W: S = Process Status
>* K: %CPU = CPU usage
>* N: %MEM = Memory usage (RES)
>* M: TIME+ = CPU Time, hundredths

11  NI-Lab.  2005/05/11(Wed) 12:26
manの内容をテキストファイルに保存する方法。
そのままだと制御コードが入ってしまうので col コマンドを使う。
col - 入力中にある逆改行コードを処理するフィルタ

http://www.itmedia.co.jp/help/tips/linux/l0697.html
エンタープライズ: Linux Tips - man表示内容をファイル保存させたい

>$ man ls | col -bfx > ls.txt

12  NI-Lab.  2005/07/13(Wed) 08:36
watch コマンド
watch - execute a program periodically, showing output fullscreen

同じコマンドを自動で何度も入力して、結果を監視(監視するのは人だけど)できる。

watch -d 'ps -ef | grep java | grep tomcat'

みたいな感じで。