下面是Linux系統一些常見的操作命令的使用情況介紹,
1.檔案相關命令
1) 檔案創建
① 創建單個檔案
touch test.txt
② 創建多個檔案
touch test1.txt test2.txt
touch {test1.txt,test2.txt}
2) 檔案洗掉
① 洗掉檔案時,系統會詢問是否洗掉
rm test.txt
② 強制洗掉檔案
rm -rf test.txt
3) 檔案移動或重命名
① 檔案移動
mv test.txt /tmp/
② 檔案重命名
mv test.txt a.txt
③ 檔案移動并重命名
mv test.txt /tmp/a.txt
4) 檔案拷貝、追加或重命名
① 檔案拷貝
cp test.txt /tmp/
② 檔案拷貝并重命名
cp test.txt /tmp/a.txt
③ 一個檔案內容拷貝到里另一個檔案中
cat test1.txt > test2.txt
④ 一個檔案內容追加到里另一個檔案中
cat test1.txt >> test2.txt
5) vim檔案操作
① vim作業模式

② 插入命令

③ 定位命令

④ 洗掉命令

⑤ 替換和取消命令

6) 檔案內容查看cat、more、less、head、tail、grep、cut、sort
① 正序查看
cat test.txt
② 倒序查看
tac test.txt
③ 從前向后以頁讀取檔案(上翻:[b],下翻:[空格鍵])
more test.txt
④ 從第5行向后以頁讀取檔案(上翻:[b],下翻:[空格鍵])
more +5 test.txt
⑤ 查找第一個出現"test"字串的行,并從該處前兩行開始顯示輸出
more +/test test.txt
⑥ 從前向后以頁讀取檔案(上翻:[pageup],下翻:[pagedown])
less test.txt
⑦ 顯示檔案的前n行(默認10行,不帶n)
head -n test.txt
⑧ 顯示檔案的后n行(默認10行,不帶n)
tail -n test.txt
⑨ 跟蹤顯示檔案新追加的內容
tail -f test.txt
⑩ 文本過濾,模糊查找含字母a的行
grep a test.txt
? 顯示test.txt檔案第1,3,5行(-d:指定分隔符;-f:指定檔案)
cut -d : -f 1,3,5 test.txt
? 檔案內容排序(-k:指定欄位;3:第三列;-t:指定分割符;-n:以數字大小進行排序,-u:去重)
sort -k 3 -t : -n -u test.txt
7) 給檔案設定擁有者,權限
① 將test.txt的用戶擁有者設為zwh1,組的擁有者設為zwh2
chown zwh1:zwh2 test.txt
② 將當前目錄下的所有檔案與子目錄的用戶擁有者為zwh1,組擁有者設為zwh2
chown -R zwh1:zwh2 *
③ 將當前目錄下的所有檔案與子目錄皆設為任何人可讀取
chmod -R a+r *
④ 將test1.txt 與test2.txt設為其擁有者和其所屬同一個組者可寫入,但其他以外的人則不可寫入
chmod ug+w,o-w test1.txt test2.txt
8)其他他檔案操作
① 查看檔案詳情
stat test.txt
② 查看檔案大小
du -h test.txt [root@hdp1 /]# du -h zwh/ 4.0K zwh/
③ 查看檔案夾及子目錄檔案大小
du -ah zwh/ [root@hdp1 /]# du -ah zwh/ 0 zwh/test1.txt 0 zwh/test2.txt 4.0K zwh/test.txt 4.0K zwh/
④ 回到原來路徑
cd -
⑤ 回到上級路徑
cd ..
2.系統命令
1)主機名操作
① 查看主機名
hostname
② 修改主機名(重啟后永久生效),將名字修改即可
vim /etc/hostname
2)修改IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
3)查看系統資訊
① 顯示全部資訊
uname -a
② 顯示作業系統的發行編號
uname -r
③ 顯示作業系統名稱
uname -s
4) 查看檔案資訊
file test.txt
5) 查看磁區
df -h
6) 查看用戶最近登錄情況
last
3.用戶和組
1) 用戶操作
① 添加一個tom用戶,設定它屬于users組,并添加注釋資訊
useradd -g users -c "hr tom" tom
② 設定tom用戶的密碼
passwd tom
③ 修改tom用戶的登陸名為tom1
usermod -l tom1 tom
④ 將tom添加到zwh和root組中
usermod -G zwh,root tom
2) 用戶組操作
① 添加一個zwh的組
groupadd zwh
② 將tom用戶從root組和zwh組洗掉
gpasswd -d tom root和gpasswd -d tom zwh
③ 將zwh組名修改為zwh1
groupmod -n zwh1 zwh
4.查找
1) 查找可執行的命令
which ls
2) 從某個檔案夾開始查找
find / -name "zwh*" -ls
3) 查找并洗掉
find / -name "zwh*" -ok rm {} \;
find / -name "zwh*" -exec rm {} \;
4) 查找用戶為hadoop的檔案
find /usr -user hadoop -ls
5) 查找用戶為hadoop并且(-a)擁有組為root的檔案
find /usr -user hadoop -a -group root -ls
6) 查找用戶為hadoop或者(-o)擁有組為root并且是檔案夾型別的檔案
find /usr -user hadoop -o -group root -a -type d
7) 查找權限為777的檔案
find / -perm -777 -type d -ls
8) 顯示命令歷史
history
5.打包和壓縮
1) gzip壓縮
gzip test.txt
2) 解壓
gzip -d test.txt.gz
3) bzip2壓縮
bzip2 test
4) 解壓
bzip2 -d test.bz2
5) 打包并壓縮成bz2
tar -jcvf a.tar.bz2
6) 解壓bz2
tar -jxvf a.tar.bz2
7) 將當前目錄的檔案打包
tar -cvf bak.tar .
8) 解壓
tar -xvf bak.tar
9) 打包并壓縮gzip
tar -zcvf test.tar.gz
10) 解壓縮
tar -zxvf test.tar.gz
11) 解壓到/usr/下
tar -zxvf test.tar.gz -C /usr
12) 查看壓縮包內容
tar -ztvf test.tar.gz
6.防火墻
Centos7:
1) 查看防火墻狀態
firewall-cmd --state
2) 停止防火墻
systemctl stop firewalld.service
3) 開啟防火墻
systemctl start firewalld.service
4) 禁止firewall開機啟動
systemctl disable firewalld.service
Centos6:
1) 查看防火墻狀態
service iptables status
2)停止防火墻
service iptables stop
3)開啟防火墻
service iptables star
4)查看iptables是否開機啟
chkconfig iptables --list
5)設定iptables開機啟動
chkconfig iptables on
6)設定iptables開機不啟動
chkconfig iptables off
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/60911.html
標籤:Linux
上一篇:16進制轉字符亂碼是啥情況
下一篇:Linux下用戶的創建與洗掉
