linux操作命令總結二()

1)查看目錄大小

du -sm  /directory   查看/directory目錄總大小, 單位MB

 

2) RPM軟件包

rpm -qa |grep vnc          查詢已經安裝軟件中帶vnc關鍵字的軟件包

rpm -e vnc                   卸載vnc軟件

rpm -e vnc  --nodeps    卸載vnc軟件,忽略軟件包的依賴關係

rpm -i vnc.rpm             安裝vnc 軟件

 

3)獲取IP地址

dhclient  eth0               獲取eth0的ip地址

 

4)打印硬盤分區的uuid信息

blkid

 

5)格式化硬盤

mkfs.ext4  /dev/sdb1    按照ext4格式來格式化/dev/sdb1分區

mkfs.ext3  /dev/sdb1    按照ext3格式來格式化/dev/sdb1分區

 

6) 磁盤檢查

fsck

 

7) 編譯src.rpm包

下載src 軟件包

wget http://xen-4.0.1-6.fc14.src.rpm

安裝

rpm -i xen-4.0.1-6.fc14.src.rpm

從build源代碼中獲取二進制包

#cd /root/rpmbuild/SEPCS

#rpmbuild -bb xen.spec

解釋一下:

rpmbuild 有三個參數

bb (build binary)

bs (build source)

ba  (build all)

安裝新build出來的包

#cd /root/rpmbuild/RPMS/x86_64/

#rpm -Uvh xen-4.0.1-6*.rpm

 

8)打patch及生成patch

打patch(忽略第一級目錄)

patch -p1 < my.patch

生成patch

patch -Nur old/  new/  > mypatch.diff

去除已經打的my.patch

patch -R -p1  < my.patch

 

9) git或hg下生成patch

git diff  >my.patch

hg diff >my.patch

把修改後的代碼生成統一格式的patch包

 

10)製作initramfs

ubuntu環境

mkinitramfs -o /boot/initramfs-3.3.7.img    3.3.7 (-o 參數是制定輸出路徑及名稱)

Redhat環境

mkinitrd -f /boot/initramfs-3.3.7.img  3.3.7

命令後面的3.3.7 是/lib/modules/下你需要生成的initramfs的版本

 

11)把image文件mount起來

先查看image的offset偏移字節大小

[root@localhost work]# fdisk -lu ia32e_rhel6u2.img
You must set cylinders.
You can do this from the extra functions menu.

Disk ia32e_rhel6u2.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00086c44

            Device Boot      Start         End      Blocks   Id  System
ia32e_rhel6u2.img1   *        2048    15753215     7875584   83  Linux
Partition 1 does not end on cylinder boundary.
ia32e_rhel6u2.img2        15753216    16777215      512000   82  Linux swap / Solaris
Partition 2 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(1044, 85, 1)

通過fdisk -lu命令可以看到redhat的image的偏移是2048個sectors,而每個sector是512個字節,所以這個image的總偏移大小事2048*512=1048576

就可以通過命令:mount -o loop,offset=1048576 ia32e_rhel6u2.img /mnt  把這個image給mount到/mnt目錄了。

 

12)在linux系統中,讓程序啓動的信息輸出到串口

修改/boot/grub/grub.conf的grub啓動配置文件,如下圖所示。

title Red Hat Enterprise Linux (2.6.32-220.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-220.el6.x86_64 ro root=UUID=a71042df-7979-44b3-ad9f-21547df29ef7 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD  SYSFONT=latarcyrheb-sun16 rhgb crashkernel=128M  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM   console=com1 com1=115200,8n1
        initrd /boot/initramfs-2.6.32-220.el6.x86_64.img
只需要在kernel中添加紅色字體的配置信息即可。

 

13)linux下的copy和paste

拷貝:選中複製內容,使用快捷鍵shift+ctrl+c

粘貼:在需要粘貼的地方,使用快捷鍵shift+ctrl+v

 

14) find的高級命令

find /home -name *.txt  -exec ls -l {} \;

該命令是在/home命令下查找.txt後綴結尾的文件,並通過ls -l命令顯示出來。前面查找不是重點,重點在於怎樣通過ls顯示出來。

該例子中特殊的地方有"{}"已經"\;",還有-exec這個關鍵字,這些東西的意義爲:

{}代表“有find找到的內容”,find找到的結果放置到{}位置中。

-exec 一直到“\;”是關鍵字,代表find額外命令的開始(-exec)到結束(\;),在這中間就是find命令內的額外命令。

因爲“;”在bash環境中有特殊意義,因此需要利用反斜槓來轉義。


15) 刪除repo sync文件夾中的全部.git文件夾

repo forall -c rm .git -rf


16) 生成帶email地址的RSA key

ssh-keygen -t rsa -C "name@company"

-t 制定key 類型

-C 設置email地址


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章