Linux学习笔记(二)|常用命令
Linux學習筆記(二)常用命令
1.文件處理命令
1.1命令格式與目錄處理 -ls
功能描述:顯示目錄文件
原意:list
所在路徑:/bin/ls
語法:
ls-a 顯示所有文件,包括隱藏文件
ls-l 詳細信息顯示
ls-d 查看目錄屬性
說明:
1)個別命令使用不遵循此格式
2)當有多個選項時,可以寫在一起
3)簡化選項與完整選項-a 等于 --all
1.2目錄處理命令
mkdir
原意:make directories
路徑:/bin/mkdir
語法:mkdir -p【目錄名】
功能:創(chuàng)建新目錄
例:mkdir -p /Derek
cd
原意:change directory
路徑:shell內(nèi)置
語法:cd [目錄]
功能:切換目錄
例:cd /tmp 切換到指定目錄
cd /.. 切換到指定目錄
pwd
原意:print working directory
路徑:/bin/pwd
語法:pwd
功能:顯示當前目錄
例:pwd
rmdir
原意:remove empty directories
路徑:/bin/rmdir
語法:rmdir [目錄名]
功能:刪除空目錄
例:rmdir /tmp/china
cp
原意:copy
路徑:/bin/cp
語法:
cp -r 復制目錄
cp -p 保留文件屬性
功能:復制文件或目錄
例:cp -r /tmp/Derek /root 將目錄/tmp/Derek復制到/root下
rm
原意:remove
路徑:/bin/rm
語法:
rm -r 刪除目錄
rm -f 強制執(zhí)行
功能:刪除文件
例:rm /tmp/yum.log刪除文件yum.log
1.3文件處理命令
touch
命令所在路徑:/bin/touch
執(zhí)行權限:所有用戶
語法:touch [文件名]
功能描述:創(chuàng)建空文件
范例:touch python_test.py 創(chuàng)建py文件
cat
命令所在路徑:/bin/cat
執(zhí)行權限:所有用戶
語法:cat [文件名]
功能描述:顯示文件內(nèi)容
-n 顯示行號
范例: cat /etc/issue
more
命令所在路徑:/bin/more
執(zhí)行權限:所有用戶
語法:more [文件名]
(空格) 或f 翻頁
(Enter) 換行
q或Q 退出
功能描述:分頁顯示文件內(nèi)容
less
命令所在路徑:/usr/bin/less
執(zhí)行權限:所有用戶
語法:less [文件名]
功能描述:分頁顯示文件內(nèi)容(可向上翻頁)
head
命令所在路徑:/usr/bin/head
執(zhí)行權限:所有用戶
語法:head [文件名]
功能描述:顯示文件前面幾行
head -n 指定行數(shù)
tail
命令所在路徑:/usr/bin/tail
執(zhí)行權限:所有用戶
語法:tail [文件名]
功能描述:顯示文件后面幾行
tail -n 指定行數(shù)
tail -f 動態(tài)顯示文件末尾內(nèi)容
1.4鏈接命令
ln
命令英文原意:link
命令所在路徑:/bin/ln
執(zhí)行權限:所有用戶
語法:ln -s [原文件] [目標文件]
-s 創(chuàng)建軟鏈接
功能描述:生成鏈接文件
2.文件搜索命令
find
命令所在路徑:/bin/find
執(zhí)行權限:所有用戶
語法:find [搜索范圍] [匹配條件]
功能描述:文件搜索
范例:
find /etc -name init 在目錄/etc中查找文件init
find /etc -name *init* 在目錄/etc中查找文件名包含init
find /etc -name init??? 在目錄/etc中查找文件名init開頭并有3個字符的
find /etc -name init* 在目錄/etc中查找文件名init開頭的
locate
命令所在路徑:/usr/bin/locate
執(zhí)行權限:所有用戶
語法:locate 文件名
功能描述:在文件資料庫中查找文件
范例:locate inittab
which
命令所在路徑:/usr/bin/which
執(zhí)行權限:所有用戶
語法:which 命令
功能描述:搜索命令所在目錄及別名信息
范例:$which ls
whereis
命令所在路徑:/usr/bin/whereis
執(zhí)行權限:所有用戶
語法:whereis [命令名稱]
功能描述:搜索命令所在目錄及幫助文檔路徑
范例: whereis ls
grep
命令所在路徑:/bin/grep
執(zhí)行權限:所有用戶
語法:grep -iv [指定字串] [文件]
功能描述:在文件中搜尋字串匹配的行并輸出
-i 不區(qū)分大小寫
-v 排除指定字串
范例:grep mysql /root/install.log
# grep -v ^# /etc/inittab 去除以#開頭的所有行信息,^表示以XXX開頭
3.用戶管理命令
useradd
命令所在路徑:/usr/sbin/useradd
執(zhí)行權限:root
語法:useradd 用戶名
功能描述:添加新用戶
范例: useradd yangmi
passwd
命令所在路徑:/usr/bin/passwd
執(zhí)行權限:所有用戶
語法:passwd 用戶名
功能描述:設置用戶
范例: passwd yangmi
普通用戶只能更改自己密碼,root用戶可以更好所有人密碼
who
命令所在路徑:/usr/bin/who
執(zhí)行權限:所有用戶
語法:who
功能描述:查看登錄用戶信息
范例: who
參數(shù)分別為:
用戶名 登錄終端[tty本地終端/pts遠程終端] 登錄時間 IP地址[沒有表示本地登錄]
4.壓縮解壓命令
gzip
命令英文原意:GNU zip
命令所在路徑:/bin/gzip
執(zhí)行權限:所有用戶
語法:gzip [文件]
功能描述:壓縮文件
壓縮后文件格式:.gz
gunzip [= gzip -d]
命令英文原意:GNU unzip
命令所在路徑:/bin/gunzip
執(zhí)行權限:所有用戶
語法:gunzip [壓縮文件]
功能描述:解壓縮.gz的壓縮文件
范例: gunzip boduo.gz
tips:只能壓縮文件不能壓縮目錄
tar
命令所在路徑:/bin/tar
執(zhí)行權限:所有用戶
語法:tar 選項[-zcf] [壓縮后文件名] [目錄]
-c 打包
-v 顯示詳細信息
-f 指定文件名
-z 打包同時壓縮
功能描述:打包目錄 壓縮后文件格式:.tar.gz
范例:
tar -zcf Japan.tar.gz Japan
將目錄Japan打包并壓縮為.tar.gz文件
| tar -x | 解包 |
| tar -v | 顯示詳細信息 |
| tar -f | 指定解壓文件 |
| tar -z | 解壓縮 |
zip
命令所在路徑:/usr/bin/zip
執(zhí)行權限:所有用戶
語法:
zip 選項[-r] [壓縮后文件名] [文件或目錄]
-r 壓縮目錄
功能描述:壓縮文件或目錄
壓縮后文件格式:.zip
范例:
zip china.zip china 壓縮文件
壓縮文件
zip -r Japan.zip Japan 壓縮目錄
tips:會保留原文件
unzip
命令所在路徑:/usr/bin/unzip
執(zhí)行權限:所有用戶
語法:unzip [壓縮文件]
功能描述:解壓.zip的壓縮文件
范例: unzip test.zip
bzip2
命令所在路徑:/usr/bin/bzip2
執(zhí)行權限:所有用戶
語法: bzip2 選項 [-k] [文件]
-k 產(chǎn)生壓縮文件后保留原文件
功能描述:壓縮文件
壓縮后文件格式:.bz2
范例: bzip2 -k boduo
tar -cjf Japan.tar.bz2 Japan
5.網(wǎng)絡命令
write
指令所在路徑:/usr/bin/write
執(zhí)行權限:所有用戶
語法:write <用戶名>
功能描述:給用戶發(fā)信息,以Ctrl+D保存結束
范例: # write linzhiling
tips:輸入錯誤,control+delete 刪除
wall
命令英文原意:write all
指令所在路徑:/usr/bin/wall
執(zhí)行權限:所有用戶
語法:wall [message]
功能描述:發(fā)廣播信息
范例: wall ShenChao is a honest man!
ping
命令所在路徑:/bin/ping
執(zhí)行權限:所有用戶
語法:ping 選項 IP地址
-c 指定發(fā)送次數(shù)
功能描述:測試網(wǎng)絡連通性
范例: ping 192.168.1.156
ifconfig
命令英文原意:interface configure
命令所在路徑:/sbin/ifconfig
執(zhí)行權限:root
語法:ifconfig 網(wǎng)卡名稱 IP地址
功能描述:查看和設置網(wǎng)卡信息
范例: ifconfig eth0 192.168.8.250
mail
命令所在路徑:/bin/mail
執(zhí)行權限:所有用戶
語法:mail [用戶名]
功能描述:查看發(fā)送電子郵件
范例: mail root
last
命令所在路徑:/usr/bin/last
執(zhí)行權限:所有用戶
語法:last
功能描述:列出目前與過去登入系統(tǒng)的用戶信息
范例: last
traceroute
命令所在路徑:/bin/traceroute
執(zhí)行權限:所有用戶
語法:traceroute
功能描述:顯示數(shù)據(jù)包到主機間的路徑
范例:traceroute www.lampbrother.net
netstat
命令所在路徑:/bin/netstat
執(zhí)行權限:所有用戶
語法:netstat [選項]
功能描述:顯示網(wǎng)絡相關信息
選項:
-t : TCP協(xié)議
-u : UDP協(xié)議
-l : 監(jiān)聽
-r : 路由
-n : 顯示IP地址和端口號
范例:
netstat -tlun 查看本機監(jiān)聽的端口
netstat -an 查看本機所有的網(wǎng)絡連接
netstat -rn 查看本機路由表
查看某一端口是否被占用:netstat -tunlp |grep 2181
setup
命令所在路徑:/usr/bin/setup
執(zhí)行權限:root
語法:setup
功能描述:配置網(wǎng)絡
范例: setup
mount
命令位置:/bin/mount
執(zhí)行權限:所有用戶
命令語法:mount [-t 文件系統(tǒng)] 設備文件名 掛載點
范例: mount -t iso9660 /dev/sr0 /mnt/cdrom
總結
以上是生活随笔為你收集整理的Linux学习笔记(二)|常用命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java预科篇2-环境搭建
- 下一篇: Linux学习笔记(三)|Vim编辑器