一、Linux上的文件管理類命令及其使用方法和相關演示
目錄管理命令
- mkdir
在shell中執行命令 man mkdir,顯示出以下內容(部分重要內容):
NAME
mkdir – make directories
SYNOPSIS
mkdir [OPTION]… DIRECTORY…
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options
too.
-m, –mode=MODE
set file mode (as in chmod), not a=rwx – umask
-p, –parents
no error if existing, make parent directories as needed
-v, –verbose
print a message for each created directory
-Z set SELinux security context of each created directory to the
default type
–context[=CTX]
like -Z, or if CTX is specified then set the SELinux or SMACK
security context to CTX
–help display this help and exit
–version
output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report mkdir translation bugs to <http://translationproject.org/team/>
可以看出mkdir實為make diretories的簡寫,即為創建目錄之意,下面將著重描述幾個主要的參數
用法:mkdir [OPTION]… DIRECTORY…
-p: 自動按需創建父目錄;
在shell終端中輸入 mkdir /test/filep,顯示結果如下:
[root@localhost /]# mkdir /test/filep
mkdir: cannot create directory ‘/test/filep’: No such file or directory
查其原因為不存在/test/目錄,而-p這個參數則可以解決這個問題,直接創建相關父目錄,顯示結果如下:
[root@localhost /]# mkdir -p /test/filep
[root@localhost /]# ls
12-07-20 bin etc lib64 opt root srv tmp var
12-07-26 boot home media practise run sys tools
12-07-27 dev lib mnt proc sbin test usr
[root@localhost /]# cd /test/
[root@localhost test]# ls
filep
-v: verbose,顯示詳細過程;
在創建目錄過程中到底發生了什么,則可以使用-v參數,示例如下:
[root@localhost /]# mkdir -pv /test/filev
mkdir: created directory ‘/test’
mkdir: created directory ‘/test/filev’
-m MODE:直接給定權限;
該功能為文件、目錄授權,尚未涉獵,暫不說明
- rmdir
在shell中執行命令 man rmdir,顯示出以下內容(部分重要內容):
NAME
rmdir – remove empty directories
SYNOPSIS
rmdir [OPTION]… DIRECTORY…
DESCRIPTION
Remove the DIRECTORY(ies), if they are empty.
–ignore-fail-on-non-empty
ignore each failure that is solely because a directory
is 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 display this help and exit
–version
output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report rmdir translation bugs to <http://translationproject.org/team/>
可以看出rmdir實為remove move diretories的簡寫,即為移除空目錄之意,下面將著重描述幾個主要的參數:
rmdir [OPTION]… DIRECTORY…
-p:刪除某目錄后,如果其父目錄為空,則一并刪除之;
-v: 顯示過程;
可以發現,這兩個參數實際上與mkdir的參數意義基本相同,我則以一個命令展示:
[root@localhost /]# rmdir -pv /test/filev/
rmdir: removing directory, ‘/test/filev/’
rmdir: removing directory, ‘/test’
rmdir: removing directory, ‘/’
rmdir: failed to remove directory ‘/’: Device or resource busy
由于我在命令中加入了根目錄,根目錄正在使用,最終根目錄移除失敗,所以輸入命令的時候一定要多加小心?。。。。。?/span>
文件管理命令
- cp
在shell中執行命令 man cp,顯示出以下內容(部分重要內容):
NAME
cp – copy files and directories
SYNOPSIS
cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… -t DIRECTORY SOURCE…
DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options
too.
-a, –archive
same as -dR –preserve=all
–attributes-only
don’t copy the file data, just the attributes
–backup[=CONTROL]
make a backup of each existing destination file
-b like –backup but does not accept an argument
–copy-contents
copy contents of special files when recursive
-d same as –no-dereference –preserve=links
-f, –force
if an existing destination file cannot be opened, remove it and
try again (this option is ignored when the -n option is also
used)
-i, –interactive
prompt before overwrite (overrides a previous -n option)
-H follow command-line symbolic links in SOURCE
-l, –link
hard link files instead of copying
-L, –dereference
always follow symbolic links in SOURCE
-n, –no-clobber
do not overwrite an existing file (overrides a previous -i
option)
-P, –no-dereference
never follow symbolic links in SOURCE
-p same as –preserve=mode,ownership,timestamps
–preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,time‐
stamps), if possible additional attributes: context, links,
xattr, all
-c deprecated, same as –preserve=context
–no-preserve=ATTR_LIST
don’t preserve the specified attributes
–parents
use full source file name under DIRECTORY
-R, -r, –recursive
copy directories recursively
–reflink[=WHEN]
control clone/CoW copies. See below
–remove-destination
remove each existing destination file before attempting to open
it (contrast with –force)
–sparse=WHEN
control creation of sparse files. See below
–strip-trailing-slashes
remove any trailing slashes from each SOURCE argument
-s, –symbolic-link
make symbolic links instead of copying
-S, –suffix=SUFFIX
override the usual backup suffix
-t, –target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
-T, –no-target-directory
treat DEST as a normal file
-u, –update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
-v, –verbose
explain what is being done
-x, –one-file-system
stay on this file system
-Z set SELinux security context of destination file to default type
–context[=CTX]
like -Z, or if CTX is specified then set the SELinux or SMACK
security context to CTX
–help display this help and exit
–version
output version information and exit
By default, sparse SOURCE files are detected by a crude heuristic and
the corresponding DEST file is made sparse as well. That is the behav‐
ior selected by –sparse=auto. Specify –sparse=always to create a
sparse DEST file whenever the SOURCE file contains a long enough
sequence of zero bytes. Use –sparse=never to inhibit creation of
sparse files.
When –reflink[=always] is specified, perform a lightweight copy, where
the data blocks are copied only when modified. If this is not possible
the copy fails, or if –reflink=auto is specified, fall back to a stan‐
dard copy.
The backup suffix is ‘~’, unless set with –suffix or SIM‐
PLE_BACKUP_SUFFIX. The version control method may be selected via the
–backup option or through the VERSION_CONTROL environment variable.
Here are the values:
none, off
never make backups (even if –backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups
As a special case, cp makes a backup of SOURCE when the force and
backup options are given and SOURCE and DEST are the same name for an
existing, regular file.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report cp translation bugs to <http://translationproject.org/team/>
可以看出cp實為copy的簡寫,即為復制之意,下面將著重描述幾個主要的參數:
cp命令:copy
源文件;目標文件;
單源復制: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目錄下創建一個與源文件同名的文件,并復制其數據流;
[root@localhost practise]# cp test/cp1.txt /practise/cptest/
cp: cannot stat ‘test/cp1.txt’: No such file or directory
[root@localhost practise]# mkdir /practise/cptest
[root@localhost /]# cp /test/cp1.out /practise/cptest/
[root@localhost /]# ll practise/cptest/
total 4
-rw-r–r–. 1 root root 370 Jul 27 14:34 cp1.out
[root@localhost /]# cp /test/cp1.out /practise/cptest/
cp: overwrite ‘/practise/cptest/cp1.out’? y
以上命令部分即為單源復制的相關操作。
多源復制:cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… -t DIRECTORY SOURCE…
如果DEST不存在:錯誤;
如果DEST存在:
如果DEST是非目錄文件:錯誤;
如果DEST是目錄文件:分別復制每個文件至目標目錄中,并保持原名;
多源復制和單源復制的功能基本相同,就不一一贅述了。
常用選項:
-i:交互式復制,即覆蓋之前提醒用戶確認;
之前覆蓋命令行時,即時沒有輸入-i也出現了覆蓋提示,是因為使用了別名,輸入alias即可查詢。
alias cp=’cp -i’
alias date=’date “+%a %b %d %H:%M:%S %Z %Y”‘
alias egrep=’egrep –color=auto’
alias fgrep=’fgrep –color=auto’
alias grep=’grep –color=auto’
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’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’
可以看出實際上輸入的cp就是cp -i的命令。
-f:強制覆蓋目標文件;
[root@localhost /]# cp -f /test/cp1.out /practise/cptest/
cp: overwrite ‘/practise/cptest/cp1.out’?
[root@localhost /]# \cp -f /test/cp1.out /practise/cptest/
[root@localhost /]# ll /practise/cptest/
total 4
-rw-r–r–. 1 root root 370 Jul 27 14:41 cp1.out
與之前相比,cp1.out這個文件的修改時間已經發生了變化,說明這個命令強制覆蓋了,而最前面的‘\’的使用則是為了不使用別名的功能。
-r, -R:遞歸復制目錄;
[root@localhost cptest]# pwd
/practise/cptest
[root@localhost cptest]# ls
cp1.out
[root@localhost cptest]# cp -r /home/gentoo/ /practise/cptest/gentoo/
[root@localhost cptest]# cd /practise/cptest/gentoo/
[root@localhost gentoo]# ls
[root@localhost gentoo]# cd ..
[root@localhost cptest]# ls
cp1.out gentoo
此段命令可以看出-r的使用方法。
-d:復制符號鏈接文件本身,而非其指向的源文件;
-a:-dR –preserve=all, archive,用于實現歸檔;
–preserv=
mode:權限
ownership:屬主和屬組
timestamps: 時間戳
context:安全標簽
xattr:擴展屬性
links:符號鏈接
all:上述所有屬性
- mv
mv命令:move
mv [OPTION]… [-T] SOURCE DEST
mv [OPTION]… SOURCE… DIRECTORY
mv [OPTION]… -t DIRECTORY SOURCE..
常用選項:
-i:交互式;
-f:force
- rm
rm命令:remove
rm [OPTION]… FILE…
常用選項:
-i:interactive
-f:force
-r: recursive
刪除目錄:rm -rf /PATH/TO/DIR
危險操作:rm -rf /*
鑒于mv、rm命令與cp命令的相似性,在此就不再一一解釋了
注意:所有不用的文件建議不要直接刪除,而是移動至某個專用目錄;(模擬回收站)
二、bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示
- 命令執行狀態返回值
由于man bash查詢出的命令過于龐大,就不在此處復制。每一條命令的執行,默認都會返回一個狀態值,其中0代表成功,1-255代表各種失敗的狀態,二這個狀態返回值保存于bash的特殊變量$?中,通過echo $?即可查詢,示例如下:
[root@localhost /]# mkdir -pv /test/file
mkdir: created directory ‘/test’
mkdir: created directory ‘/test/file’
[root@localhost /]# echo $?
0
[root@localhost /]# rmdir -pv /test/file1
rmdir: removing directory, ‘/test/file1’
rmdir: failed to remove ‘/test/file1’: No such file or directory
[root@localhost /]# echo $?
1
- 命令行展開
~:自動展開為用戶的家目錄,或指定的用戶的家目錄;
{}:可承載一個以逗號分隔的路徑列表,并能夠將其展開為多個路徑;
例如:/tmp/{a,b} 相當于 /tmp/a /tmp/b
[root@localhost ~]# cd /etc/ntp/crypto/
[root@localhost crypto]# pwd
/etc/ntp/crypto
[root@localhost crypto]# cd ~
[root@localhost ~]# pwd
/root
如上所示,正確的使用~可以快速的返回用戶的家目錄。
三、使用命令行展開功能來完成以下練習
我會將所有練習中的tmp目錄統一更換為practise目錄
3.1
[root@localhost practise]# mkdir -pv /practise/{a,b}_{c,d}
mkdir: created directory ‘/practise/a_c’
mkdir: created directory ‘/practise/a_d’
mkdir: created directory ‘/practise/b_c’
mkdir: created directory ‘/practise/b_d’
[root@localhost practise]# ls
a_c cptest mail.rc man6 modprobe.d
a_d filep makedumpfile.conf.sample man7 modules-load.d
a.txt functions.out man man8 motd
a-z issue1 man1 man9 mtab
A-Z issue.tee man2 man_db.conf multipath
b_c machine-id man3 maven my.cnf
b_d magic man4 mime.types my.cnf.d
cat.out mailcap man5 mke2fs.conf system-release
3.2
[root@localhost practise]# mkdir -pv /practise/mylinux/{bin,boot/grub,dev,etc/{rc.d/ini.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,user/local/{bin,sbin},var/{lock,log,run}}
mkdir: created directory ‘/practise/mylinux’
mkdir: created directory ‘/practise/mylinux/bin’
mkdir: created directory ‘/practise/mylinux/boot’
mkdir: created directory ‘/practise/mylinux/boot/grub’
mkdir: created directory ‘/practise/mylinux/dev’
mkdir: created directory ‘/practise/mylinux/etc’
mkdir: created directory ‘/practise/mylinux/etc/rc.d’
mkdir: created directory ‘/practise/mylinux/etc/rc.d/ini.d’
mkdir: created directory ‘/practise/mylinux/etc/sysconfig’
mkdir: created directory ‘/practise/mylinux/etc/sysconfig/network-scripts’
mkdir: created directory ‘/practise/mylinux/lib’
mkdir: created directory ‘/practise/mylinux/lib/modules’
mkdir: created directory ‘/practise/mylinux/lib64’
mkdir: created directory ‘/practise/mylinux/proc’
mkdir: created directory ‘/practise/mylinux/sbin’
mkdir: created directory ‘/practise/mylinux/sys’
mkdir: created directory ‘/practise/mylinux/tmp’
mkdir: created directory ‘/practise/mylinux/user’
mkdir: created directory ‘/practise/mylinux/user/local’
mkdir: created directory ‘/practise/mylinux/user/local/bin’
mkdir: created directory ‘/practise/mylinux/user/local/sbin’
mkdir: created directory ‘/practise/mylinux/var’
mkdir: created directory ‘/practise/mylinux/var/lock’
mkdir: created directory ‘/practise/mylinux/var/log’
mkdir: created directory ‘/practise/mylinux/var/run’
為了更直觀的看清楚,可以使用tree命令
[root@localhost practise]# tree mylinux/
mylinux/
├── bin
├── boot
│?? └── grub
├── dev
├── etc
│?? ├── rc.d
│?? │?? └── ini.d
│?? └── sysconfig
│? ? ? ? └── network-scripts
├── lib
│?? └── modules
├── lib64
├── proc
├── sbin
├── sys
├── tmp
├── user
│?? └── local
│? ? ? ? ? ├── bin
│? ? ? ? ? └── sbin
└── var
? ? ? ├── lock
? ? ? ├── log
? ? ? └── run
24 directories, 0 files
四、文件的元數據信息
先查看一下文件的源信息有哪些
[root@localhost ~]# stat /practise/cptest/cp1.out
File: ‘/practise/cptest/cp1.out’
Size: 370 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4494 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:default_t:s0
Access: 2018-07-31 15:26:41.169470109 +0800
Modify: 2018-07-31 15:26:41.169470109 +0800
Change: 2018-07-31 15:26:41.169470109 +0800
Birth: –
那這些原數據代表什么含義呢?可以通過命令檢索所需要的內容
[root@localhost ~]# whatis stat
stat (2) – get file status
stat (3p) – get file status
stat (1) – display file or file system status
[root@localhost ~]# man 2 stat
The stat structure
All of these system calls return a stat structure, which contains the
following fields:
struct stat {
dev_t st_dev; /* ID of device containing file */ 文件名稱
ino_t st_ino; /* inode number */文件的inode
mode_t st_mode; /* file type and mode */文件的權限
nlink_t st_nlink; /* number of hard links */文件的硬鏈接個數
uid_t st_uid; /* user ID of owner */文件的UID
gid_t st_gid; /* group ID of owner */文件的GID(組ID)
dev_t st_rdev; /* device ID (if special file) */設備ID號
off_t st_size; /* total size, in bytes */文件的大小
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
/* Since Linux 2.6, the kernel supports nanosecond
precision for the following timestamp fields.
For the details before Linux 2.6, see NOTES. */
struct timespec st_atim; /* time of last access */文件的最后訪問時間
struct timespec st_mtim; /* time of last modification */文件的修改時間
struct timespec st_ctim; /* time of last status change */文件的最后用戶改變時間
#define st_atime st_atim.tv_sec /* Backward compatibility */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
};
上述信息中比較重要的就是三個時間戳信息,如何對他們進行一一修改,就需要用到touch命令
NAME
touch – change file timestamps
SYNOPSIS
touch [OPTION]… FILE…
-a change only the access time
-c, –no-create
do not create any files
-m change only the modification time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
做幾個操作驗證一下
[root@localhost ~]# touch -a /practise/cptest/cp1.out
[root@localhost ~]# stat /practise/cptest/cp1.out
File: ‘/practise/cptest/cp1.out’
Size: 370 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4494 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:default_t:s0
Access: 2018-08-01 16:09:16.950950710 +0800
Modify: 2018-07-31 15:26:41.169470109 +0800
Change: 2018-08-01 16:09:16.950950710 +0800
Birth: –
[root@localhost ~]# touch -m /practise/cptest/cp1.out
[root@localhost ~]# stat /practise/cptest/cp1.out
File: ‘/practise/cptest/cp1.out’
Size: 370 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 4494 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:default_t:s0
Access: 2018-08-01 16:09:16.950950710 +0800
Modify: 2018-08-01 16:11:59.061199361 +0800
Change: 2018-08-01 16:11:59.061199361 +0800
Birth: –
通過以上命令可以發現,當修改單獨Access或Modify時,Change都會隨之改變。
五、如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果
[root@localhost ~]# ls -a /practise/cptest/
. .. cp1.out gentoo
[root@localhost ~]# ls /practise/cptest/
cp1.out gentoo
[root@localhost ~]# alias la=’ls -a’
[root@localhost ~]# la /practise/cptest/
. .. cp1.out gentoo
從上可以看出,紅色部分為定義命令的別名。如何在命令中引用另一個命令的執行結果可見下面的示例:
[root@localhost ~]# echo `date` > /practise/errordate.out
[root@localhost ~]# cat /practise/errordate.out
Wed Aug 01 17:08:05 CST 2018
[root@localhost ~]# echo $(date) > /practise/errordate.out
[root@localhost ~]# cat /practise/errordate.out
Wed Aug 01 17:08:32 CST 2018
[root@localhost ~]# echo $(date) >> /practise/errordate.out
[root@localhost ~]# cat /practise/errordate.out
Wed Aug 01 17:08:32 CST 2018
Wed Aug 01 17:08:45 CST 2018
可以看出$(COMMAND)或者`COMMAND`都可以達到引用命令執行結果。
六、一些基礎命令的使用
1、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一個數字(可以有其他字符)的文件或目錄。
[root@localhost ~]# ls -d /var/l*[0-9]*[[:lower:]]
ls: cannot access /var/l*[0-9]*[[:lower:]]: No such file or directory
[root@localhost ~]# ls -d /var/l*
/var/lib /var/local /var/lock /var/log
2、顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。
[root@localhost ~]# ls -d /etc/[0-9]*[^0-9]
ls: cannot access /etc/[0-9]*[^0-9]: No such file or directory
3、顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其他任意長度任意字符的文件或目錄。
[root@localhost ~]# ls -d /etc/[^a-z][a-z]*
ls: cannot access /etc/[^a-z][a-z]*: No such file or directory
4、在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,
[root@bogon ~]# mkdir /tmp/tfile-`date +%F-%H-%M-%S`
[root@bogon ~]# ls /tmp/
[root@bogon ~]# ls -d /tmp/tfile*
/tmp/tfile-2018-08-02-10-40-45
5、復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。
[root@bogon ~]# cp -r /etc/p*[^0-9] /tmp/mytest1
cp: target ‘/tmp/mytest1’ is not a directory
[root@bogon ~]# mkdir /tmp/mytest1
[root@bogon ~]# cp -r /etc/p*[^0-9] /tmp/mytest1
[root@bogon ~]# ll /tmp/mytest1/
total 48
drwxr-xr-x. 2 root root 4096 Aug 2 10:53 pam.d
-rw-r–r–. 1 root root 2012 Aug 2 10:53 passwd
-rw-r–r–. 1 root root 2000 Aug 2 10:53 passwd-
-rw-r–r–. 1 root root 1362 Aug 2 10:53 pbm2ppa.conf
-rw-r–r–. 1 root root 2872 Aug 2 10:53 pinforc
drwxr-xr-x. 10 root root 116 Aug 2 10:53 pki
drwxr-xr-x. 2 root root 28 Aug 2 10:53 plymouth
drwxr-xr-x. 5 root root 52 Aug 2 10:53 pm
-rw-r–r–. 1 root root 6300 Aug 2 10:53 pnm2ppa.conf
drwxr-xr-x. 2 root root 6 Aug 2 10:53 popt.d
drwxr-xr-x. 2 root root 154 Aug 2 10:53 postfix
drwxr-xr-x. 3 root root 219 Aug 2 10:53 ppp
drwxr-xr-x. 2 root root 78 Aug 2 10:53 prelink.conf.d
-rw-r–r–. 1 root root 233 Aug 2 10:53 printcap
-rw-r–r–. 1 root root 1819 Aug 2 10:53 profile
drwxr-xr-x. 2 root root 4096 Aug 2 10:53 profile.d
-rw-r–r–. 1 root root 6545 Aug 2 10:53 protocols
drwxr-xr-x. 2 root root 79 Aug 2 10:53 pulse
drwxr-xr-x. 2 root root 23 Aug 2 10:53 purple
drwxr-xr-x. 2 root root 35 Aug 2 10:53 python
6、復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中。
[root@bogon ~]# mkdir /tmp/mytest2
[root@bogon ~]# cp -r /etc/*.d /tmp/mytest2/
[root@bogon ~]# ls -d /etc/*.d
/etc/auto.master.d /etc/logrotate.d /etc/rc5.d
/etc/bash_completion.d /etc/modprobe.d /etc/rc6.d
/etc/binfmt.d /etc/modules-load.d /etc/rc.d
/etc/cgconfig.d /etc/my.cnf.d /etc/reader.conf.d
/etc/chkconfig.d /etc/oddjobd.conf.d /etc/request-key.d
/etc/cron.d /etc/pam.d /etc/rsyslog.d
/etc/depmod.d /etc/popt.d /etc/rwtab.d
/etc/dracut.conf.d /etc/prelink.conf.d /etc/setuptool.d
/etc/exports.d /etc/profile.d /etc/statetab.d
/etc/gdbinit.d /etc/rc0.d /etc/sudoers.d
/etc/grub.d /etc/rc1.d /etc/sysctl.d
/etc/init.d /etc/rc2.d /etc/tmpfiles.d
/etc/krb5.conf.d /etc/rc3.d /etc/xinetd.d
/etc/ld.so.conf.d /etc/rc4.d /etc/yum.repos.d
[root@bogon ~]# ls -d /tmp/mytest2/*.d
/tmp/mytest2/auto.master.d /tmp/mytest2/prelink.conf.d
/tmp/mytest2/bash_completion.d /tmp/mytest2/profile.d
/tmp/mytest2/binfmt.d /tmp/mytest2/rc0.d
/tmp/mytest2/cgconfig.d /tmp/mytest2/rc1.d
/tmp/mytest2/chkconfig.d /tmp/mytest2/rc2.d
/tmp/mytest2/cron.d /tmp/mytest2/rc3.d
/tmp/mytest2/depmod.d /tmp/mytest2/rc4.d
/tmp/mytest2/dracut.conf.d /tmp/mytest2/rc5.d
/tmp/mytest2/exports.d /tmp/mytest2/rc6.d
/tmp/mytest2/gdbinit.d /tmp/mytest2/rc.d
/tmp/mytest2/grub.d /tmp/mytest2/reader.conf.d
/tmp/mytest2/init.d /tmp/mytest2/request-key.d
/tmp/mytest2/krb5.conf.d /tmp/mytest2/rsyslog.d
/tmp/mytest2/ld.so.conf.d /tmp/mytest2/rwtab.d
/tmp/mytest2/logrotate.d /tmp/mytest2/setuptool.d
/tmp/mytest2/modprobe.d /tmp/mytest2/statetab.d
/tmp/mytest2/modules-load.d /tmp/mytest2/sudoers.d
/tmp/mytest2/my.cnf.d /tmp/mytest2/sysctl.d
/tmp/mytest2/oddjobd.conf.d /tmp/mytest2/tmpfiles.d
/tmp/mytest2/pam.d /tmp/mytest2/xinetd.d
/tmp/mytest2/popt.d /tmp/mytest2/yum.repos.d
7、復制/etc目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。
[root@bogon ~]# ls -d /etc/{l,m,n}*.conf
/etc/ld.so.conf /etc/locale.conf /etc/mke2fs.conf /etc/nsswitch.conf
/etc/libaudit.conf /etc/logrotate.conf /etc/nfs.conf /etc/ntp.conf
/etc/libuser.conf /etc/man_db.conf /etc/nfsmount.conf
[root@bogon ~]# mkdir /tmp/mytest3
[root@bogon ~]# cp -r /etc/{l,m,n}*.conf /tmp/mytest3
[root@bogon ~]# ls -d /tmp/mytest3/{l,m,n}*.conf
/tmp/mytest3/ld.so.conf /tmp/mytest3/mke2fs.conf
/tmp/mytest3/libaudit.conf /tmp/mytest3/nfs.conf
/tmp/mytest3/libuser.conf /tmp/mytest3/nfsmount.conf
/tmp/mytest3/locale.conf /tmp/mytest3/nsswitch.conf
/tmp/mytest3/logrotate.conf /tmp/mytest3/ntp.conf
/tmp/mytest3/man_db.conf
以上為本次學習內容,如有錯誤敬請指出~
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/104013
從文章中學習到基礎命令的用法和作者遇到的一些坑,很不錯,在排版上優化一下會更好,繼續加油。