Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。
目錄管理類的命令
mkdir
用法:
mkdir [選項]... 目錄...
選項:
-p 遞歸創建多個目錄
實例:
[root@centos7 ~]# mkdir -p /tmp/jerry/2016/11/4 [root@centos7 /]# tree /tmp /tmp ├── akonadi-root.9I0Ba3 ├── anaconda.log ├── hogsuspend ├── hsperfdata_root │ └── 88148 ├── hsperfdata_user ├── ifcfg.log ├── jerry │ └── 2016 │ └── 11 │ └── 4 **注意:** **centos7&6默認沒有安裝tree命令,記得yum install tree 就OK。**
選項:
-v 顯示創建過程即命令執行過程
實例:
[root@centos7 /]# mkdir -pv /tmp/aaa/bbb/ccc/2016/11qa mkdir: 已創建目錄 "/tmp/aaa" mkdir: 已創建目錄 "/tmp/aaa/bbb" mkdir: 已創建目錄 "/tmp/aaa/bbb/ccc" mkdir: 已創建目錄 "/tmp/aaa/bbb/ccc/2016" mkdir: 已創建目錄 "/tmp/aaa/bbb/ccc/2016/11qa"
選項:
-m:設定目錄權限,不加則為默認權限
實例:
[root@centos7 /]# mkdir -m 777 -pv /tmp/fbi/cia mkdir: 已創建目錄 "/tmp/fbi" mkdir: 已創建目錄 "/tmp/fbi/cia" [root@centos7 /]# ll /tmp/fbi 總用量 0 drwxrwxrwx. 2 root root 6 11月 4 15:52 cia [root@centos7 /]# mkdir -m 775 -pv /tmp/hbo/oom/ubuntu mkdir: 已創建目錄 "/tmp/hbo" mkdir: 已創建目錄 "/tmp/hbo/oom" mkdir: 已創建目錄 "/tmp/hbo/oom/ubuntu [root@centos7 /]# ll /tmp/hbo/oom/ 總用量 0 drwxrwxr-x. 2 root root 6 11月 4 16:00 ubuntu 注意:-m 參數設定的目錄權限只對最后一級的目錄生效,其上級目錄均是默認的755。哈哈~~
rmdir
用法:
rmdir [選項]... 目錄...
選項參數:
--ignore-fail-on-non-empty 忽略僅由目錄非空產生的所有錯誤 -p, --parents remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a' -v, --verbose output a diagnostic for every directory processed --help 顯示此幫助信息并退出 --version 顯示版本信息并退出
實例:
[root@centos7 tmp]# rmdir -pv fbi/cia/ rmdir: 正在刪除目錄 "fbi/cia/" rmdir: 正在刪除目錄 "fbi"
文件查看類命令
cat
用法:
用法:cat [選項]... [文件]... 將[文件]或標準輸入組合輸出到標準輸出。
選項:
-A, --show-all 等于-vET -b, --number-nonblank 對非空輸出行編號 -e 等于-vE -E, --show-ends 在每行結束處顯示"$" -n, --number 對輸出的所有行編號 -s, --squeeze-blank 不輸出多行空行 -t 與-vT 等價 -T, --show-tabs 將跳格字符顯示為^I -u (被忽略) -v, --show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外 --help 顯示此幫助信息并退出 --version 顯示版本信息并退出
平時可能用到的選項就是輸出行號了,實例如下:
[root@centos7 /]# cat -n /etc/rc.local 1 #!/bin/bash 2 # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES 3 # 4 # It is highly advisable to create own systemd services or udev rules 5 # to run scripts during boot instead of using this file. 6 # 7 # In contrast to previous versions due to parallel execution during boot 8 # this script will NOT be run after all other services. 9 # 10 # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure 11 # that this script will be executed during boot. 12 13 touch /var/lock/subsys/local [root@centos7 /]#
tac
tac命令:與cat功能相近,只是逆序顯示文件內容
head
用法:
head [選項]... [文件]... 查看文件的前N行,默認為10行
選項:
-n -#
實例:
[root@centos7 ~]# head /etc/passwd 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 sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin [root@centos7 ~]# head - 15 /etc/passwd [root@centos7 ~]# head -15 /etc/passwd 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 sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
tail
用法:
tail [選項]... [文件]...
選項參數:
-n:指定顯示的行數。不加任何參數默認顯示10行,從最后一行開始; -#:直接指定顯示的行數,從最后一行開始; -f:查看文件尾部內容結束后不退出,跟隨顯示新增的行;
實例:
[root@centos7 ~]# tail -2 /etc/passwd tcpdump:x:72:72::/:/sbin/nologin user:x:1000:1000:user:/home/user:/bin/bash [root@centos7 ~]# tail /etc/passwd mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin pcp:x:988:985:Performance Co-Pilot:/var/lib/pcp:/sbin/nologin pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin gnome-initial-setup:x:987:982::/run/gnome-initial-setup/:/sbin/nologin avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin oprofile:x:16:16:Special user account to be used by OProfile:/var/lib/oprofile:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin user:x:1000:1000:user:/home/user:/bin/bash
more
用法:
more [選項] 文件... 特點:翻屏至文件尾部后自動退出;
選項參數:
-d 顯示幫助,而不是響鈴 -f 統計邏輯行數而不是屏幕行數 -l 抑制換頁(form feed)后的暫停 -p 不滾屏,清屏并顯示文本 -c 不滾屏,顯示文本并清理行尾 -u 抑制下劃線 -s 將多個空行壓縮為一行 -NUM 指定每屏顯示的行數為 NUM +NUM 從文件第 NUM 行開始顯示 +/STRING 從匹配搜索字符串 STRING 的文件位置開始顯示 -V 輸出版本信息并退出
實例:
略過,給你個眼神自己體會^_^
less
特點: 其實man讀取幫助手冊就是調用的less指令。所以less命令的操作方式同man
文件管理類命令
cp
用法:
單源復制:cp [OPTION]... [-T] SOURCE DEST 多源復制:cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... 單源復制:cp [OPTION]... [-T] SOURCE DEST 如果DEST不存在:則事先創建此文件,并復制源文件的數據流至DEST中; 如果DEST存在: 如果DEST是非目錄文件:則覆蓋目標文件; 如果DEST是目錄文件:則先在DEST目錄下創建一個與源文件同名的文件,并復制其數據流; 多源復制:cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... 如果DEST不存在:錯誤; 如果DEST存在: 如果DEST是非目錄文件:錯誤; 如果DEST是目錄文件:分別復制每個文件至目標目錄中,并保持原名;
選項參數:
-i:交互式復制,即覆蓋之前提醒用戶確認; -f:強制覆蓋目標文件; -r, -R:遞歸復制目錄; -d:復制符號鏈接文件本身,而非其指向的源文件; -a:-dR --preserve=all, archive,用于實現歸檔; --preserv= mode:權限 ownership:屬主和屬組 timestamps: 時間戳 context:安全標簽 xattr:擴展屬性 links:符號鏈接 all:上述所有屬性
實例:
`單源復制-目標文件不存在情況` [root@centos ~]# ls /tmp/ whatis.q3Uigb yum.log [root@centos ~]# cp /etc/issue /tmp [root@centos ~]# ls /tmp/ issue whatis.q3Uigb yum.log [root@centos ~]# cat /tmp/issue CentOS release 6.5 (Final) Kernel \r on an \m `單源復制-目標文件已存在情況` [root@centos ~]# cp /etc/hosts /tmp/issue cp: overwrite `/tmp/issue'? y [root@centos ~]# cat /tmp/issue 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 `多源復制-目標目錄不存在情況` [root@centos ~]# cp /etc/hosts /etc/issue /tmp/x cp: target `/tmp/x' is not a directory `多源復制-目標目錄已存在情況` [root@centos ~]# mkdir /tmp/x [root@centos ~]# cp /etc/hosts /etc/issue /tmp/x [root@centos ~]# ls /tmp/x hosts issue [root@centos ~]# `-r選項實例` [root@centos ~]# mkdir -p /tmp/souce/x/y/z [root@centos ~]# mkdir /tmp/dest [root@centos ~]# cp -r /tmp/souce/ /tmp/dest/ [root@centos ~]# tree /tmp/dest/ /tmp/dest/ └── souce └── x └── y └── z 4 directories, 0 files [root@centos ~]# `--preserve選項實例` [root@centos ~]# ls -l /tmp/ |grep liubin -rw-rw-r--. 1 liubin liubin 0 Sep 27 04:56 liubin [root@centos ~]# cp --preserve=ownership /tmp/liubin /tmp/root [root@centos ~]# ls -l /tmp/ total 16 drwxr-xr-x. 3 root root 4096 Sep 27 04:53 dest -rw-r--r--. 1 root root 158 Sep 27 04:43 issue -rw-rw-r--. 1 liubin liubin 0 Sep 27 04:56 liubin -rw-rw-r--. 1 liubin liubin 0 Sep 27 04:59 root drwxr-xr-x. 3 root root 4096 Sep 27 04:49 souce drwxr-xr-x. 2 root root 4096 Sep 27 04:44 x -rw-------. 1 root root 0 Sep 27 03:07 yum.log
mv
用法:
mv [OPTION]... [-T] SOURCE DEST mv [OPTION]... SOURCE... DIRECTORY mv [OPTION]... -t DIRECTORY SOURCE..
選項參數:
-i:交互式 -f:強制移動
實例:
[root@localhost ~]# tree test test |-- 1p2a |-- 28pa |-- Pa99 |-- cpdoc.txt |-- hahaha | |-- cpdoc.txt | |-- cpdoc1.txt | `-- text.txt |-- p,a |-- pa |-- pa12 `-- papi 1 directory, 11 files [root@localhost ~]# mv test/1p2a test/hahaha [root@localhost ~]# tree test test |-- 28pa |-- Pa99 |-- cpdoc.txt |-- hahaha | |-- 1p2a | |-- cpdoc.txt | |-- cpdoc1.txt | `-- text.txt |-- p,a |-- pa |-- pa12 `-- papi 1 directory, 11 files [root@localhost ~]# mv test/hahaha test/mvtest [root@localhost ~]# tree test test |-- 28pa |-- Pa99 |-- cpdoc.txt |-- mvtest | |-- 1p2a | |-- cpdoc.txt | |-- cpdoc1.txt | `-- text.txt |-- p,a |-- pa |-- pa12 `-- papi 1 directory, 11 files
rm
用法:
rm [OPTION]... FILE...
選項參數:
-i:interactive -f:force -r: recursive
實例:
[root@centos ~]# ls /tmp dest issue liubin root souce yum.log [root@centos ~]# tree /tmp/souce/ /tmp/souce/ └── x └── y └── z 3 directories, 0 files [root@centos ~]# rm -rf /tmp/souce/ [root@centos ~]# ls anaconda-ks.cfg install.log install.log.syslog [root@centos ~]#
bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示。
用法
echo $?:顯示最近一條命令的執行結果
只能查看最近一條命令的執行的狀態結果返回值
命令執行成功,則顯示:0
命令執行失敗,則顯示:1-255之間的任意數字
實例
[root@centos7 ~]# ls /var account cache db games kerberos local log nis preserve spool tmp yp adm crash empty gopher lib lock mail opt run target www [root@centos7 ~]# echo $? 0 [root@centos7 ~]# ls /varte ls: 無法訪問/varte: 沒有那個文件或目錄 [root@centos7 ~]# echo $? 2 [root@centos7 ~]# lsd /var bash: lsd: 未找到命令... [root@centos7 ~]# echo $? 127 [root@centos7 ~]#
請使用命令行展開功能來完成以下練習:
創建/tmp目錄下的:ac, ad, bc, bd
[root@centos7 ~]# mkdir -v /tmp/{a,b}_{c,d} mkdir: 已創建目錄 "/tmp/a_c" mkdir: 已創建目錄 "/tmp/a_d" mkdir: 已創建目錄 "/tmp/b_c" mkdir: 已創建目錄 "/tmp/b_d" [root@centos7 ~]# ls /tmp/ a_c a_d anaconda.log b_c b_d
創建/tmp/mylinux目錄下的:
mylinux ├── bin ├── boot │ └── grub ├── dev ├── etc │ ├── rc.d │ │ └── init.d │ └── sysconfig │ └── network-scripts ├── lib │ └── modules ├── lib64 ├── proc ├── sbin ├── sys ├── tmp ├── usr │ └── local │ ├── bin │ └── sbin └── var ├── lock ├── log └── run [root@centos7 ~]# mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}} mkdir: 已創建目錄 "/tmp/mylinux" mkdir: 已創建目錄 "/tmp/mylinux/bin" mkdir: 已創建目錄 "/tmp/mylinux/boot" mkdir: 已創建目錄 "/tmp/mylinux/boot/grub" mkdir: 已創建目錄 "/tmp/mylinux/dev" mkdir: 已創建目錄 "/tmp/mylinux/etc" mkdir: 已創建目錄 "/tmp/mylinux/etc/rc.d" mkdir: 已創建目錄 "/tmp/mylinux/etc/rc.d/init.d" mkdir: 已創建目錄 "/tmp/mylinux/etc/sysconfig" mkdir: 已創建目錄 "/tmp/mylinux/etc/sysconfig/network-scripts" mkdir: 已創建目錄 "/tmp/mylinux/lib" mkdir: 已創建目錄 "/tmp/mylinux/lib/modules" mkdir: 已創建目錄 "/tmp/mylinux/lib64" mkdir: 已創建目錄 "/tmp/mylinux/proc" mkdir: 已創建目錄 "/tmp/mylinux/sbin" mkdir: 已創建目錄 "/tmp/mylinux/sys" mkdir: 已創建目錄 "/tmp/mylinux/tmp" mkdir: 已創建目錄 "/tmp/mylinux/usr" mkdir: 已創建目錄 "/tmp/mylinux/usr/local" mkdir: 已創建目錄 "/tmp/mylinux/usr/local/bin" mkdir: 已創建目錄 "/tmp/mylinux/usr/local/sbin" mkdir: 已創建目錄 "/tmp/mylinux/var" mkdir: 已創建目錄 "/tmp/mylinux/var/lock" mkdir: 已創建目錄 "/tmp/mylinux/var/log" mkdir: 已創建目錄 "/tmp/mylinux/var/run" [root@centos7 ~]#
文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息。
[root@centos7 etc]# stat /bin/bash 文件:"/bin/bash" 大?。?60392 塊:1880 IO 塊:4096 普通文件 設備:fd00h/64768d Inode:67111627 硬鏈接:1 權限:(0755/-rwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root) 環境:system_u:object_r:shell_exec_t:s0 最近訪問:2016-11-06 13:06:17.318000042 +0800 最近更改:2016-08-03 00:00:07.000000000 +0800 最近改動:2016-11-03 13:47:45.414998262 +0800 創建時間:- touch命令: touch - change file timestamps touch [OPTION]... FILE... -c: 指定的文件路徑不存在時不予創建; -a: 僅修改access time; -m:僅修改modify time; -t STAMP [[CC]YY]MMDDhhmm[.ss] 實例一:創建不存在的文件 命令: touch log2012.log log2013.log 輸出: [root@localhost test]# touch log2012.log log2013.log [root@localhost test]# ll -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log 如果log2014.log不存在,則不創建文件 [root@localhost test]# touch -c log2014.log [root@localhost test]# ll -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log 實例二:更新log.log的時間和log2012.log時間戳相同 命令: touch -r log.log log2012.log 輸出: [root@localhost test]# ll -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log -rw-r--r-- 1 root root 0 10-28 14:48 log.log [root@localhost test]# touch -r log.log log2012.log [root@localhost test]# ll -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log -rw-r--r-- 1 root root 0 10-28 14:48 log.log 實例三:設定文件的時間戳 命令: touch -t 201211142234.50 log.log 輸出: [root@localhost test]# ll -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log -rw-r--r-- 1 root root 0 10-28 14:48 log.log [root@localhost test]# touch -t 201211142234.50 log.log [root@localhost test]# ll -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log -rw-r--r-- 1 root root 0 2012-11-14 log.log 說明: -t time 使用指定的時間值 time 作為指定文件相應時間戳記的新值.此處的 time規定為如下形式的十進制數: [[CC]YY]MMDDhhmm[.SS] 這里,CC為年數中的前兩位,即”世紀數”;YY為年數的后兩位,即某世紀中的年數.如果不給出CC的值,則touch 將把年數CCYY限定1969--2068之內.MM為月數,DD為天將把年數CCYY限定在1969--2068之內.MM為月數,DD為天數,hh 為小時數(幾點),mm為分鐘數,SS為秒數.此處秒的設定范圍是0--61,這樣可以處理閏秒.這些數字組成的時間是環境變量TZ指定的時區中的一個時 間.由于系統的限制,早于1970年1月1日的時間是錯誤的
如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果?
命令別名查看:
[root@centos ~]# alias
alias cp='cp -i'
alias l.='ls -d .* –color=auto'
alias ll='ls -l –color=auto'
alias ls='ls –color=auto'
alias mv='mv -i'
alias rm='rm -i'
創建別名:
[root@centos ~]# alias clear='cls'
[root@centos ~]# alias
alias clear='cls'
alias cp='cp -i'
alias l.='ls -d .* –color=auto'
alias ll='ls -l –color=auto'
alias ls='ls –color=auto'
alias mv='mv -i'
alias rm='rm -i'
引用命令的執行結果:
使用“引用:
[root@centos ~]# echo date
Tue Sep 27 06:45:08 CST 2016
[root@centos ~]#
使用$(COMMAND)引用
[root@centos ~]# file $(which –skip-alias ls)
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[root@centos ~]#
顯示var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄。
[root@centos7 /]# ls -dl /var/l*[0-9]*[a-z] drwxr-xr-x. 2 root root 6 11月 6 14:58 /var/l42opm drwxr-xr-x. 2 root root 6 11月 6 14:58 /var/l47wsd -rw-r--r--. 1 root root 0 11月 6 15:38 /var/l9cxz drwxr-xr-x. 2 root root 6 11月 6 15:35 /var/ls4gs drwxr-xr-x. 2 root root 6 11月 6 15:34 /var/lw56tcp -rw-r--r--. 1 root root 0 11月 6 15:37 /var/lw89cxz -rw-r--r--. 1 root root 0 11月 6 15:37 /var/lw99cxz [root@centos7 /]# ls -dl /var/l*[[:digit:]]*[[:alpha:]] drwxr-xr-x. 2 root root 6 11月 6 14:58 /var/l42opm drwxr-xr-x. 2 root root 6 11月 6 14:58 /var/l47wsd -rw-r--r--. 1 root root 0 11月 6 15:38 /var/l9cxz drwxr-xr-x. 2 root root 6 11月 6 15:35 /var/ls4gs drwxr-xr-x. 2 root root 6 11月 6 15:34 /var/lw56tcp -rw-r--r--. 1 root root 0 11月 6 15:37 /var/lw89cxz -rw-r--r--. 1 root root 0 11月 6 15:37 /var/lw99cxz
顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。
[root@centos7 /]# ls -dl /etc/[[:digit:]]*[[:alpha:]] drwxr-xr-x. 2 root root 6 11月 6 15:43 /etc/12sad -rw-r--r--. 1 root root 29 11月 6 15:45 /etc/12sd drwxr-xr-x. 2 root root 6 11月 6 15:43 /etc/23gfhg -rw-r--r--. 1 root root 35 11月 6 15:46 /etc/4543sdcsf [root@centos7 /]# ls -dl /etc/[0-9]*[^0-9] drwxr-xr-x. 2 root root 6 11月 6 15:43 /etc/12sad -rw-r--r--. 1 root root 29 11月 6 15:45 /etc/12sd drwxr-xr-x. 2 root root 6 11月 6 15:43 /etc/23gfhg -rw-r--r--. 1 root root 35 11月 6 15:46 /etc/4543sdcsf
顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄。
[root@centos7 /]# ls -dl /etc/[^a-z]*[a-z] drwxr-xr-x. 2 root root 6 11月 6 15:43 /etc/12sad -rw-r--r--. 1 root root 29 11月 6 15:45 /etc/12sd drwxr-xr-x. 2 root root 6 11月 6 15:43 /etc/23gfhg -rw-r--r--. 1 root root 35 11月 6 15:46 /etc/4543sdcsf
在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22。
touch /tmp/tfile-$(date +%F-%H-%M-%S)
復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。
mkdir /tmp/mytest1 && cp -r /etc/p*[^0-9] /tmp/mytest1/
復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中。
mkdir /tmp/mytest2 && cp -r /etc/*.d /tmp/mytest2/
復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。
mkdir -p /tmp/mytest3 && cp /etc/[lmn]*.conf /tmp/mytest3/
原創文章,作者:N24_Jerry,如若轉載,請注明出處:http://www.www58058.com/57962
贊,命令總結的很詳細,排版也比較好~繼續加油~