LN_command
Linux コマンド(UNIXコマンドも含む)
find
3日以内の変更されたファイルを探す # find ./ -ctime -3 -depth -print ** find -depth -print -ctime -3 とやると全てのファイルが表示されてしまいます。 理由 man find で調べる。(Hint 優先順位)
7日以前の tmp ディレクトリのファイルを削除 # find ./tmp/ -type f -print -mtime +7 -exec rm -f {} \; 10日以前の log/ 以下の *.nn.log ファイルを gzip で圧縮 # find ./log/ -type f -name "*.??.log" -mtime +10 -exec gzip -f {} \;
# フォルダの400日以前ファイルのみを削除 > find ./ -maxdepth 1 -type f -mtime +400 -print -exec rm -f {} \;
---- 100日以上前のメールボックスを削除 #!/bin/sh HOMEDIR="/home" # cd $HOMEDIR for n in [a-z]* do echo "USER $n" find $HOMEDIR/$n/Maildir -type f -mtime +100 -print -exec rm -f {} \; done
バックアップ Full # cd /hoge ; find . -depth -print | cpio -pduvm /backup 差分 # cd /hoge ; find . -depth -print | cpio -pdvm /bakcup (u オプションを除く)
チェックサム # cd /hoge; find ./ -type f | xargs md5sum
# FULL # rsync -auvr ./hoge /backupmedia/BACKUP_Folder # 上書き # rsync -auvr --delete ./hoge /backupmedia/backup_folder
ホスト名の変更
# vi sysconfig/network HOSTNAME=www の行を
カーネルモジュールの確認
lsmod 確認 insmod ロード rmmod アンロード
Linux が利用するインタラプト等の一覧
インタラプト # cat /proc/interrupts ポート # more /proc/ioports
CPU
# lscpu
# cat /proc/cpuinfo
error のリダイレクト shell_command > out_file 2>&1
Swap の遷移 #### zypper install sysstat # sar -B ## freebsd では BSDではiostat(1)コマンド
swap 領域の開放
swapoff -a && sudo swapon -a
Kermit の代わりに / screen /dev/ttyUSB0 9600
screen /dev/ttyUSB0 9600 (終了 C-a k (Ctrl+aを押した後に k) )
rpm のコマンド
オプション | |
---|---|
-ivh [rpm パッケージ名] | rpmファイルのインストール |
-ivh --test [rpm パッケージ名] | rpmファイルのインストール テスト |
-Uvh [rpm パッケージ名] | rpmファイルのアップグレード |
-Uvh --test [rpm パッケージ名] | rpmファイルのアップグレード テスト |
-ev [rpm パッケージ名] | rpmファイルの削除 |
-qa | インストールされている rpm ファイルの一覧を表示 |
スッティッキービット
bit | option | comments | ||
---|---|---|---|---|
4000 | u+s | コマンドが所有者の権限で実行される | chmod 4755 cmannd-name | |
2000 | g+s | コマンドが所有グループの権限で実行される | chmod 2755 command-name | |
1000 | o+s | ディレクトリ内のファイルを名前変更・削除できるのは所有者のみ | chmod 1755 dir-name |
コンソールのブラックアウトの禁止
setterm -blank nn を実行すれば,nn 分不活性状態が続いた後に スクリーンを消すように端末ドライバーを設定できます (nn を0にすると,スクリーンセーブ機能はオフになります. 古いカーネルの中には,次のキーボード割り込みが起こった後に初めて, スクリーンセーブ機能が働くようになっているものもあります)
FC3のカーネルソースのインストールの仕方
# up2date --get-source kernel # インストールの仕方 # rpm -ivh kernel-<version>.src.rpm # cd /usr/src/redhat/SPECS # rpmbuild -bp --target=<arch> kernel-2.6.spec # yum /etc/yum.conf [base] name=Fedora Core $releasever - $basearch - Base #baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/$releasever/$basearch/os/ baseurl=ftp://ftp.kddlabs.co.jp/Linux/packages/fedora/core/$releasever/$basearch/os # [updates-released] name=Fedora Core $releasever - $basearch - Released Updates #baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/updates/$releasever/$basearch/ baseurl=ftp://ftp.kddlabs.co.jp/Linux/packages/fedora/core/updates/$releasever/$basearch warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2 public key not available for XXXXXXX.rpm などとエラーをだす場合には rpm --import http://www.fedoralegacy.org/FEDORA-LEGACY-GPG-KEY もしくは rpm --import /usr/share/rhn/RPM-GPG-KEY* とGPGキーをインポートする事
ISOイメージをマウントするには
# mount -t iso9660 -o loop ISOファイル名 マウントポイント
CD-Rを作成するには
# cdrecord --dev=/dev/cdrom image.iso
DVD-Rを作成するには
# dvdrecord -v -dao dev=/dev/dvd speed=1 image.iso TAO をサポートしていない云々で書き込めないので(涙)
DVD-RAM をフォーマットするには!!
注意 DOSモードで初期化します!!! # mkfs -t msdos -I -s 32 -S 2048 /dev/hda
DEBIAN
aptitude / モジュール検索 + モジュールインストール apt install Package_name Java のパッケージをいれる場合には java-package java-common のをいれる事
VMware の NAT
クライアントOSでNAT(/dev/vmnet8)を使う場合 defaltroute は xxx.yyy.zzz.2 になる また 詳細は /etc/vmware/vmnet8/ 以下に dhcpd と nat のディレクトリがあり dhcpd.conf と nat.conf があるので適宜修正する。
SElinux の解除
恒久的に
/etc/selinux/config の SELINUX=enforcing の行を( SELINUX=disabled にする
例 起動時の場合(一時的に)
# getenforce Enforcing # setenforce 0 # getenforce Permissive #
ファイル毎
HTTPd の公開用の登録 # restorecon /home/ユーザディレクトリ/public_html # restorecon -R /home/ユーザディレクトリ/public_html
FTPで home_dir を接続許可にする /usr/sbin/setsebool -P ftp_home_dir on /usr/sbin/getsebool -a | gr
確認方法
# sestatus
Run Lebelへの登録
標準への登録(ntpd の場合) # chkconfig --add ntpd # chkconfig --level 3 ntpd on # chkconfig --list ntpd ntpd 0:オフ 1:オフ 2:オフ 3:オン 4:オフ 5:オフ 6:オフl
lzh ファイルの解凍
Windows で圧縮された lzh ファイルの場合 linux 上で解凍するときに ファイル名が全て小文字になる場合がある。 このときには lha -eg [ファイル名] で解凍する事
Postfix の特定キュー(送信者 hoge@foo.bar.hoge) を削除
postqueue -p | tail +2 | awk 'BEGIN { RS = "" } { if ( $7 == "hoge@foo.bar.hoge" ) print $1 } ' | tr -d '*!' | postsuper -d - # $7=sender, $8=recipient1, $9=recipient2 確認してね。。 もしくは mailq | tail +2 | awk 'BEGIN { RS = "" } # $7=sender, $8=recipient1, $9=recipient2 { if ( $7 == "hoge@foo.bar.hoge" ) print $1 } ' | tr -d '*!' | postsuper -d -
vi のコマンド
:%s/置換前文字列/置換後文字列/[ENTER] でカーソル近辺の文字列を1つだけ置換。 :%s/置換前文字列/置換後文字列/g[ENTER] で文書内の該当文字列をすべて置換。 :B,Es/置換前文字列/置換後文字列/g[ENTER] で行番号B〜E内の該当文字列をすべて置換。 日本語対応のvi(jvim,jelvis)を使っている場合は、文字列に日本語を使えます。
スクリーンショット
ImageMagic を使うばあい import -frame -screen capture.jpg GIMP を使う場合 ファイル > 取り込み > 画面 GNOMEの場合 gnome-screenshot --delay=5 --window
プロセスの優先順位を変更して実行する
nice -n [-19 -- 19] command -19 (最優先) 19 (優先度低い)
パケットフォワードの設定
# コマンドで実行 echo 1 > /proc/sys/net/ipv4/ip_forward # # /etc/sysctl.conf net.ipv4.ip_forward = 1 # IP フォワード net.ipv4.conf.default.rp_filter = 1 # IP Spoofingの防御 net.ipv4.tcp_syncookies = 1 # SYN Flood攻撃への対処
Linux で P2P
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/668usebittorrent.html http://azureus.sourceforge.net/
FC5 右ボタンにTERMINAL メニューを!!!!
マウスの右クリックメニューの中から起動したければ、 yum -y install nautilus-open-terminal でインストールすればメニュー内の順番は違いますが使えるようになります。
rsync
rsync のオプション -a 可能な限りファイルの情報を保持してコピーする -u 更新されたファイルだけをコピーする -v 詳細表示 -z ファイルを圧縮して転送する -r ディレクトリを再帰的に行う -b 古いファイルのバックアップを作成する -e ssh sshでデータを暗号化してコピーする --delete 送信元に存在しないファイルを削除する --exclude 指定したファイルを除外してコピーする 例 rsync -auvzr --delete /etc/ /media/usbdisk/LNX5/etc/ rsync -auvzr --delete --exclude='spool/squid' /var/ /media/usbdisk/LNX5/var/ rsync -auvzr --delete /usr/ /media/usbdisk/LNX5/usr/ rsync -auvzr --delete /root/ /media/usbdisk/LNX5/root/ rsync -auvzr -e ssh /home/html/ user@servername:/home/httpd/html/ # # ディレクトリレベルのバックアップ # rsync -auvr /x/foo/ /home/foo # rsync -auvr /SRC_DIR/foo/ /DIST_DIR/foo # キー ポイント SRC は最後に / をつけ DIST はつけない。。理由は DIR の事を考えると分かる。。
外付けHDDの作成
## パーティションの作成 #fdisk /dev/sda コマンド (m でヘルプ): n コマンドアクション e 拡張 p 基本領域 (1-4) p 領域番号 (1-4): 1 最初 シリンダ (1-38913, default 1): Using default value 1 終点 シリンダ または +サイズ または +サイズM または +サイズK (1-38913, default 38913): Using default value 38913 コマンド (m でヘルプ): w 領域テーブルは交換されました! ioctl() を呼び出して領域テーブルを再読込みします。 ディスクを同期させます。 ### 初期化(ファイルシステムの作成) # mkfs -t ext3 /dev/sda1 mke2fs 1.38 (30-Jun-2005) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 39075840 inodes, 78142160 blocks 3907108 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=79691776 2385 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. # # ReiserFS の場合 # # mkreiserfs /dev/hda4 # # mkfs.reiserfs /dev/hda4 # # mkfs -t reiserfs /dev/hda4 Command (m for help): p
FAT32 での場合 Disk /dev/sdb: 200.0 GB, 200049647616 bytes 255 heads, 63 sectors/track, 24321 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xb59d6804 Device Boot Start End Blocks Id System /dev/sdb1 1 3824 30716248+ c W95 FAT32 (LBA) /dev/sdb2 3825 24321 164642152+ 83 Linux Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): c Changed system type of partition 2 to c (W95 FAT32 (LBA)) Command (m for help): p Disk /dev/sdb: 200.0 GB, 200049647616 bytes 255 heads, 63 sectors/track, 24321 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xb59d6804 Device Boot Start End Blocks Id System /dev/sdb1 1 3824 30716248+ c W95 FAT32 (LBA) /dev/sdb2 3825 24321 164642152+ c W95 FAT32 (LBA) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks. ファイルシステムの作成 # mkfs.vfat -v -F 32 /dev/ # fdisk /dev/sdb #### # USB の場合 # mkfs.vfat -v -c -F 32 /dev/sdXn
SUSE のインストールの時の注意
ランレベル3のときに 画面サイズが 80x24 にならない時がある この時に /boot/grub/menu.lst の kernel /vmlinuz root=/dev/xxxx vga=0x31a resume=/dev/xxxx splash=silent showopts の様になっているので vga=0x31a の部分を vga=normal に変更する!! 数値の意味
色数/解像度 | 640x480 | 800x600 | 1024x768 | 1280x1024 | |
---|---|---|---|---|---|
256色 | 301 | 303 | 305 | 307 | |
32000色 | 310 | 313 | 316 | 319 | |
64000色 | 311 | 314 | 317 | 31A | |
1677万色 | 312 | 315 | 318 | 31B |
suse10.2 に radeon X1600 openSUSE 10.2
If you want or need to use the latest and greatest ATI driver, continue here .
Use YaST -> Software -> Change installation Source -> Add Protocol: http Server Name: : www2.ati.com Directory on Server: suse/10.2 to add the ATI http server as additional installation source. Now use YaST -> Software -> Install and Delete Software to install the ATI/fglrx driver. Select the following packages: x11-video-fglrxG01 ati-fglrxG01-kmp-<kernel-flavor> <kernel-flavor> depends on your installed kernel. Check with "uname -r" for installed default/smp/bigsmp kernel. Use "sax2 -r" for X.Org configuration.
xterm を終了しても子プロセスが終了しないように。。する方法 nohup :コマンドを利用する #!/bin/sh nohup ./hoge.sh &
--
全2重・半二重の見分けかた。 ethtool eth1 とやる ethtool -s eth1 autoneg off speed 100 duplex full とすると 100baseTX の 全2重に変更した。。 # vi /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 BOOTPROTO=static ONBOOT=yes TYPE=Ethernet IPADDR=192.168.0.254 NETMASK=255.255.255.0 ETHTOOL_OPTS="autoneg off speed 100 duplex full" <<<追加
OpenSUSE 10.2
リポジトリの変更
/sbin/yast2 inst_source & を実行 oss レポジトリ http://ftp.riken.go.jp/Linux/opensuse/distribution/10.2/repo/oss/ http://ftp.lab.kdd.co.jp/Linux/distributions/opensuse/distribution/10.2/repo/oss/ http://ftp.novell.co.jp/pub/opensuse/distribution/10.2/repo/oss non-oss レポジトリ http://ftp.riken.go.jp/Linux/opensuse/distribution/10.2/repo/non-oss/ http://ftp.lab.kdd.co.jp/Linux/distributions/opensuse/distribution/10.2/repo/non-oss/ update レポシトリ ftp://ftp.novell.co.jp/pub/suse/suse/update/10.2/ http://ftp.riken.go.jp/Linux/suse/suse/update/10.2/ http://ftp.lab.kdd.co.jp/Linux/distributions/SuSE/suse/update/10.2/
OpenSUSE 10.3
リポジトリの変更
/sbin/yast2 inst_source & を実行 oss レポジトリ http://ftp.riken.go.jp/Linux/opensuse/distribution/10.3/repo/oss/ http://ftp.lab.kdd.co.jp/Linux/distributions/opensuse/distribution/10.3/repo/oss/ http://ftp.novell.co.jp/pub/opensuse/distribution/10.3/repo/oss non-oss レポジトリ http://ftp.riken.go.jp/Linux/opensuse/distribution/10.3/repo/non-oss/ http://ftp.lab.kdd.co.jp/Linux/distributions/opensuse/distribution/10.3/repo/non-oss/ http://ftp.novell.co.jp//pub/opensuse/distribution/10.3/repo/oss/ update レポシトリ http://ftp.novell.co.jp/pub/suse/opensuse/update/10.3 http://ftp.lab.kdd.co.jp/Linux/distributions/opensuse/update/10.3/ http://download.opensuse.org/update/10.3/
ATI http://www2.ati.com/suse/10.3
opensuse 11.4 の firefox4
opensuse 11.4 の firefox4 で 日本語IME が動かない問題
env GTK_IM_MODULE=xim firefox
として起動すれば問題はないと思う。。まだテスト中
注意 *アルバイト君が .bashrc に export GTK_IM_MODULE=xim を追加してパニックになっていました。。(よく考えればわかりますよ。。)
bash のヒストリーログを削除する
bashのhistoryを削除するには $ history -c
awk の使い方
久しぶりに使おうとしてハマった。。(笑) squid のログのモニタ。。 tail -f ./a.log | awk '{print $1,$3,$4,$6,$5}'
date コマンドの
MST のtimezone を知りたい
> env TZ=MST date "+%Y/%m/%d%n %H:%M:%S" 2013/07/29 22:31:01
Cable 抜け
cat /sys/class/net/eth0/operstate
スループットの計測
$ wget http://www.lcp.nrl.navy.mil/nuttcp/nuttcp-6.1.2.tar.bz2 $ tar xvjf nuttcp-6.1.2.tar.bz2 $ cd nuttcp-6.1.2 $ make nuttcp
サーバ $ nuttcp -S
クライアント $ nuttcp xxx.xxx.xxx.xxx
dstat を使うhttps://t-min.hatenablog.com/entry/2018/03/18/213624
https://github.com/dagwieers/dstat
dstat
sar を使う
インストール # yum install sysstat 計測 ## sar 間隔 回数 # sar -o /tmp/sar.log 5 30 データ参照 ## CPU # sar -f /tmp/sar.log ## IO # sar -b -f /tmp/sar.log ## MEMORY # sar -r -f /tmp/sar.log ## TCP # sar -n TCP -f /tmp/sar.log ### (DEV/IP/ICMP/TCP/UDP などがあり ALL で全部を出力)
NDT
https://github.com/ndt-project/ndt/wiki
IO の負荷を減らして処理
DD の時 ionice -c3 dd if=/dev/zero of=100GB.img bs=1M count=102400 oflag=sync # rsync コマンドを用いるケース rsync -av --bwlimit 10000 src dst
# 大量のファイルを削除 find ./foobar -exec sleep 0.1 \; -delete -print
# 大きなファイルを削除 truncate コマンド使えば良いらしい
S.M.A.R.T チェック
smartctl /dev/sda -i
wifi のチェック
224 sudo iwconfig -a 252 sudo iw help 253 sudo iw dev 254 sudo iwconfig 269 sudo iw phy 274 sudo iwconfig 1002 /usr/sbin/iwconfig
wifi のAPの強度を見る
$ nmcli dev wifi
ハードウェアインフォメーション
ディストリビューションを調べる $cat /etc/issue
CPU を調べる $cat /proc/cpuinfo
メモリを調べる $cat /proc/meminfo | tail 30
$ free
$ ps auxwwO-r | head
$ dstat -tclmgdnpy --tcp 5
$ sudo slabtop -o -s c | head -n 15
$ while true; do date '+%H:%M:%S ' | tr -d '\n'; cat /proc/sys/fs/dentry-state; sleep 5; done
ソースの印刷
> cat your_progam_code.c | a2ps -M A4 -L 80 -l 125 -r --output=P.ps > cat PR.c | a2ps -M A4 --line-numbers=1 -L 80 -l 125 -r --output=P.ps
ENV コマンド
複数書ける(スペースで区切る??) env HTTP_PROXY=http://192.168.1.21:8080 HTTPS_PROXY=http://192.168.1.21:8080 /usr/bin/skypeforlinux
Iwlist next.......