目次

Tips

普段Linuxを使っていて教えてもらった事や、調べて分かった事

$ grep [0-9]{6} hogehoge // 例ではhogehogeというファイルから6桁の数字を検索 // 大カッコをエスケープしている事に注意!! </code>

$ grep [0-9]{1,6} hogehoge // 例ではhogehogeというファイルから1〜6桁の数字を検索 // 大カッコをエスケープしている事に注意!! </code>

$ rpm2cpio hogehoge.rpm | cpio -dim usr/lib/* </code>

$ find $(ディレクトリ} -type f -exec chmod 775 {} ; // 大カッコの後のスペースに注意 $ find ${ディレクトリ} -type f -print0 | xargs -0 chmod 664 </code>

$ for i in *; do chmod 664 $i; done </code>

$ cp -rp ./oldhome ./newhome </code>

$ cp -r ./oldhome ./newhome </code>

$ faxspool 012-345-6789 hogehoge.ps $ sudo faxrunq </code>

$ sed 's/huga/HUGA/' hogehoge </code>

$ for fname in *.html ; do sed 's/hoge/HOGE/' $fname > $fname.new; rm $fname ; mv $fname.new $fname ; done // 「${fname%.html}」とすると、ファイル名から「.html」をカットする </code>

$ lsof | grep -i hogehoge </code>

$ ping hogehoge $ arp | grep -e hogehoge </code>

$ perl -e 'print scalar localtime hogehoge' </code>

$ rpm -bb hogehoge.spec </code>

$ fold -b -w 256 hogehoge > hugahuga </code>

cd /home/hogeUser/fat32

// このディレクトリーにディスクイメージを作る

dd if=/dev/zero of=hogehoge.ext2 bs=1024k count=100

// これ(hogehoge.ext2)がディスクイメージのファイル名 // bs=1024kがブロックサイズでcount=100がブロック数なので、100MB作成する

mke2fs -F hogehoge.ext2

mkdir -p /home/hogeUser/hogehoge.dat

chown hogeUser /home/hogeUser /home/hogeUser/hogehoge.dat

mount -o loop hogehoge.ext2 /home/hogeUser/hogehoge.dat

chown hogeUser /home/hogeUser/hogehoge.dat/.

</code>

$ su - postgres $ vacuumdb DM名 </code>

$ su - postgres $ psqlj DB名 DB名=# VACUUM gwlog; </code>

$ find . -ctime +N -exec rm {} ; </code>

$ find /usr/hoge/fuga/ -type f -mtime +14 -exec chmod 440 {} ; </code>

$ tail -f hogehoge </code>

vi /etc/vmware/config

「xkeymap.keycode.211 = 0x073」を追加 Guest OSをシャットダウン後

/etc/init.d/vmware restart

</code>

$ sudo apt-get install task-kde </code>

$ apt-cache search hogehoge </code>

$ sudo mkbootdisk カーネルのバージョン </code>

$ nmap -sP 10.1.1.1-100 </code>

$ sudo cat /etc/passwd | mksmbpasswd.sh > /etc/smbpasswd </code>

$ gpg –keyserver pgp.mit.edu –recv-keys ID </code>

$ wc hoge // 表示される内容は「行数 単語数 ファイルサイズ ファイル名」となる </code>

$ find hogehoge -type f|wc -l </code>

$ sudo apt-get update $ sudo apt-get install scim-bridge scim-bridge-gtk $ sudo vi /usr/share/vine/imelib 「GTK_IM_MODULE=scim」を「GTK_IM_MODULE=scim-bridge」に変更 $ setime scim XWindowを再起動 </code>

$ sudo up2date -f kernel $ sudo up2date -f kernel-source $ sudo up2date -f kernel-utils </code>

$ sudo vi /etc/network/interfaces 以下の様に設定 iface lo inet loopback auto lo
iface eth0 inet static address xxx.xxx.xxx.xxx network xxx.xxx.xxx.0 netmask 255.255.255.0 broadcast xxx.xxx.xxx.255 gateway xxx.xxx.xxx.xxx auto eth0 設定完了後 $ sudo /etc/init.d/networking restart として、ネットワークを再起動する </code>

$ sudo vi /etc/network/interfaces 以下の様に設定 iface lo inet loopback auto lo
iface eth0 inet dhcp auto eth0 設定完了後 # /etc/init.d/networking restart として、ネットワークを再起動する </code>

$ sudo alien hogehoge.hugahuga.rpm </code>

$ sudo update-rc.d -f hogehoge remove // サービスのパッケージがapt-get等でアップデートされた場合には、 // 自動起動が再セットされる場合があるので、その際には上記処理を // 再度行う必要がある </code>

$ sudo sysv-rc-conf hogehoge off // 使い方はchkconfとほぼ同じ? </code>

$ gconf-editor [apps] > [metacity] > [general]と選択していき [button_layout]を「close,maximize,minimize:menu」に変更する </code>

$ sudo dd if=/dev/hdb | gzip -c > ./hdb.gz </code>

Adobe AIRをインストール後 $ sudo ln -s /usr/lib64/libadobecertstore.so /usr/lib32/ </code>

$ time hogehoge </code>

$ grep -l -i hogehoge * | xargs rm -f </code>

参照方法 $ last </code>

参照方法 $ lastlog </code>

参照方法(root権限が必要) # lastb </code>

参照方法(root権限が必要) $ sudo faillog </code>

#!/bin/sh /sbin/route add -net 10.0.1.0 netmask 255.255.255.0 gw 10.1.1.30 dev eth0 </code>

</code>

<?xml version=“1.0” encoding=“UTF-8”?> <!DOCTYPE wallpapers SYSTEM “gnome-wp-list.dtd”> <wallpapers>   <wallpaper deleted=“false”>     <name>Ubuntu 14.04 Community Wallpapers</name>     <filename>/home/makoto/Data/Wallpaper/Car/FD3S/FD3S.xml</filename>     <options>zoom</options>   </wallpaper>&br;</wallpapers> </code>

$ grep -E -e '(hogehoge|hugahugga)' hogehuga.txt </code>

$ cut -d ',' -f 2,3,5-7 hugahoge.csv </code>

$ nl -s, hugahoge.csv </code>

$ sort -t. -k1,1 -k2,2 -k3,3 -k4,4 -g IPAddress.txt </code>

$ at 07:00 091712 at> echo hogehoge > hugahuga.txt at> [Ctrl+D] </code>

ubuntuの場合(要libnet-ip-perl) $ /usr/share/doc/libnet-ip-perl/examples/ipcount 10.1.0.0 - 10.1.255.255 CentOSの場合(要perl-Net-IP) $ ipcount 10.1.0.0 - 10.1.255.255 </code>

$ export no_proxy=localhost,hoge.huga.com </code>

$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND makoto 25353 0.1 0.0 15368 2268 pts/4 S+ 17:22 0:00 top

$ cat /proc/25353/stat 25353 (top) S 25318 25353 9705 34820 25353 4194304 185 0 0 0 0 4 0 0 20 0 1 0 89908 15736832 567 18446744073709551615 4194304 4247452 140728479687936 0 0 0 0 0 138047495 1 0 0 17 3 0 0 0 0 0 6344704 6347792 7163904 140728479696172 140728479696176 140728479696176 140728479698923 0 $ cat /proc/25318/stat 25318 (bash) S 25317 25318 9705 34820 25353 4194560 570 2240 0 0 0 0 1 0 20 0 1 0 89817 118427648 939 18446744073709551615 4194304 5094508 140737195549472 0 0 0 65536 3686404 1266761467 1 0 0 17 0 0 0 0 0 0 7192576 7228592 17289216 140737195552635 140737195552641 140737195552641 140737195552750 0 $ cat /proc/25317/stat 25317 (su) S 25206 25317 9705 34820 25353 4194560 267 0 0 0 0 0 0 0 20 0 1 0 89817 164220928 798 18446744073709551615 1 1 0 0 0 0 2147196671 0 16384 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $ cat /proc/25206/stat 25206 (bash) S 25205 25206 9705 34820 25353 4194560 477 1388 0 0 0 0 0 0 20 0 1 0 89550 118317056 870 18446744073709551615 1 1 0 0 0 0 65536 3686404 1266761467 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $ cat /proc/25205/stat 25205 (sudo) S 9705 25205 9705 34820 25353 4194560 396 0 0 0 0 0 0 0 20 0 1 0 89550 197926912 1267 18446744073709551615 1 1 0 0 0 0 0 0 752135 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $ cat /proc/9705/stat 9705 (bash) S 9704 9705 9705 34820 25353 4194304 747 93246 0 12 1 0 221 78 20 0 1 0 12219 118329344 889 18446744073709551615 1 1 0 0 0 0 65536 3686404 1266761467 0 0 0 17 1 0 0 0 0 0 0 0 0 0 0 0 0 0 $ cat /proc/9704/stat 9704 (sshd) S 9701 9701 9701 0 -1 4194624 186 0 0 0 4 3 0 0 20 0 1 0 12202 121004032 1117 18446744073709551615 1 1 0 0 0 0 0 4096 65536 0 0 0 17 2 0 0 0 0 0 0 0 0 0 0 0 0 0 $ cat /proc/9701/stat 9701 (sshd) S 3129 9701 9701 0 -1 4194560 632 204 0 0 1 0 0 0 20 0 1 0 12163 120872960 1809 18446744073709551615 1 1 0 0 0 0 0 16781312 16387 0 0 0 17 3 0 0 0 0 0 0 0 0 0 0 0 0 0 $ cat /proc/3129/stat 3129 (sshd) S 1 3129 3129 0 -1 4194624 281 13257 0 15 0 0 19 7 20 0 1 0 2117 82579456 810 18446744073709551615 1 1 0 0 0 0 0 4096 81925 0 0 0 17 2 0 0 0 0 0 0 0 0 0 0 0 0 0 </code>

内容 コマンド
ディスク情報を表示 blkid
マウント情報を表示 df
BIOS/UEFI情報を表示 dmidecode -t bios
メモリ情報を表示 dmidecode -t memory
ディスク情報を表示 fdisk -l
現在のメモリ使用状況を表示 free -m
ディスク情報を表示 hdparm -i デバイスファイル
ハードウェア情報をフル表示 hwinfo
ハードウェア情報を表示 hwinfo –short
ネットワーク情報を表示 ifconfig -a
ハードウェア情報を表示 inxi -Fxz
ネットワーク情報を表示 ip link_show
ルーティング情報を表示 ip route
ディスク情報を表示 lsblk
CPU情報を表示 lscpu
ハードウェア情報をフル表示 lshw
CPU情報を表示 lshw -C cpu
ネットワーク情報を表示 lshw -C network
ハードウェア情報を表示 lshw -short
ディスク情報を表示 lshw -short -C disk
メモリ情報を表示 lshw -short -C memory
PCI情報を表示 lspci
指定したデバイスの情報表示 lspci -v -s デバイス番号
VGA情報を表示 lspci | grep -i vga
USB情報を表示 lsusb
ネットワーク情報を表示 netstat -i
ルーティング情報を表示 netstat -r
現在のメモリ使用状況を表示 top

$ fc-cache -fv </code>

vi /etc/netplan/01-network-manager-all.yaml

cat /etc/netplan/01-network-manager-all.yaml

network: version: 2 renderer: networkd ethernets:

enp4s0:
  dhcp4: false
  dhcp6: false
  addresses: [10.1.1.41/24]
  gateway4: 10.1.1.22
  nameservers:
    addresses: [10.0.71.156, 10.0.70.118]
    search: [seas-san-a.com, san-a.co.jp]

netplan apply

</code>

$ rehash </code>