目前分類:Linux (2)

瀏覽方式: 標題列表 簡短摘要

gzip解壓縮
1.先將檔名改為.gz
 mv initrd-2.6.18-92.el5.img initrd-2.6.18-92.el5.gz
2.gzip -d       # -d --decompress 
 gzip -d initrd-2.6.18-92.el5.gz

file initrd-2.6.18-92.el5
initrd-2.6.18-92.el5: ASCII cpio archive (SVR4 with no CRC)

===========================================================

cpio 解壓縮
cpio -ivcdu < initrd-2.6.18-92.el5

cpio - copy files to and from archives

‘-c’   Identical  to “-H newc”, use the new (SVR4) portable format.  
    If  you wish the old portable (ASCII) archive format, use  
                “-H  odc” instead.

‘-d, --make-directories’
             Create leading directories where needed.

‘-i, --extract’
              Run in copy-in mode.  see “Copy-in mode”.

‘-u, --unconditional’
              Replace  all  files,  without asking whether to replace existing
              newer files with older files.

‘-v, --verbose’冗長的
              List the files processed, or with ‘-t’, give an  ‘ls  -l’  style
              table  of contents listing.  In a verbose table of contents of a
              ustar archive, user and group names in the archive that  do  not
              exist  on the local system are replaced by the names that corre-
              spond locally to the numeric UID and GID stored in the  archive.

===========================================================

 

查看硬碟使用容量

# df -Th

Filesystem                           Type         Size  Used     Avail   Use%  Mounted on

/dev/mapper/centos-root       xfs          6.7G   4.6G    2.1G    69%    /

devtmpfs                          devtmpfs     906M     0     906M     0%    /dev

tmpfs                                   tmpfs       921M   88K   920M     1%     /dev/shm

tmpfs                                   tmpfs       921M  8.7M   912M    1%     /run

tmpfs                                    tmpfs      921M     0      921M    0%     /sys/fs/cgroup

/dev/sda1                                xfs       497M  157M  341M    32%    /boot

tmpfs                                    tmpfs     185M   8.0K    184M    1%    /run/user/0

-h, --  human-readable (自動選擇KB,MB,GB顯示)    
          print sizes in human readable format (e.g., 1K 234M 2G)/

-T, --   print file system Type


列出目錄使用的容量
# du -sh /*
 -s, --summarize
   display only a total for each argument


0             /bin
131M      /boot
816K      /dev
39M       /etc
5.7M      /home
0           /lib
0           /lib64
0           /media
0          /mnt
20M     /opt
du: cannot access ‘/proc/4761/task/4761/fd/4’: No such file or directory
du: cannot access ‘/proc/4761/task/4761/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/4761/fd/4’: No such file or directory
du: cannot access ‘/proc/4761/fdinfo/4’: No such file or directory
0            /proc
5.3M     /root
8.8M     /run
0           /sbin
0           /srv
0           /sys
216K     /tmp
3.3G     /usr
1.3G     /var

====================================================

hdparm 測試讀取速度

 -t   Perform device read timings

 -T   Perform cache read timings

 

[root@localhost ~]# hdparm -t /dev/sda

/dev/sda:

 Timing buffered disk reads: 612 MB in  3.00 seconds = 203.94 MB/sec

 

[root@localhost ~]# hdparm -t --direct /dev/sda

/dev/sda:

 Timing O_DIRECT disk reads: 684 MB in  3.04 seconds = 225.30 MB/sec

 

[root@localhost ~]# hdparm -T /dev/sda

/dev/sda:

 Timing cached reads:   9900 MB in  2.00 seconds = 4954.13 MB/sec

 

[root@localhost ~]# hdparm -T --direct /dev/sda

/dev/sda:

 Timing O_DIRECT cached reads:   102 MB in  2.03 seconds =  50.33 MB/sec

====================================================

查看記憶體指令 free

free 指令可以看實體記憶體和 Swap 的使用情況

-h human readable output (automatic unit scaling)

-s update every [delay] seconds

 

[root@localhost ~]# free -hs 5
[root@localhost ~]# watch -n 5 'free -h'  (
比較清楚)

 

             total       used       free     shared    buffers     cached

Mem:          996M       366M       629M       3.6M       8.3M        65M

-/+ buffers/cache:       292M       703M

Swap:         815M         0B       815M

 

====================================================

RAM Disk

[root@localhost ~]# mkdir /tmp/tmpfs

[root@localhost ~]# mount -t tmpfs -o size=50M tmpfs /tmp/tmpfs/

-t, --types vfstype

-o, --options opts

 

# df -TH

Filesystem           Type    Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

                     ext4    7.0G  4.3G  2.4G  64% /

tmpfs                tmpfs   523M  308k  523M   1% /dev/shm

/dev/sda1            ext4    500M   39M  435M   9% /boot

tmpfs                tmpfs    53M     0   53M   0% /tmp/tmpfs

 

寫入測試

# dd count=50 bs=1M if=/dev/zero of=/tmp/tmpfs/test.img

50+0 records in

50+0 records out

52428800 bytes (52 MB) copied, 0.0617388 s, 849 MB/s

 

# dd count=12500 bs=4k if=/dev/zero of=/tmp/tmpfs/test.img

12500+0 records in

12500+0 records out

51200000 bytes (51 MB) copied, 0.0744877 s, 687 MB/s

 

dd count=2k bs=1M if=/tmp/ramdisk/test2g.img of=/dev/null

 

