Linux文件管理命令

pwd:printing working directory 顯示工作目錄

[root@promote ~]# pwd
/root

cd:change directory 切換目錄

格式:cd [/PATH/TO/SOMEDIR]
cd:切換回家目錄

[root@promote etc]# cd 
[root@promote ~]# pwd
/root

注意:bash中,~表示家目錄
cd ~:切換回自己的家目錄

[root@promote ~]# cd /bin
[root@promote bin]# cd ~
[root@promote ~]# pwd
/root

cd ~USERNAME:切換至指定用戶的家目錄

[root@promote ~]# cd /bin
[root@promote bin]# cd ~root
[root@promote ~]# pwd
/root

cd -:在上一次所在目錄與當(dāng)前目錄之間來回切換

[root@promote ~]# cd -
/bin
[root@promote bin]# cd -
/root
[root@promote ~]# cd -
/bin
[root@promote bin]# cd -
/root

ls:list 列出指定目錄下的內(nèi)容

格式:ls [OPTION]... [FILE]...
-a:顯示所有文件,包括隱藏文件

[root@centos7 ~]# ls -a
.   anaconda-ks.cfg  .bash_logout   .bashrc  .config  .dbus    Documents  .esd_auth      .local  Pictures  
.tcshrc    Videos
..  .bash_history    .bash_profile  .cache   .cshrc   Desktop  Downloads  .ICEauthority  Music   Public    
Templates  .Xauthority

-A:顯示除 . 和 . . 之外的所有文件

[root@centos7 ~]# ls -A
anaconda-ks.cfg  .bash_logout   .bashrc  .config  .dbus    Documents  .esd_auth      .local  Pictures  
.tcshrc    Videos
.bash_history    .bash_profile  .cache   .cshrc   Desktop  Downloads  .ICEauthority  Music   Public    
Templates  .Xauthority

-l:--long,長格式列表,即顯示文件的詳細(xì)屬性信息

[root@centos7 ~]# ls -l
total 4
-rw-------. 1 root root 1628 Mar 24 14:34 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Desktop
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Documents
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Downloads
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Music
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Pictures
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Public
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Templates
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Videos

-:表示文件類型,-,d,b,c,l,s,p

rw-r--r--

字符名稱 含義
rw- 文件屬主的權(quán)限
r-- 文件屬組的權(quán)限
r-- 其他用戶(非屬主、屬組)的權(quán)限
1 數(shù)字表示文件被硬鏈接的次數(shù)
第一個root 文件的屬主
第二個root 文件的屬組
1628 數(shù)字表示文件的大小,單位是字節(jié)

-h,--human-readable 對文件大小單位換算 換算后的結(jié)果可能是非精確值

[root@centos7 ~]# ls -h
anaconda-ks.cfg  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos


[root@centos7 ~]# ls -l -h
total 4.0K
-rw-------. 1 root root 1.6K Mar 24 14:34 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Desktop
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Documents
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Downloads
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Music
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Pictures
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Public
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Templates
drwxr-xr-x. 2 root root    6 Mar 24 14:52 Videos

Mar 24 14:34:文件最近一次被修改的時(shí)間
anaconda-ks.cfg:文件名

-d:只查看目錄自身屬性,而非其內(nèi)部的文件列表

[root@centos7 ~]# ls -d
.

-r:reverse,逆序顯示

[root@centos7 ~]# ls -r
Videos  Templates  Public  Pictures  Music  Downloads  Documents  Desktop  anaconda-ks.cfg

-R:recursive,遞歸顯示

[root@centos7 ~]# ls -R
.:
anaconda-ks.cfg  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

./Desktop:

./Documents:

./Downloads:

./Music:

./Pictures:

./Public:

./Templates:

./Videos:

cat:concatenate 文本文件查看工具

