
1.printf格式化輸出(format and print data)
文法:printf(選項)(參數)
參數
輸出格式:指定資料輸出時的格式;
輸出字元串:指定要輸出的資料。
格式替代符
%c ASCII字元。顯示相對應參數的第一個字元
%d, %i 十進制整數
%e, %E, %f 浮點格式
%g %e或%f轉換,看哪一個較短,則删除結尾的零
%G %E或%f轉換,看哪一個較短,則删除結尾的零
%o 不帶正負号的八進制值
%s 字元串
%u 不帶正負号的十進制值
%x 不帶正負号的十六進制值,使用a至f表示10至15
%X 不帶正負号的十六進制值,使用A至F表示10至15
%% 字面意義的%
[root@test ~]# printf '%c\n' 1010
1
[root@test ~]# printf '%d\n' 123
123
[root@test ~]# printf '%e\n' 123
1.230000e+02
[root@test ~]# printf '%E\n' 123
1.230000E+02
[root@test ~]# printf '%f\n' 123
123.000000
[root@test ~]# printf '%g\n' 123
123
[root@test ~]# printf '%g\n' 123.123456
123.123
[root@test ~]# printf '%g\n' 123.000456
123
[root@test ~]# printf '%g\n' 123.00456
123.005
[root@test ~]# printf '%g\n' 123.00446
123.004
[root@test ~]# printf '%G\n' 123.00446
123.004
[root@test ~]# printf '%o\n' 101010
305222
[root@test ~]# printf '%o\n' 8
10
[root@test ~]# printf '%o\n' 8888
21270
[root@test ~]# printf '%s\n' abc
abc
[root@test ~]# printf '%u\n' -100
18446744073709551516
[root@test ~]# printf '%u\n' 100
100
[root@test ~]# printf '%x\n' 1010
3f2
[root@test ~]# printf '%x\n' -1010
fffffffffffffc0e
[root@test ~]# printf '%X\n' -1010
FFFFFFFFFFFFFC0E
[root@test ~]# printf '%X\n' 1010
3F2
[root@test ~]# printf '%%\n' 1010
%
轉義序列
- \a 警告字元,通常為ASCII的BEL字元
- \b 後退
- \c 抑制(不顯示)輸出結果中任何結尾的換行字元(隻在%b格式訓示符控制下的參數字元串中有效),而且,任何留在參數裡的字元、任何接下來的參數以及任何留在格式字元串中的字元,都被忽略
- \f 換頁(formfeed)
- \n 換行
- \r 回車(Carriage return)
- \t 水準制表符
- \v 垂直制表符
- \\ 一個字面上的反斜杠字元
[root@test ~]# printf 'abc\babc\n'
ababc
[root@test ~]# printf 'abc\cabc\n'
abc\cabc
[root@test ~]# printf 'abc\cabc\naaaa'
abc\cabc
aaaa[root@test ~]# printf 'abc\cabc\naaaa\nbadfas'
abc\cabc
aaaa
badfas[root@test ~]# printf 'abc\cabc\naaaa\fbadfas'
abc\cabc
aaaa
badfas[root@test ~]# printf 'abc\cabc\naaaa\fbadfas\n'
abc\cabc
aaaa
badfas
[root@test ~]# printf 'abc\cabc\naaaa\f\rbadfas\n'
abc\cabc
aaaa
badfas
[root@test ~]# printf 'abc\cabc\naaaa\f\rba\rdfas\n'
abc\cabc
aaaa
dfas
[root@test ~]# printf 'abc\cabc\naaaa\f\rbadfas\n'
abc\cabc
aaaa
badfas
[root@test ~]# printf 'abc\cabc\na\raaa\f\rbadfas\n'
abc\cabc
aaa
badfas
[root@test ~]# printf 'aaaa\tbbbn'
aaaa bbbn[root@test ~]# printf 'aaaa\tbbb\n'
aaaa bbb
[root@test ~]# printf 'aaaa\vbbb\n'
aaaa
bbb
[root@test ~]# printf 'aaaa\\bbb\n'
aaaa\bbb
[root@test ~]#
2.mkdir:建立空目錄
文法:mkdir (選項)(參數)
-p:parents如果目錄存在則不建立也不報錯,若不存在則建立需要的目錄
[root@test ~]# ls
scripts
[root@test ~]# mkdir test/xxx/abc -p
[root@test ~]# ls
scripts test
[root@test ~]# tree test
test
`-- xxx
`-- abc
2 directories, 0 files
-v:verbose 詳細資訊,顯示建立過程
[root@test ~]# mkdir -pv abc/bcd/dce/efg
mkdir: created directory `abc'
mkdir: created directory `abc/bcd'
mkdir: created directory `abc/bcd/dce'
mkdir: created directory `abc/bcd/dce/efg'
{}大括号展開
[root@test ~]# mkdir -pv xxx/{a,b,c}/bcd
mkdir: created directory `xxx'
mkdir: created directory `xxx/a'
mkdir: created directory `xxx/a/bcd'
mkdir: created directory `xxx/b'
mkdir: created directory `xxx/b/bcd'
mkdir: created directory `xxx/c'
mkdir: created directory `xxx/c/bcd'
[root@test ~]# tree xxx
xxx
|-- a
| `-- bcd
|-- b
| `-- bcd
`-- c
`-- bcd
6 directories, 0 files
[root@test ~]# mkdir -pv xxx/{a,b}_{b,c}_{d,e}
mkdir: created directory `xxx/a_b_d'
mkdir: created directory `xxx/a_b_e'
mkdir: created directory `xxx/a_c_d'
mkdir: created directory `xxx/a_c_e'
mkdir: created directory `xxx/b_b_d'
mkdir: created directory `xxx/b_b_e'
mkdir: created directory `xxx/b_c_d'
mkdir: created directory `xxx/b_c_e'
[root@test ~]# tree xxx
xxx
|-- a
| `-- bcd
|-- a_b_d
|-- a_b_e
|-- a_c_d
|-- a_c_e
|-- b
| `-- bcd
|-- b_b_d
|-- b_b_e
|-- b_c_d
|-- b_c_e
`-- c
`-- bcd
14 directories, 0 files
-m:指定檔案目錄的權限,直接指定權限不受umask影響
[qiuhom@test xx]$ ll
total 0
[qiuhom@test xx]$ mkdir test
[qiuhom@test xx]$ ll
total 4
drwxrwxr-x 2 qiuhom qiuhom 4096 Oct 19 15:26 test
[qiuhom@test xx]$ mkdir -m 400 test2
[qiuhom@test xx]$ ll
total 8
drwxrwxr-x 2 qiuhom qiuhom 4096 Oct 19 15:26 test
dr-------- 2 qiuhom qiuhom 4096 Oct 19 15:27 test2
3.rmdir:删除空目錄(remove directory)隻允許删除空目錄,非空目錄删不了
[root@test ~]# tree aaa
aaa
0 directories, 0 files
[root@test ~]# rmdir aaa
[root@test ~]# tree abc
abc
`-- bcd
`-- dce
`-- efg
3 directories, 0 files
[root@test ~]# rmdir abc
rmdir: failed to remove `abc': Directory not empty
4.tree:檢視檔案系統樹,檢視目錄樹
[root@test work]# tree scripts
scripts
|-- auto_bak_log.sh
|-- auto_delete_log.sh
|-- batch_create_user.sh
|-- batch_delete_user.sh
|-- clear
|-- nginx_install.sh
`-- rsync_server_config.sh
0 directories, 7 files
[root@test work]# tree mysql_log/
mysql_log/
`-- mysql.log
0 directories, 1 file
5.touch:建立一個空檔案,這個指令的主要作用是改變檔案的時間戳(change file timestamps)
文法:touch [OPTION]... FILE...
-c:不建立檔案,檔案不存在不建立檔案,預設不加-c 是檔案不存在就建立檔案,所有這個指令才有了建立檔案的功能。
[root@test xxx]# ls
[root@test xxx]# touch -c abc
[root@test xxx]# ls
預設不加-c就是檔案不存在就建立檔案
[root@test xxx]# ls
[root@test xxx]# touch abc
[root@test xxx]# ls
abc
提示:建立檔案,可以使用文本編輯器來建立
-a:隻改變通路時間(access time)
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:32:34.842999349 +0800
Modify: 2018-10-16 21:32:34.842999349 +0800
Change: 2018-10-16 21:32:34.842999349 +0800
[root@test xxx]# touch -a abc
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:32:34.842999349 +0800
Change: 2018-10-16 21:33:23.714999000 +0800
提示:改變通路時間,檔案的改變時間也會跟着發生改變,因為隻要檔案發生了改變,change所對應的時間也就會更新
-m:隻改變修改時間(modify time)
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:32:34.842999349 +0800
Change: 2018-10-16 21:33:23.714999000 +0800
[root@test xxx]# touch -m abc
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:37:13.442000125 +0800
Change: 2018-10-16 21:37:13.442000125 +0800
-t:指定時間
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:37:13.442000125 +0800
Change: 2018-10-16 21:37:13.442000125 +0800
[root@test xxx]# touch -m -t 201010101254.33 abc
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2010-10-10 12:54:33.000000000 +0800
Change: 2018-10-16 21:43:55.968996321 +0800
6.stat:檢視檔案的詳細屬性
[root@test ~]# stat scripts
File: `scripts'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 131075 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:17:07.214995505 +0800
Modify: 2018-09-14 10:52:57.264000280 +0800
Change: 2018-10-16 21:17:01.983000675 +0800
[root@test ~]# stat abc
File: `abc'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 140544 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:23:40.826000125 +0800
Modify: 2018-10-16 21:19:30.404995317 +0800
Change: 2018-10-16 21:19:30.404995317 +0800
7.rm(remove)删除檔案
文法:rm (選項)(參數)
-i:删除已有檔案或目錄之前先詢問使用者
[root@test xxx]# ls
abc
[root@test xxx]# rm -i abc
rm: remove regular empty file `abc'? y
[root@test xxx]# ls
[root@test xxx]#
-f:強制删除檔案或目錄(不詢問使用者)
[root@test xxx]# ls
bcd
[root@test xxx]# rm -f bcd
[root@test xxx]# ls
[root@test xxx]#
-r:遞歸處理,将指定目錄下的所有檔案與子目錄一并處理
[root@test ~]# tree test
test
`-- xxx
`-- abc
2 directories, 0 files
[root@test ~]# \rm -r test
[root@test ~]# ls
scripts xxx
說明:以上執行個體是因為rm是一個别名,它指向的指令是 rm -i 所有我用反斜線取消别名所指定的指令。
8.cp複制檔案或目錄
文法:cp(選項)(參數)
-d:隻複制連結檔案,不複制連結檔案所指向的檔案。
[root@test ~]# ls
scripts xxx
[root@test ~]# ll /application/
total 1512
drwxrwxr-x 9 root root 4096 Aug 31 17:08 haproxy-1.6.2
-rw-r--r-- 1 root root 1538976 Aug 15 15:53 haproxy-1.6.2.tar.gz
lrwxrwxrwx 1 root root 25 Jul 28 01:10 nginx -> /application/nginx-1.6.3/
drwxr-xr-x 11 root root 4096 Jul 28 01:10 nginx-1.6.3
[root@test ~]# cp -d /application/nginx /root/
[root@test ~]# ls -l /root/
total 8
lrwxrwxrwx 1 root root 25 Oct 16 21:58 nginx -> /application/nginx-1.6.3/
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 21:51 xxx
-f:強制覆寫檔案(非互動)
[root@test ~]# ll xxx/
total 16
-rw-r--r-- 1 root root 4534 Oct 16 22:09 123
-rwxr-xr-x 1 root root 4534 Oct 16 22:04 sshd
[root@test ~]# \cp -f scripts/nohup.out xxx/123
[root@test ~]# ll xxx/
total 8
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 4534 Oct 16 22:04 sshd
提示:\的作用是取消别名
-i:覆寫既有檔案之前先詢問使用者;
[root@test ~]# ll xxx/
total 8
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 4534 Oct 16 22:04 sshd
[root@test ~]# \cp -i xxx/123 xxx/sshd
cp: overwrite `xxx/sshd'? y
[root@test ~]# ll xxx/
total 0
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 0 Oct 16 22:14 sshd
-l:對源檔案建立硬連接配接,而非複制檔案
[root@test ~]# ls -l xxx/
total 0
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 0 Oct 16 22:14 sshd
[root@test ~]# cp -l xxx/sshd abc
[root@test ~]# ll
total 12
-rwxr-xr-x 2 root root 0 Oct 16 22:14 abc
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 22:06 xxx
[root@test ~]# ll xxx/
total 0
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 2 root root 0 Oct 16 22:14 sshd
提示:我們可以看到sshd 前面硬連結數目增加了1.當然我們也可以用inode方式去看,如果連個檔案的inode号一樣 那麼就說明他們是同一個檔案。
[root@test ~]# ll -i xxx/sshd abc
135455 -rwxr-xr-x 2 root root 0 Oct 16 22:14 abc
135455 -rwxr-xr-x 2 root root 0 Oct 16 22:14 xxx/sshd
說明:以上執行個體說明cp -l 是對檔案建立硬連結,而非複制檔案
-R/r:遞歸處理,将指定目錄下的所有檔案與子目錄一并處理
[root@test xxx]# ls
[root@test xxx]# cp -r /etc/init.d/ /root/xxx/
[root@test xxx]# ls
init.d
[root@test xxx]# tree
.
`-- init.d
|-- DbSecuritySpt
|-- abrt-ccpp
|-- abrt-oops
|-- abrtd
|-- acpid
|-- atd
|-- auditd
|-- blk-availability
|-- cpuspeed
|-- crond
|-- functions
...
-s:對源檔案建立符号連接配接,而非複制檔案;
[root@test ~]# ll
total 12
-rwxr-xr-x 1 root root 0 Oct 16 22:14 abc
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 22:31 xxx
[root@test ~]# cp -s nginx_install.sh test
[root@test ~]# ll
total 12
-rwxr-xr-x 1 root root 0 Oct 16 22:14 abc
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
drwxr-xr-x 2 root root 4096 Oct 16 22:31 xxx
[root@test ~]#
-b:覆寫已存在的檔案目标前将目标檔案備份;
[root@test xxx]# ls
ttt
[root@test xxx]# \cp -b ../abc ttt
[root@test xxx]# ls
ttt ttt~
[root@test xxx]#
-v:詳細顯示指令執行的操作。
[root@test ~]# cp -v nginx_install.sh ooo
`nginx_install.sh' -> `ooo'
-p:保留源檔案的屬主,屬組 和建立時間等屬性
[root@test ~]# ls -l abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
[root@test ~]# cp -p abc ddd
[root@test ~]# ls -l ddd
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-a:歸檔複制,常用于備份參數的效果和同時指定"-dpR"參數相同
[qiuhom@test ~]$ ll
total 39636
-rw-r-S--- 1 root root 20163 Sep 20 18:36 a.txt
-rw-r--r-- 1 root root 4227297 Oct 14 11:19 bin.tar.gz
-rw-r--r-- 1 root root 50566 Oct 14 11:21 etc_rc_init.tar.gz
-rwsr--r-- 1 qiuhom qiuhom 177 Sep 12 10:55 mycron
-rw-r--r-- 1 root root 36277770 Oct 14 11:20 usr_bin.tar.gz
[qiuhom@test ~]$ cp -a bin.tar.gz test
[qiuhom@test ~]$ ll
total 43768
-rw-r-S--- 1 root root 20163 Sep 20 18:36 a.txt
-rw-r--r-- 1 root root 4227297 Oct 14 11:19 bin.tar.gz
-rw-r--r-- 1 root root 50566 Oct 14 11:21 etc_rc_init.tar.gz
-rwsr--r-- 1 qiuhom qiuhom 177 Sep 12 10:55 mycron
-rw-r--r-- 1 qiuhom qiuhom 4227297 Oct 14 11:19 test
-rw-r--r-- 1 root root 36277770 Oct 14 11:20 usr_bin.tar.gz
[qiuhom@test ~]$ stat bin.tar.gz
File: `bin.tar.gz'
Size: 4227297 Blocks: 8264 IO Block: 4096 regular file
Device: 803h/2051d Inode: 135931 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 23:47:19.533000125 +0800
Modify: 2018-10-14 11:19:50.026000238 +0800
Change: 2018-10-14 11:19:50.026000238 +0800
[qiuhom@test ~]$ stat test
File: `test'
Size: 4227297 Blocks: 8264 IO Block: 4096 regular file
Device: 803h/2051d Inode: 140564 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ qiuhom) Gid: ( 500/ qiuhom)
Access: 2018-10-14 11:30:35.254999044 +0800
Modify: 2018-10-14 11:19:50.026000238 +0800
Change: 2018-10-16 23:47:19.536000125 +0800
提示:因為執行cp指令 會通路源檔案,所有屬性裡的通路時間會發生變化,而目标檔案的通路時間和修改是件和源檔案被通路前的時間一樣。應為生成新的檔案,是以目标檔案的改變是見和源檔案的通路時間一樣,兩者是同時發生的。
9.mv(move)移動檔案
文法:mv(選項)(參數)
mv SRC DEST
mv -t DEST SRC
移動單個檔案到指定文目錄
[root@test ~]# ls
aaa abc ddd jjj nginx_install.sh ooo scripts test xxx
[root@test ~]# mv abc xxx
[root@test ~]# ls
aaa ddd jjj nginx_install.sh ooo scripts test xxx
[root@test ~]# ls xxx
abc ttt ttt~
移動多個檔案到指定目錄下
[root@test ~]# ll
total 20
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rwxr-xr-x 1 root root 0 Oct 16 22:39 jjj
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
-rw-r--r-- 1 root root 693 Oct 16 22:35 ooo
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
drwxr-xr-x 2 root root 4096 Oct 16 22:42 xxx
[root@test ~]# mv ddd jjj nginx_install.sh test ooo xxx
[root@test ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 22:44 xxx
[root@test ~]# ll xxx
total 8
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rwxr-xr-x 1 root root 0 Oct 16 22:39 jjj
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
-rw-r--r-- 1 root root 693 Oct 16 22:35 ooo
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rwxr-xr-x 1 root root 0 Oct 16 22:34 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~
當目标檔案是檔案是會覆寫其目标檔案
[root@test xxx]# ll
total 8
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rwxr-xr-x 1 root root 0 Oct 16 22:39 jjj
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rw-r--r-- 1 root root 693 Oct 16 22:35 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~
[root@test xxx]# mv jjj ttt
mv: overwrite `ttt'? y
[root@test xxx]# ll
total 4
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~
提示:可以看到ttt檔案的大小發生了改變,說明ttt原有的資料被jjj給覆寫了
當源檔案是多個檔案時,目标檔案必須是目錄
[root@test xxx]# ll
total 4
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~
[root@test xxx]# mv abc ddd ttt
mv: target `ttt' is not a directory
[root@test xxx]# mv abc ddd ttt ..
[root@test xxx]# ls
nginx_install.sh test ttt~
[root@test xxx]#
-t:指定目标目錄(這裡必須是目錄,檔案不行)
[root@test xxx]# ls
nginx_install.sh test ttt~
[root@test xxx]# mv -t /tmp test nginx_install.sh ttt~
[root@test xxx]# ll
total 0
[root@test xxx]# ls /tmp
Gtcpe gates.lod nginx_install.sh test_dir yum_save_tx-2018-10-13-19-486q4O6n.yumtx
conf.n moni.lod test ttt~
在同目錄下,可以更改檔案名
[root@test ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
[root@test ~]# mv ddd abc
[root@test ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
10.install :複制檔案和設定屬性
-d:建立目錄
[root@test ~]# ls
aaa abc scripts ttt xxx
[root@test ~]# install -d bbb/cccc/ddd
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
[root@test ~]# tree bbb
bbb
`-- cccc
`-- ddd
2 directories, 0 files
提示:這個建立目錄和mkdir -p類似
-m:指定權限,預設是rwxr_xr_x權限(755)
[root@test ~]# install -m 644 abc jjj
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
-t:指定目标目錄
[root@test ~]# ll xxx
total 0
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
[root@test ~]# install -t xxx ttt abc jjj
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 23:06 xxx
[root@test ~]# ll xxx
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
提示:目标必須是目錄 ,不能是檔案
-g:指定目标檔案的屬組
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 23:06 xxx
[root@test ~]# install -g qiuhom jjj ccc
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rwxr-xr-x 1 root qiuhom 0 Oct 16 23:10 ccc
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 23:06 xxx
提示:複制前指定ccc 為qiuhom組的權限
-o:指定目标屬主
[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
[root@test xxx]# install -o qiuhom abc ddd
[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 qiuhom root 0 Oct 16 23:13 ddd
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
提示:指定目标檔案ddd的屬主為qiuhom
-v:輸出指令執行過程
[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 qiuhom root 0 Oct 16 23:13 ddd
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
[root@test xxx]# install -vm 400 ddd fff
`ddd' -> `fff'
[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 qiuhom root 0 Oct 16 23:13 ddd
-r-------- 1 root root 0 Oct 16 23:16 fff
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
作者:Linux-1874
出處:https://www.cnblogs.com/qiuhom-1874/
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利.