讀取測試

# dd count=50 bs=1M if=/tmp/tmpfs/test.img of=/dev/null

48+1 records in

48+1 records out

51200000 bytes (51 MB) copied, 0.0272163 s, 1.9 GB/s

 

# dd count=12500 bs=4k if=/tmp/tmpfs/test2g.img of=/dev/null

12500+0 records in

12500+0 records out

51200000 bytes (51 MB) copied, 0.030945 s, 1.7 GB/s

=======================================

adminX 發表在 痞客邦 留言(0) 人氣()

  • Jan 31 Tue 2017 20:34
  • 轉貼

cut,sed,awk 字串處理

轉貼 http://jarkin.blogspot.tw/search/label/Shell%20Scritp

cut 教學:

  cut -b 10- filename //刪除該列的前10個字元
  cut -d(分界字元) filename //指定欄位的分界字元



sed 教學:
  sed -e '3d' //刪除第3列
  sed -e '2,5d' //刪除第2~5列
  sed -e '4,$d' //刪除第4列,但第4列是最後一列;錢字號『 $ 』代表最後一行!
  sed -e "/${var}/"d //在shell中,用變數代替
  sed 's/^...//' //刪除該列的前3個字元
  sed 's/...$//' //刪除該列的最後3個字元
  sed '/Hello/d' dataf3 //刪除Hello該列
  sed -i “s/\r//”FILENAME //刪除檔案中的^M字元
 
  sed 's/要被取代的字串/新的字串/g'
  ex: sed 's/*//g' //將「*」符用空白字元取代



awk教學:
  awk 'NR!=3 {print $0}' //刪除第3列
  awk '!(NR>=2 && NR<=5){print $0}' //刪除第2~5列



綜合:
  捉取第一列的「:」前的資料
  awk 'NR==1' aaa.a | cut -f 1 -d :

  捉取第一列的「:」前的資料並計算個數
  awk 'NR==1' aaa.a | cut -f 1 -d : | wc -m
 
  cat test.sh | awk -F = '/Sub 1/ {print NR}' //抓test.sh的Sub 1所在的列數


  抓取Channel方法
  iwconfig ra0 2>/dev/null | grep Channel | awk '{print $2}' | cut -b 9-
 
=========================================================

檢查檔案是否存在

if [ -f "檔案路徑" ]; then
    echo "檔案存在!!"
else
    echo "檔案不存在!!"
fi

or
if [ ! -f "檔案路徑" ]; then 
 
=========================================================

Get DHCP Assignment Default Gateway

Shell Code:
    route -n | grep 'UG[ \t]' | awk '{print $2}'


Shell Code: 
    route -n | grep '^0\.0\.\0\.0[ \t]\+[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]\+[ \t]\+0\.0\.0\.0[ \t]\+[^ \t]*G[^ \t]*[ \t]' | awk '{print $2}'
=========================================================

Linux 一些系統訊息
 

整理一些linux系統一些常用的系統信息查看命令.
有些在freebsd下也能用…
# uname -a # 查看內核/操作系統/CPU信息
# head -n 1 /etc/issue # 查看操作系統版本
# cat /proc/cpuinfo # 查看CPU信息
# hostname # 查看計算機名
# lspci -tv # 列出所有PCI設備
# lsusb -tv # 列出所有USB設備
# lsmod # 列出加載的內核模塊
# env # 查看環境變量資源
# free -m # 查看內存使用量和交換區使用量
# df -h # 查看各分區使用情況
# du -sh <目錄名> # 查看指定目錄的大小
# grep MemTotal /proc/meminfo # 查看內存總量
# grep MemFree /proc/meminfo # 查看空閒內存量
# uptime # 查看系統運行時間、用戶數、負載
# cat /proc/loadavg # 查看系統負載磁盤和分區
# mount | column -t # 查看掛接的分區狀態
# fdisk -l # 查看所有分區
# swapon -s # 查看所有交換分區
# hdparm -i /dev/hda # 查看磁盤參數(僅適用於IDE設備)
# dmesg | grep IDE # 查看啟動時IDE設備檢測狀況網絡
# ifconfig # 查看所有網絡接口的屬性
# iptables -L # 查看防火牆設置
# route -n # 查看路由表
# netstat -lntp # 查看所有監聽端口
# netstat -antp # 查看所有已經建立的連接
# netstat -s # 查看網絡統計信息進程
# ps -ef # 查看所有進程
# top # 實時顯示進程狀態用戶
# w # 查看活動用戶
# id <用戶名> # 查看指定用戶信息
# last # 查看用戶登錄日誌
# cut -d: -f1 /etc/passwd # 查看系統所有用戶
# cut -d: -f1 /etc/group # 查看系統所有組
# crontab -l # 查看當前用戶的計劃任務服務
# chkconfig –list # 列出所有系統服務
# chkconfig –list | grep on # 列出所有啟動的系統服務程序
# rpm -qa # 查看所有安裝的軟件包
# cat /proc/cpuinfo :查看CPU相關參數
# cat /proc/partitions :查看硬盤和分區
# cat /proc/meminfo :查看內存信息
# cat /proc/version :查看版本,類似uname -r
# cat /proc/ioports :查看設備io端口
# cat /proc/interrupts :查看中斷
# cat /proc/pci :查看pci設備的信息
# cat /proc/swaps :查看所有swap分區的信息

=========================================================

 

 
 
文章標籤

adminX 發表在 痞客邦 留言(2) 人氣()