格式:cat [OPTION]... [FILE]...

  [root@centos7 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Mar 24 14:30:18 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=385f075d-1421-48a1-911b-d6ec2f9c2016 /                       xfs     defaults        0 0
UUID=3710be3c-5419-4d96-9795-e5f6863b59b3 /boot                   xfs     defaults        0 0
UUID=3f0703b3-e4e1-4f8d-84c4-dfb4c6ec4dc6 /data                   xfs     defaults        0 0
UUID=8c696c94-b458-44c3-a218-a9c09512e4bd swap                    swap    defaults        0 0

-n:給顯示的文本行編號

[root@centos7 ~]# cat -n /etc/issue
 1  \S
 2  Kernel \r on an \m
 3  

-e:顯示行結(jié)束符$

[root@centos7 ~]# cat -e /etc/issue
\S$
Kernel \r on an \m$
$

file:查看文件內(nèi)容類型

格式:file [FILE]...

[root@centos7 ~]# file /etc/shadow
/etc/shadow: ASCII text
[root@centos7 ~]# file /etc/issue
/etc/issue: ASCII text

注意:和上述 cat命令聯(lián)系,cat只能查看文本文件,如果需要查看該文件是否為文本文件可以先用 file命令

tac:文本文件查看工具

和cat作用一樣 逆序顯示

[root@centos7 ~]# tac /etc/issue

Kernel \r on an \m
\S
[root@centos7 ~]# cat /etc/issue
\S
Kernel \r on an \m

分屏查看命令:more less

格式:more FILE
翻屏至文件尾部后自動退出
格式:less FILE
和man命令一樣

head:查看文件前n行

格式:head [options] FILE
-n #或 -#:指定要查看的行數(shù)

tail:查看文件后n行

格式:tail [options] FILE
-n #或 -#:指定要查看的行數(shù)
-f:查看文件尾部內(nèi)容結(jié)束后不退出,跟隨顯示新增的行

stat:stat - display file or file system status

格式:stat FILE . . .
文件:兩類數(shù)據(jù)
元數(shù)據(jù):metadata 使用stat看到的就是元數(shù)據(jù)
數(shù)據(jù):data 使用cat看到的都是數(shù)據(jù)
時(shí)間戳:Access: 2019-03-26 09:17:24.612736837 +0800
Modify: 2019-03-26 09:17:24.612736837 +0800
Change: 2019-03-26 09:17:24.612736837 +0800

[root@centos7 ~]# stat /tmp/1.txt
  File: ‘/tmp/1.txt’
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d  Inode: 67614504    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2019-03-26 09:17:24.612736837 +0800
Modify: 2019-03-26 09:17:24.612736837 +0800
Change: 2019-03-26 09:17:24.612736837 +0800
Birth: -
字符名稱 含義
File 文件名稱
Size 文件大小
Blocks IO塊大小
regular file 這里是顯示文件的類型,這是一個普通文件
Device 所在設(shè)備
Inode Inode節(jié)點(diǎn)號
Links 被鏈接的次數(shù)
Access(第一個) 訪問權(quán)限
Uid uid號和屬主
Gid gid號和屬組
Access(第二個) 文件最近一次的訪問時(shí)間
Modify 文件的修改時(shí)間
Chang 文件的改變時(shí)間

修改文件的時(shí)間戳信息用 touch命令

touch:touch - change file timestamps 當(dāng)目標(biāo)文件不存在時(shí)直接創(chuàng)建

格式:touch [OPTION]... FILE...
-c:指定的文件路徑不存在時(shí)不予創(chuàng)建

[root@centos7 ~]# touch -c /tmp/ljw
[root@centos7 ~]# ls /tmp
1.txt                                                                         tracker-extract-files.0
hsperfdata_root                                                               vmware-root_5644-1003073663
ks-script-FMHiRV                                                              vmware-root_5754-701204016
l.1                                                                           vmware-root_5794-700548750
ljw                                                                           vmware-root_6159-1950294947

-a:僅修改access time
-m:僅修改modify time
-t STAMP:[[CC]YY]MMDDhhmm[.ss]

[root@centos7 ~]# touch -m -t 0212010313.23 /tmp/1.txt
[root@centos7 ~]# stat /tmp/1.txt
  File: ‘/tmp/1.txt’
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d  Inode: 67614504    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2019-03-26 09:17:24.612736837 +0800
Modify: 2002-12-01 03:13:23.000000000 +0800
Change: 2019-03-26 09:26:33.116726874 +0800
Birth: -

echo:回顯命令

格式:echo [SHORT-OPTION]... [STRING]...
-n:不自動進(jìn)行換行操作

[root@centos7 ~]# echo -n hello
hello[root@centos7 ~]# 

-e:讓轉(zhuǎn)義符生效

\n \t \b
換行 制表符 退格,刪除前一個字符
[root@centos7 ~]# echo "hello \neveryone"
hello \neveryone
[root@centos7 ~]# echo -e "hello \neveryone"
hello 
everyone

STRING可以用引號,單引號和雙引號均可用
單引號:強(qiáng)引用,變量引用不執(zhí)行替換

[root@centos7 ~]# echo '$SHELL'
$SHELL

雙引號:弱引用,變量引用會被替換

[root@centos7 ~]# echo "$SHELL"
/bin/bash

注意:變量引用的正規(guī)符號
$(name)

關(guān)機(jī)或重啟命令:shutdown

格式:shutdown [OPTIONS...] [TIME] [WALL...]
OPTIONS:
-h:halt 立即關(guān)閉

[root@centos7 ~]# shutdown -h 13:00
Shutdown scheduled for Tue 2019-03-26 13:00:00 CST, use 'shutdown -c' to cancel.
在下午一點(diǎn)關(guān)機(jī)(-h參數(shù)使用24小時(shí)制)

-r:reboot 重啟

[root@centos7 ~]# shutdown -r +10
Shutdown scheduled for Mon 2019-03-25 21:41:21 CST, use 'shutdown -c' to cancel.
[root@centos7 ~]# 
Broadcast message from root@centos7.localdomain (Mon 2019-03-25 21:31:21 CST):

The system is going down for reboot at Mon 2019-03-25 21:41:21 CST!
在10分鐘后重啟

-c:cancel 取消預(yù)定的定時(shí)關(guān)機(jī)操作

WALL:向所有終端發(fā)送消息

關(guān)機(jī)命令:

[root@centos7 ~]# systemctl poweroff
[root@centos7 ~]# poweroff

重啟命令:

[root@centos7 ~]# reboot

日期相關(guān)的命令:Linux系統(tǒng)啟動時(shí)從硬件讀取日期和時(shí)間信息,讀取完成后,就不再與硬件相關(guān)聯(lián)

date :系統(tǒng)時(shí)鐘 顯示日期時(shí)間

格式:date [OPTION]... [+FORMAT]

[root@centos7 ~]# date
Mon Mar 25 21:38:12 CST 2019

FORMAT:格式符

%F %T %s
年月日 小時(shí)分鐘秒 1970年1月1日(unix元年)0點(diǎn)0分0秒到命令執(zhí)行那一刻經(jīng)過的秒數(shù)

按照“年-月-日 小時(shí):分鐘:秒”的形式顯示當(dāng)前時(shí)間

[root@centos7 ~]# date "+%Y-%m-%d %H:%M:%S"
2019-03-25 21:54:33

設(shè)置日期時(shí)間:date [MMDDhhmm[[CC]YY][.ss]]

[root@centos7 ~]# date 032521582019.01
Mon Mar 25 21:58:01 CST 2019

hwclock,clock:硬件時(shí)鐘 顯示或設(shè)定硬件時(shí)鐘

[root@centos7 ~]# hwclock
Mon 25 Mar 2019 10:00:10 PM CST  -0.698718 seconds
[root@centos7 ~]# clock
Mon 25 Mar 2019 10:00:56 PM CST  -0.445681 seconds

-s, --hctosy:以hc為準(zhǔn),系統(tǒng)設(shè)定和硬件一樣

-w, --systohc:以sys為準(zhǔn),硬件設(shè)置和系統(tǒng)一樣

cal

格式:cal [[month] year]

[root@centos7 ~]# cal
     March 2019     
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
[root@centos7 ~]# cal 2019
                           2019                               

       January               February                 March       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
       1  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                              31
       April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6             1  2  3  4                      1
7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
        July                  August                September     
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30

       October               November               December      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
       1  2  3  4  5                   1  2    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31

which:顯示命令的完整路徑

格式:which [options] [--] programname [...]

[root@centos7 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls

如果不想讓which顯示命令別名,用\which實(shí)現(xiàn)

[root@centos7 ~]# \which ls
/usr/bin/ls

--skip-alias:忽略別名

[root@centos7 ~]# which --skip-alias
Usage: /usr/bin/which [options] [--] COMMAND [...]
Write the full path of COMMAND(s) to standard output.

whereis:顯示二進(jìn)制文件,源碼文件,手冊頁

格式:whereis [options]
-b 只看二進(jìn)制格程序路徑
-m 只搜索使用手冊文件路徑
-s 只搜索源文件路徑

who:查看登錄當(dāng)前系統(tǒng)的相關(guān)用戶信息

格式:who [OPTION]

[root@centos7 ~]# who
root     :0           2019-03-26 08:43 (:0)
root     pts/0        2019-03-26 08:43 (192.168.0.101)

-b:顯示最近一次操作系統(tǒng)啟動的時(shí)間

[root@centos7 ~]# who -b
     system boot  2019-03-26 08:41

-d:顯示死亡進(jìn)程

[root@centos7 ~]# who -d

-l:顯示登錄進(jìn)程

[root@centos7 ~]# who -l

-r:運(yùn)行級別

[root@centos7 ~]# who -r
     run-level 5  2019-03-26 08:42

w:增強(qiáng)版的who命名,顯示登錄用戶和正在做什么

[root@centos7 ~]# w
 08:46:28 up 4 min,  2 users,  load average: 0.11, 0.62, 0.36
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       :0               08:43   ?xdm?   1:21   0.60s /usr/libexec/gnome-session-binary --session 
gnome-classic
root     pts/0    192.168.0.101    08:43    4.00s  0.19s  0.09s w

mkdir:make directories

格式:mkdir [OPTION]... DIRECTORY...
-p:自動按需創(chuàng)建父目錄,目錄不存在時(shí)自動創(chuàng)建目錄

[root@centos7 ~]# mkdir /tmp/ljw/x
[root@centos7 ~]# ls /tmp
hsperfdata_root                                                               vmware-root_5644-1003073663
ks-script-FMHiRV                                                              vmware-root_5754-701204016
ljw                                                                           vmware-root_5794-700548750

-v:verbose,顯示詳細(xì)過程

[root@centos7 ~]# mkdir -pv /tmp/a/b/c
mkdir: created directory ‘/tmp/a’
mkdir: created directory ‘/tmp/a/b’
mkdir: created directory ‘/tmp/a/b/c’

-m MODE:直接給定權(quán)限
注意:路徑基名為命令的作用對象,基名之前的路徑必須存在

rmdir:remove empty directories

格式:rmdir [OPTION]... DIRECTORY...

[root@centos7 ~]# rmdir /tmp/a
rmdir: failed to remove ‘/tmp/a’: Directory not empty
[root@centos7 ~]# rmdir /tmp/a/b/c
單獨(dú)使用rmdir命令時(shí),只能刪除空目錄

-p:刪除某空目錄后,如果其父附錄為空,則一并刪除
-v:verbose,顯示詳細(xì)過程

tree

格式:tree [options] [directory]

[root@centos7 ~]# tree
.
├── anaconda-ks.cfg
├── Desktop
├── Documents
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
└── Videos

-L:level,指定要顯示的層級
如果沒有tree明了,使用~]# sudo yum -y install tree 安裝tree命令

cp:copy

  1. 單源復(fù)制:cp [OPTION]... [-T] SOURCE DEST
    如果DEST不存在,則事先創(chuàng)建此文件,并復(fù)制源文件的數(shù)據(jù)流至DEST中
    如果DEST存在:

    • 如果DEST是非目錄文件,則覆蓋目標(biāo)文件
    • 如果DEST是目錄文件,則先在DEST目錄下創(chuàng)建一個與源文件同名的文件,并復(fù)制其數(shù)據(jù)流至目標(biāo)文件
  2. 多源復(fù)制:cp [OPTION]... SOURCE... DIRECTORY,cp [OPTION]... -t DIRECTORY SOURCE...
    如果DEST不存在,錯誤
    如果DEST存在:
    如果DEST是非目錄文件:錯誤
    如果DEST是目標(biāo)文件:分別復(fù)制每個文件至目標(biāo)目錄中,并保持原名

常用選項(xiàng):
-i:交互式復(fù)制,即覆蓋之前提醒用戶確認(rèn)

[root@centos7 ~]# touch /tmp/1.txt
[root@centos7 ~]# touch /tmp/11.txt
[root@centos7 ~]# cp -i /tmp/1.txt /tmp/11.txt
cp: overwrite ‘/tmp/11.txt’? y

-f:強(qiáng)制覆蓋目標(biāo)文件

-r:遞歸復(fù)制目錄
-d:復(fù)制符號鏈接文件本身,而非其指向的源文件

[root@centos7 ~]# ll /etc/issue
-rw-r--r--. 1 root root 23 Nov 23 21:16 /etc/issue
[root@centos7 ~]# cp -d /etc/issue abc
cp: overwrite ‘a(chǎn)bc’? y
[root@centos7 ~]# ll abc
-rw-r--r--. 1 root root 23 Mar 26 13:33 abc

-a:-dR --preserve=all,archive,用于實(shí)現(xiàn)歸檔
--preserve=

字符 含義
mode 權(quán)限
ownership 屬主和屬組
timestamps 時(shí)間戳
context 安全標(biāo)簽
xattr 擴(kuò)展屬性
links 符號鏈接
all 上述所有屬性

-p:保留源文件或目錄的屬性

[root@centos7 ~]# stat /etc/issue
  File: ‘/etc/issue’
  Size: 23          Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d  Inode: 67199714    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2019-03-26 09:03:47.229025436 +0800
Modify: 2018-11-23 21:16:58.000000000 +0800
Change: 2019-03-24 14:30:37.691004012 +0800
 Birth: -
[root@centos7 ~]# cp -p /etc/issue ljw
[root@centos7 ~]# stat ljw
 File: ‘ljw’
  Size: 23          Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d  Inode: 102558741   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2019-03-26 09:03:47.229025436 +0800
Modify: 2018-11-23 21:16:58.000000000 +0800
Change: 2019-03-26 13:39:04.792595732 +0800
Birth: -

mv:move (和cp類似)

mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...

-i:交互式操作,覆蓋前先詢問用戶,如果源文件與目標(biāo)文件或目標(biāo)目錄中的文件同名,則詢問用戶是否覆蓋目標(biāo)文件
-f:若目標(biāo)文件或目錄與現(xiàn)有的文件或目錄重復(fù),則直接覆蓋現(xiàn)有的文件或目錄

rm:remove

格式:rm [OPTION]... FILE...
-i:刪除已有文件或目錄之前先詢問用戶。(只有root用戶默認(rèn)rm=rm -i)

[root@centos7 ~]# rm 3.txt
rm:是否刪除普通空文件 "3.txt"?y
[root@centos7 ~]#

-f:強(qiáng)制刪除文件或目錄

[root@centos7 ~]# rm -f 10.txt
[root@centos7 ~]#

-r:遞歸處理,將指定目錄下的所有文件與子目錄一并處理

刪除目錄:rm -rf /PATH/TO/DIR
危險(xiǎn)操作:rm -rf / 或者 rm -rf /
自殺
注意:所有不用文件建議不要直接刪除,而是移動至某個專用目錄(模擬回收站)

install:復(fù)制文件

install命令與cp命令類似,均可以將文件或目錄拷貝到指定的路徑;但是install命令可以控制目標(biāo)文件的屬性。

install命令:復(fù)制文件和設(shè)置文件屬性

   install [OPTION]... [-T] SOURCE DEST  單源復(fù)制

   install [OPTION]... SOURCE... DIRECTORY  多源復(fù)制

   install [OPTION]... -t DIRECTORY SOURCE...  多源復(fù)制

   install [OPTION]... -d DIRECTORY...  創(chuàng)建空目錄

-m,--mode=MODE,設(shè)定目標(biāo)文件權(quán)限,默認(rèn)為755

-o,--owner=OWNER,設(shè)定目標(biāo)文件的屬主

-g,--group=GROUP,設(shè)定目標(biāo)文件屬組

-d:創(chuàng)建目錄

[root@centos7 ~]# install /etc/passwd /tmp/passwd.bak
[root@centos7 ~]# cat /tmp/passwd.bak | head -5
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

mktemp:創(chuàng)建臨時(shí)文件或臨時(shí)目錄

格式:mktemp [OPTION]... [TEMPLATE]

使用mktemp 命令生成臨時(shí)文件時(shí),文件名參數(shù)應(yīng)當(dāng)以"文件名.XXXX"的形式給出,mktemp 會根據(jù)文件名參數(shù)建立一個臨時(shí)文件

例如:mktemp test.XXXX

[root@centos7 ~]# mktemp test.XXX
test.yXH

-d:創(chuàng)建臨時(shí)目錄

[root@centos7 ~]# mktemp -d test.XXXX
test.On1N

-u:干跑,不創(chuàng)建文件測試使用

注意:mktemp會將創(chuàng)建的臨時(shí)文件名直接返回,因此,可直接通過沒命令引用保存起來

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容