1.文件目錄類
1)pwd指令
基本語法:
pwd
功能描述:顯示當前工作目錄的絕對路徑。
eg:
[root@localhost ~]# pwd
/root
2)ls指令
基本語法:
ls [選項] [目錄或是文件]
常用選項:
-a:顯示當前目錄所有的文件和目錄,包括隱藏的。
-l:以列表的方式顯示信息。
eg:查看當前目錄下的所有內容信息。
[root@localhost /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@localhost /]# ls -a
. .. bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@localhost /]# ls -l
總用量 24
lrwxrwxrwx. 1 root root 7 11月 5 21:52 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 11月 5 22:16 boot
drwxr-xr-x. 20 root root 3300 11月 6 15:23 dev
drwxr-xr-x. 138 root root 8192 11月 6 15:23 etc
drwxr-xr-x. 3 root root 17 11月 5 22:21 home
lrwxrwxrwx. 1 root root 7 11月 5 21:52 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 11月 5 21:52 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 11月 5 2016 media
drwxr-xr-x. 2 root root 6 11月 5 2016 mnt
drwxr-xr-x. 3 root root 16 11月 5 22:06 opt
dr-xr-xr-x. 206 root root 0 11月 6 15:21 proc
dr-xr-x---. 5 root root 184 11月 6 15:25 root
drwxr-xr-x. 41 root root 1200 11月 6 15:26 run
lrwxrwxrwx. 1 root root 8 11月 5 21:52 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 11月 5 2016 srv
dr-xr-xr-x. 13 root root 0 11月 6 15:21 sys
drwxrwxrwt. 24 root root 4096 11月 6 15:25 tmp
drwxr-xr-x. 13 root root 155 11月 5 21:52 usr
drwxr-xr-x. 21 root root 4096 11月 5 22:14 var
[root@localhost /]# ls -al
總用量 24
dr-xr-xr-x. 17 root root 224 11月 5 22:12 .
dr-xr-xr-x. 17 root root 224 11月 5 22:12 ..
lrwxrwxrwx. 1 root root 7 11月 5 21:52 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 11月 5 22:16 boot
drwxr-xr-x. 20 root root 3300 11月 6 15:23 dev
drwxr-xr-x. 138 root root 8192 11月 6 15:23 etc
drwxr-xr-x. 3 root root 17 11月 5 22:21 home
lrwxrwxrwx. 1 root root 7 11月 5 21:52 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 11月 5 21:52 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 11月 5 2016 media
drwxr-xr-x. 2 root root 6 11月 5 2016 mnt
drwxr-xr-x. 3 root root 16 11月 5 22:06 opt
dr-xr-xr-x. 206 root root 0 11月 6 15:21 proc
dr-xr-x---. 5 root root 184 11月 6 15:25 root
drwxr-xr-x. 41 root root 1200 11月 6 15:26 run
lrwxrwxrwx. 1 root root 8 11月 5 21:52 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 11月 5 2016 srv
dr-xr-xr-x. 13 root root 0 11月 6 15:21 sys
drwxrwxrwt. 24 root root 4096 11月 6 15:25 tmp
drwxr-xr-x. 13 root root 155 11月 5 21:52 usr
drwxr-xr-x. 21 root root 4096 11月 5 22:14 var
3)cd指令
基本語法:
cd [參數]
功能描述:切換到指定目錄。
常用參數:
絕對路徑和相對路徑。
4)mkdir指令
基本語法:
makdir [選項] 要創建的目錄。
功能描述:用於創建目錄。
常用參數:
-p:創建多級目錄。
eg:
[root@localhost home]# mkdir dog
[root@localhost home]# ls
dog roo
[root@localhost home]# mkdir -p ssg/skt
[root@localhost home]# ls
dog roo ssg
[root@localhost home]# cd ssg
[root@localhost ssg]# ls
skt
5)rmdir指令
基本語法:
rmdir [選項] 要刪除的空目錄。
功能描述:刪除空目錄
eg:
[root@localhost home]# ls
dog roo ssg
[root@localhost home]# rmdir dog
[root@localhost home]# ls
roo ssg
注意:rmdir指令刪除的是空目錄,如果目錄下有內容使用rm -rf進行刪除。
6)touch指令
基本語法:
touch 文件名稱
功能描述:創建空文件。
eg:
[root@localhost home]# ls
roo ssg
[root@localhost home]# touch hello.txt bell.txt
[root@localhost home]# ls
bell.txt hello.txt roo ssg
7)rm指令
基本語法:
rm [選項] 要刪除的文件或目錄
功能描述:刪除文件或目錄。
常用選項:
-r:遞歸刪除整個文件夾。
-f:強制刪除不提示。
eg:
[root@localhost home]# ls
bell.txt hello.txt roo ssg
[root@localhost home]# rm -f hello.txt bell.txt
[root@localhost home]# ls
roo ssg
[root@localhost home]# rm -r ssg
rm:是否進入目錄"ssg"? y
rm:是否刪除目錄 "ssg/skt"?y
rm:是否刪除目錄 "ssg"?y
[root@localhost home]# ls
roo
8)cp指令
基本語法:
cp [選項] source dest
功能描述:拷貝文件到指令目錄。
常用選項:
-r:遞歸複製整個文件夾。
eg:
★將/home/aa.txt拷貝到/home/bb目錄下[拷貝單個文件]
[root@localhost home]# touch aa.txt
[root@localhost home]# mkdir bb
[root@localhost home]# ls
aa.txt bb roo
[root@localhost home]# cp aa.txt bb
[root@localhost home]# cd bb
[root@localhost bb]# ls
aa.txt
★將/home/test整個目錄拷貝到/home/lyc目錄。
[root@localhost home]# mkdir -p test/pp/lf lyc
[root@localhost home]# ls
lyc roo test
[root@localhost home]# cd test
[root@localhost test]# ls
pp
[root@localhost home]# cp -r test lyc
[root@localhost home]# cd lyc
[root@localhost lyc]# ls
test
[root@localhost lyc]# cd test
[root@localhost test]# ls
pp
注意:強制覆蓋不提示的的方法:\cp
9)mv指令
基本語法:
mv old FileName newFileName (重命名)
mv moveFile targetFolder (移動文件)
eg:
★a.txt重命名爲b.txt
[root@localhost home]# touch a.txt
[root@localhost home]# ls
a.txt lyc roo test
[root@localhost home]# mv a.txt b.txt
[root@localhost home]# ls
b.txt lyc roo test
★將/home/a.txt文件移動到/root目錄下。
[root@localhost home]# mv b.txt /root
[root@localhost home]# cd /root
[root@localhost ~]# ls
anaconda-ks.cfg b.txt initial-setup-ks.cfg
10)cat指令
基本語法:
cat [選項] 要查看的文件。
常用選項:
-n:顯示行號
11)echo指令
基本語法:
echo [選項] 輸出內容。
eg:
[root@localhost ~]# echo hello world
hello world
12)head指令
基本語法:
head 文件 (查看文件頭10行內容)
head -n number 文件 (查看文件頭number行內容,number是任意行數)
功能描述:
顯示文件開頭的內容,默認顯示頭10行內容。
13)tail指令
基本語法:
tail 文件 (查看文件後10行內容)
tail -n number 文件 (查看文件後number行內容,nmber是任意行數)
tail -f 文件 (實時追蹤該文件的更新)
功能描述:
顯示文件末尾的內容,默認顯示後10行。
2.壓縮和解壓類
1)gzip指令和gunzip指令
功能描述:gzip指令用於壓縮文件,gunzip指令用於解壓文件。
基本語法:
gzip 文件 (只能將文件壓縮爲.gz文件)
gunzip 文件.gz (解壓縮文件命令)
eg:
★壓縮a.txt文件
[root@localhost home]# touch a.txt
[root@localhost home]# ls
a.txt lyc roo test
[root@localhost home]# gzip a.txt
[root@localhost home]# ls
a.txt.gz lyc roo test
★解壓文件a.txt.gz
[root@localhost home]# gunzip a.txt.gz
[root@localhost home]# ls
a.txt lyc roo test
注意:當我們使用gzip指令進行壓縮文件時,不會保留源文件。
2)zip指令和unzip指令
功能描述:zip指令用於壓縮文件,unzip用於解壓文件。
基本語法:
zip [選項] xxx.zip 將要壓縮的內容
unzip [選項] xxx.zip 解壓縮文件
zip常用選項:
-r:遞歸壓縮,即壓縮目錄。
unzip常用選項:
-d<目錄>:制定解壓後文件的存放目錄。
3)tar指令
功能描述:打包指令,最後打包後的文件是.tar.gz的文件。
基本語法:
tar [選項] xxx.tar.gz 打包的內容
常用選項:
-c:產生.tar打包文件
-v:顯示詳細信息
-f:指定壓縮後的文件名
-z:打包同時壓縮
-x:解包.tar文件