ftp://192.168.0.1/biji
第一Apsara Infrastructure Management Framework本命令
ls -l install.log
-:rw-r--r--: 1: root: root: 39410: 11-03 13:44: install.log
檔案類型:許可權:硬串連數:擁有者:所屬組:檔案大小:最有一次修改日期和時間:檔案名稱
- 普通檔案
d 目錄檔案
l 連結檔案
b 塊裝置檔案
c 字元檔案
p 管道檔案
s 套節字檔案
ls -l 長格式 -a 顯示所有檔案 -A 除了.和..所有檔案 -h 按最大單位顯示
-d 顯示目錄資訊 -t 按時間排序 -r 反向排序 -R 遞迴顯示
協助命令
1.ls --help
2.type ls
alias la='ls -la'
unalias la
3.info ls
4.man
man 1 使用者命令
man 2 系統調用
man 3 庫調用
man 4 特殊文明
man 5 設定檔
man 6 遊戲
man 7 雜項
man 8 系統命令
man 9 核心參考
man -f passwd 查詢關鍵字在那些章節有相應說明
makewhatis 維護man
man -k passwd 模糊查詢
/目錄下的目錄作用
/bin /usr/bin/ /usr/local/bin/ 普通使用者可以執行的命令
/sbin/ /usr/sbin/ /usr/local/sbin/ 管理員可以執行的命令
/root 管理員家目錄
/home 普通使用者家目錄
/etc 設定檔目錄
/var 伺服器資料目錄
/usr 應用程式目錄
/tmp 臨時檔案目錄
/dev 塊裝置目錄
/boot 引導程式目錄(核心 開機檔案 引導程式)
/lib /usr/lib /usr/local/lib 存放庫檔案和系統的模組
/sys 偽檔案系統
/proc 偽檔案系統(核心參數 進程在記憶體的資訊)
/mnt 其他掛載點
/opt 第三方軟體目錄
/net autofs
/misc autofs
/tftpboot tftp伺服器的主目錄
/selinux selinux安全性群組件使用
/media 媒介目錄
/srv 伺服器資料目錄
cd / .. ../.. . ~或者直接斷行符號 -返回上次工作的目錄
查看檔案內容的命令
1.more install.log
2.less install.log
3.head -n 50 install.log
head -50 install.log
4.tail -n 50 install.log
tail -50 install.log
tail -f /var/log/messages 動態監控記錄檔
service gpm restart 重新啟動滑鼠
5.cat install.log
cat -n install.log 所有行號
cat -b install.log 只顯示有效行行號
| 管道符
cat -n install.log | less
建立檔案
touch aa.txt
touch cc.txt tt.txt
touch abc{1..10}.txt
touch a{b,c}{1..5}.txt
建立目錄
mkdir abcd
mkdir abcde abcdf
mkdir abc{1..10}
mkdir a{b,c}{1..5}
mkdir -p xx/pp
mkdir -p -v xx/pp -p 遞迴 -v 顯示建立過程
拷貝剪下
拷貝
cp /root/install.log /tmp/
cp /root/install.log /tmp/test 拷貝過程中重新命名
cp -r /root/Desktop/ /tmp/
剪下
mv
mv /root/tt.txt /tmp/
mv /root/tt.txt /tmp/aa.txt
mv /root/abcd/ /tmp
mv ac3.txt uuu.txt
刪除
rmdir 刪除空目錄
rm aa.txt
rm -f uuu.txt
rm -rf xx/
rm -rf *
rm -rf *.txt
rm -rf ab*
練習:
1.建立以下目錄結構(一條命令完成)(並且驗證)
/aa
/ \
ba/ bc/
/ \ \
ca/ cb/ cc/
mkdir -p /aa/ba/c{a,b} /aa/bc/cc
tree /aa
ls -R /aa
2.由ba目錄進入ca目錄有幾種方法,分別是什麼
3. 拷貝/etc/man.config到ca/ 拷貝過程中將man.config改名為test.txt
mkdir -p /aa/ba/c{a,b} /aa/bc/cc
cp ../etc/man.config ../aa/ba/ca/test.txt
4.剪下test.txt檔案 cc/目錄
mv /aa/ba/ca/test.txt /aa/bc/cc/
5.在兩次拷貝同一檔案到同一個目錄下時,不出現覆蓋提示
\cp /root/install.log /
/bin/cp install.log /
unalias cp
cp /root/install.log /
vim文字編輯器
由命令模式進入輸入模式
a 當前字元後輸入
A 當前行行尾輸入
i 當前字元前輸入
I 當前字元前輸入
o 當前行的下一行輸入
O 當前行的上一行輸入
s 刪除當前字元後輸入
S 刪除當前行後輸入
home鍵 行首 end鍵 行尾
命令模式
u 撤銷一步操作
ctrl+r 重做
複製一行 yy p粘貼(游標所在行的下一行)
複製50行 50yy
剪下一行 dd p粘貼
剪下50行 50dd
刪除一行 dd
刪除50行 50dd
^行首 $行尾
刪除當前字元到行首 d^ y^
刪除當前字元到行尾 d$ y$
w 下一個單詞的首字元
yw 複製一個單詞 dw剪下一個單詞
G 尾行 gg 首行 572G
dgg 刪除當前行到首行
dG 刪除當前行到尾行
末行模式
:w q wq w! q! wq!
:w /tmp/newfile 另存
:2,4w /tmp/newfile2
:e /root/install.log 讀入檔案
:r /tmp/newfile2 追加讀入
:e! 重新讀入當前檔案
尋找
/ 從上向下 ?從下向上 n N 下一個
替換
:%s/ab/$$/gc %所有行 g 全域 s 交換 c互動式替換
:3,6s/ab/$$/ 3-6行替換
練習:
1.替換掉所有開頭的a 換成b
%s/a/b/
2.去掉整個檔案中所有的定位字元(\t)
%s/\t//g
3.去掉2-6行開頭的空格(\s)
2,6s/^ //g
2,6s/^\s//g
4.去掉整個檔案中所有的空格
%s/\s//g
%s/ //g
%s/ *//g
5.將每行分行符號號替換為空白格(\n)
%s/\n/ /g
去掉空行
g/^$/d
g/^\s*$/d
調出行號
set nu
set nonu
set autoindent
set noautoindent
檔案加密
X
vim設定檔/etc/vimrc
多檔案操作
vim aa.txt cc.txt tt.txt
:args :next :prev :last :first ctrl+6
同一屏內開啟多個檔案
vimdiff aa.txt cc.txt tt.txt
ctrl+w+w
vim -O aa.txt cc.txt tt.txt
vim -o aa.txt cc.txt tt.txt 豎向排列
vim的協助文檔
/usr/share/vim/vim70/tutor/tutor.zh.euc
iconv -f UTF8 -t GB18030 tutor.zh.euc -o test.txt
-f 檔案源字元集 -t 輸出字元集 -o 輸出檔案
使用者管理
uid 0 root (管理員) gid 0(Administrator 群組)
uid 1-499 (系統使用者) gid 1-499(系統組)
uid 500-60000(普通使用者) gid 500-60000(普通使用者組)
useradd abc1
使用者資訊檔/etc/passwd
abc1:x:503:503:PT:/home/abc1:/bin/bash
使用者名稱:密碼預留位置:uid:gid:描述資訊:家目錄:shell
useradd -u 1000 -g 503 -c hello -d /mnt/abc2 -s /bin/bash abc2
-u uid -g gid -c 描述 -d 家目錄 -s shell
groupadd uplooking
組資訊檔/etc/group
abc2:x:503:
組名:密碼:gid:如有資訊使用者名稱
groupadd -g 2000 uplooking
練習:
添加組uplooking gid為3000
添加使用者 tom uid為1200 屬於uplooking 家目錄在/mnt下 shell為bash
groupadd -g 3000 uplooking
useradd -u 2000 -g uplooking -c oooo -d /mnt/tom -s /bin/bash tom
密碼
passwd
存放密碼資訊的檔案/etc/shadow
abc2:$1$cYSCxWGT$s9pWcN0lYAIYmd5q6/ilV1:15654:0:99999:7:::
第一列:使用者名稱
第二列:密碼
第三列:最後一次修改密碼的時間
第四列:密碼最小時間
第五列:密碼的最大時間
第六列:密碼到期前警告時間
第七列:密碼到期後帳號到期時間
第八列:帳號有效期間
第九列:保留列
修改組資訊
groupmod
groupmod -g 2500 tt2 改gid
groupmod -n ttnew tt 改組名稱
修改使用者資訊
usermod -u -g -c -d -s 使用者名稱
usermod -f 密碼到期後帳號到期時間 -e 帳號有效期間
usermod -l newname oldname
usermod -L 鎖定帳戶
usermod -U 解鎖帳號
修改密碼資訊
passwd
passwd -n 最小時間 -x 最大時間 -w 警告時間 -i 密碼到期後帳號到期時間
passwd -l 鎖定使用者密碼
passwd -u 解鎖密碼
passwd -S 查看密碼狀態
練習:
建立兩個使用者jack rose 分別設定為密碼123
鎖定jack帳號
鎖定rose密碼
分別終端登入 查看資訊是否一致,能否判斷出現什麼問題?
查看/etc/shadow檔案中該兩個使用者 密碼段 有什麼不同?
刪除群組
groupdel 組名
刪除使用者
userdel -r abc -r連同家目錄一起刪除
關於使用者的設定檔
useradd eric
/etc/default/useradd 使用者預設值檔案
/var/spool/mail/ 使用者郵件資訊目錄
home=/home
shell=/bin/bash
CREATE_MAIL_SPOOL=yes
/etc/login.defs 儲存密碼預設資訊
useradd -G kf,yw wg
usermod -a -G boss abc1
usermod -G yw,kf abc1
useradd -u 0 -o admin
手工系統管理使用者
groupadd redhat
vim /etc/groupadd
redhat:x:5000:
useradd eric
vim /etc/passwd
eric:x:5000:5000:PTuser:/home/eric:/bin/bash
mkdir /home/eric
cp /etc/skel/.bash* /home/eric/
passwd eric
vim /etc/shadow
eric::15654:0:99999:7:::
grub-md5-crypt
終端登入測試密碼 建立檔案aa.txt
多使用者匯入
1.touch user.txt
aa:x:5500:5500::/home/aa:/bin/bash
bb:x:5600:5600::/home/bb:/bin/bash
newusers < user.txt
2.touch passwd.txt
aa:123
bb:123
chpasswd < passwd.txt
家目錄下檔案作用
.bash_history 記錄該使用者執行的曆史命令
.bash_logout 使用者退出時執行的命令
.bashrc nologin-shell層級環境設定檔
.bash_profile login-shell登入層級環境設定檔
/etc/bashrc
/etc/profile
載入順序
/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc
許可權管理
-rw-r--r-- 1 eric uplooking 39410 11-03 13:44 install.log
rw- | r-- | r--
user
group other
eric uplooking 其他人
u g o
root(0)------>uid=eric----->group(uplooking)---->other
檔案
r----------cat head tail more
w----------vim > >>
x----------./ 執行
目錄
r----------ls r-x查詢詳細資料
w----------touch rm -wx才能建立檔案
x----------cd
tt.txt rwxrwxrwx root root
tom rm -rf tt.txt
/test/ rwxr-x--- root root
/test/tt/ rwxrwxrwx
/test/tt/aa.txt rwxrwxrwx
tom rm -rf aa.txt
chmod u+r file/dir
chmod u+r,g-w file/dir
chmod u+r,g-r,o+rw file/dir
chmod ug+rw,o-rw file/dir
chmod ugo+rwx file/dir
chmod a+rwx file/dir
chmod u=r file/dir
chmod u=rw,g=rx file/dir
chmod u=r,g=rx,o=rwx file/dir
chmod ug=rw,o=tx file/dir
chmod ugo=rwx file/dir
chmod a=rwx file/dir
chmod -R 777 test/
r------4 w------2 x------1
rwxrwxrwx-777
561 r-xrw---x -wx-w---x 321
234 -w--wxr--
/ 755
/etc 755
/bin 755
/sbin 755
/var 755
/tmp 1777
/etc/shadow 400
/etc/passwd 644
root管理員建立檔案預設許可權 644
root管理員建立目錄預設許可權 755
普通使用者建立檔案的預設許可權 664
普通使用者建立目錄的預設許可權 775
/root 750
/home/普通使用者家目錄 700
chown tom file/dir
chgrp uplooking file/dir
chown tom.uplooking file/dir
chown tom:uplooking file/dir
chown .uplooking file/dir
chown -R tom.uplooking file/dir
練習:
1.在tmp目錄下建立目錄test 在test目錄下建立檔案aa.txt 建立使用者zorro
要求:
zorro使用者可以刪除aa.txt 但沒是不能讀寫
mkdir /tmp/test/ root root rwxr-xr-x
touch /tmp/test/aa.txt root root rw-r--r--
chmod o-r /tmp/test/aa.txt
chmod o+w /tmp/test
2.在tmp目錄下建立目錄test 在test目錄下建立檔案aa.txt 建立使用者zorro eric
要求:
zorro使用者可以讀寫aa.txt檔案 不能刪除
eric使用者不可以讀寫aa.txt 但是可以刪除
/tmp/test/ eric root rwxr-xr-x
/tmp/test/aa.txt zorro root rw-r-----
zorro
eric
chown zorro /tmp/test/aa.txt
chmod o-r /tmp/test/aa.txt
chown eric /tmp/test/
3.在/root/下建立abc.txt檔案 建立3個使用者zorro,shrek,seker 要求如下:
seker可以讀寫abc.txt檔案 但是不能刪除
zorro唯讀abc.txt檔案 不能刪除
shrek 不可以讀寫abc.txt檔案 但是可以刪除
/root/ root root rwxrwxr-x
/root/abc.txt seker zorro rw-r-----
seker
zorro
shrek ----> root
chmod 640 abc.txt
chown seker.zorro abc.txt
chmod 775 /root/
usermod -a -G root shrek
shrek shrek shrek,hello,root
進階許可權
suid許可權
suid只能加到user
chmod u+s 檔案
suid只能作用到檔案上(二進位可執行檔)
作用:任何使用者在執行擁有suid許可權的命令時,都已該命令擁有者的身份執行
練習:
要求:在不改變/etc/shadow許可權的前題下,使用tom能使用cat查看到shadow內容
which cat
chmod u+s /bin/cat
sgid
只能添加到group
chmod g+s dir/
只能作用到目錄上
作用:任何使用者在擁有sgid許可權的目錄下建立檔案(目錄)時,建立的檔案與該目錄同組
如果建立目錄,則目錄繼承sgid許可權.
練習:
在/tmp目錄下建立test目錄, 該目錄許可權777,建立使用者tom
tom在/tmp/test目錄下建立檔案aa.txt 查看aa.txt資訊
在test目錄上添加sgid許可權
tom在/tmp/test目錄下建立檔案tt.txt 查看tt.txt資訊
tom在/tmp/test目錄下建立建立目錄dir 查看目錄dir的資訊
sticky(t)冒險位,粘貼位
只能添加到other
chmod o+t dir/
只能作用到目錄上
作用:任何使用者在含有t許可權的目錄下建立的檔案,只能擁有者刪除,其他人無權刪除(除了root)
練習:
在/tmp目錄下建立test目錄, 該目錄許可權777,建立使用者tom 建立使用者jerry
使用tom 在test目錄下建立檔案tom.txt
使用jerry 在test目錄下建立檔案jerry.txt
嘗試使用tom刪除jerry.txt 使用jerry刪除tom.txt
是否能刪除?
使用tom 在test目錄下建立檔案tom.txt
使用jerry 在test目錄下建立檔案jerry.txt
在test目錄上添加t許可權
嘗試使用tom刪除jerry.txt 使用jerry刪除tom.txt
是否能刪除?
使用管理員root能否刪除?
使用tom 在test目錄下建立檔案tom.txt
使用jerry 在test目錄下建立檔案jerry.txt
添加使用者zorro 將test目錄擁有者改為zorro
使用zorro能否刪除tom.txt jerry.txt?
源檔案有無x許可權區別
chmod +x aa.txt
[root@localhost tmp]# ll aa.txt
-rwsrwsrwt 1 root root 0 11-11 14:20 aa.txt
[root@localhost tmp]# chmod -x aa.txt
[root@localhost tmp]# ll aa.txt
-rwSrwSrwT 1 root root 0 11-11 14:20 aa.tx
suid-------4
sgid-------2
sticky-----1
1777
2777
4777
3777
進程管理
ps -ef
ps aux
top
前後台切換
xclock -update 1 &
xclock -update 1
ctrl + z
jobs
bg 編號
fg 編號
kill %編號 殺掉
殺進程
kill -15 pid
kill -9 pid
pkill 進程名稱
killall 進程名稱
xkill
優先順序調整(-20~19)
nice -n -20 xclock -update 1
renice 10 -p 6020(pid)
進階命令
cat -n /etc/passwd |head -20 |tail -2 | rev | tac
wc -l行數 -w單詞數 -c字元數
sort -n 按照整個數字排序 -u 去掉重複行 -r 反向排序
uniq 去掉連續的重複行 -u 顯示不重複的行 -d 只顯示重複行 -c統計重複次數
grep root /etc/passwd
grep ^root /etc/passwd
grep halt$ /etc/passwd
grep -v halt$ /etc/passwd 取反
cut
cut -d: -f 1 /etc/passwd
cut -d: -f 1,6 /etc/passwd
cut -d: -f 1-3 /etc/passwd
cut -d: -f 1-3,6 /etc/passwd
cut -c 1,3 /etc/passwd | head -2
cut -c 1-6 /etc/passwd | head -2
練習:
1.計算出你的系統中有多少個可以登入到系統的使用者
cat /etc/passwd | grep -c bash
cat /etc/passwd | grep /bin/bash | wc -l
cat /etc/passwd | grep /bin/bash | cut -d: -f7 |uniq -c
cat -n /etc/passwd | grep /bin/bash | cut -d: -f1,7 |cat -n
2.ifconfig eth0 | awk -F':| +' '/Bcast/{print $4}'
192.168.1.1
ifconfig eth0 | head -2 | tail -1 | cut -d: -f 2 | cut -d' ' -f1
ifconfig eth0 | grep Bcast | cut -d: -f 2 | cut -d' ' -f 1
3. stat aa.txt
File: “aa.txt”
Size: 34 Blocks: 8 IO Block: 4096 一般檔案
Device: 802h/2050d Inode: 48922685 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-11-17 12:06:11.000000000 +0800
Modify: 2012-11-17 12:06:11.000000000 +0800
Change: 2012-11-17 12:06:11.000000000 +0800
只顯示時間
12:06:11
12:06:11
12:06:1
stat aa.txt | tail -3 | cut -d' ' -f3 | cut -d. -f 1
shell基礎
!! !$ !ser
重新導向符
> >>
> 標準正確輸出,如果檔案存在則覆蓋,如果檔案不存則建立
>> 標準正確輸出,如果檔案存在則追加,如果不存在則建立
2> 標準錯誤輸出,如果檔案存在則覆蓋,如果檔案不存在則建立
2>> 標準錯誤輸出,如果檔案存在則追加,如果不存在則建立
0標準正確輸入
&>
迴圈指令碼
#!/bin/bash
#添加使用者的指令碼
for i in {1..10}
do
echo "create user$i now!!!!!please wait!!!!"
sleep 1
useradd user$i
echo "Set user$i password now!!!!!"
echo 123 | passwd --stdin user$i &> /dev/null
echo "The create user$i success!!!!!"
done
判斷指令碼
#!/bin/bash
#判斷檔案是否存在
if [ -f /tmp/aa.txt ]
then
echo "the file is cunzai!!!!!display now!!!1"
sleep 1
ls -l /tmp/aa.txt
else
echo "the file is now cunzai!!!create it now !!!! "
sleep 1
touch /tmp/aa.txt
fi
網路
mii-tool
ifconfig
ifconfig eth0
ifconfig eth0 192.168.1.100/24
setup
設定檔
/etc/sysconfig/network-scripts/ifcfg-eth*
網卡別名
ifconfig eth0:0 10.10.10.1
ifconfig eth0 up
ifconfig eth0 down
ifup eth0
ifdown eth0
; 前邊命令無論是否執行成功,後邊命令都執行
&& 前邊命令執行成功,後邊命令才執行
arping 192.168.1.33
arp
route -n
route add default gw 192.168.1.1
route del default gw 192.168.1.1
traceroute
hostname 查詢主機名稱
hostname zhb.com
vim /etc/sysconfig/network 永久修改
HOSTNAME=zhb.com
注意:主機名稱和ip地址的對應關係
/etc/hosts
開啟路由轉寄功能
cat /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
壓縮,打包,安裝軟體
gzip bzip2
dd if=/dev/zero of=data bs=100M count=2 製作200M的檔案
gzip data
gunzip date.gz
bzip2 data
bunzip2 data.bz2
tar
tar -cvf boot.tar /boot
tar -tvf boot.tar
tar -rvf boot.tar data
tar -xvf boot.tar
tar -cvf /home/boot.tar /boot/
tar -xvf boot.tar -C /home/
tar -zcvf boot.tar.gz /boot
tar -ztvf boot.tar.gz
tar -zxvf boot.tar.gz
tar -jcvf boot.tar.bz2 /boot
tar -jtvf boot.tar.bz2
tar -jxvf boot.tar.bz2
tar -zcvf /home/boot.tar.gz /boot/
tar -zxvf boot.tar -C /home/
mount(掛載)
mount -t iso9660 /dev/cdrom /mnt
mount
umount /dev/cdrom
umount /mnt
-l 強制卸載
製作鏡像
cat /dev/cdrom >> /rhel5u8.iso
dd if=/dev/cdrom of=/rhel5u8.iso
掛載鏡像
mount -t iso9660 /rhel5u8.iso /mnt -o loop
軟體安裝
rpm -ivh httpd-2.2.3-63.el5.i386.rpm 安裝
rpm -q httpd 查詢是否安裝
rpm -qa | grep httpd 查詢所有安裝含有httpd關鍵字的軟體包
rpm -ql httpd 查詢軟體包的安裝路徑
rpm -qf httpd.conf 查詢該檔案是那個軟體包安裝的
rpm -qf `which mount` 同上``優先執行
rpm -qi httpd 查詢httpd軟體包的資訊
rpm -e httpd 卸載軟體包
未安裝的軟體包
rpm -qpi httpd-2.2.3-63.el5.i386.rpm未安裝資訊
rpm -qpl httpd-2.2.3-63.el5.i386.rpm安裝後的路徑
rpm -e apr-devel --nodeps 不檢測依賴關係卸載
rpm -ivh httpd-2.2.3-63.el5.i386.rpm --force 強制安裝
yum庫搭建與使用
1.mount /dev/cdrom /mnt
2.vim /etc/yum.conf
gpgcheck=0
3.cd /etc/yum.repos.d/
touch yum.repo
vim yum.repo
[yum]
name=yum server
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
yum list
yum install httpd-devel
yum remove httpd-devel
yum reinstall httpd-devel
yum clean all
rpm --import RPM-GPG-KEY-redhat-release 匯入key
建立yum庫
建庫命令
rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
/yum 裡邊全是軟體包
createrepo /yum