第二周 N28

作業二

1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。

文件類型:

  • f: 常規文件,即f;
  • d: directory,目錄文件;
  • b: block device, 塊設備文件; block為單位,隨機訪問;
  • c: character device,字符設備文件;character為單位,線性訪問;
  • l: symbolic link, 符號鏈接文件、軟鏈接文件;
  • p: name pipe,命名管道,有名字的管道;
  • s: socket,套接字文件;

 

目錄管理: mkdir, rmdir

mkdir

  • 命令參數是路徑基名,且其父目錄必須存在!

 

[root@localhost? ~]# ls /tmp/a/b/c
[root@localhost ~]# mkdir /tmp/a/b/c
mkdir: cannot create directory ‘/tmp/a/b/c’: No such file or directory


  • 父目錄不存在時,可以使用 -p選項自動創建之;

 

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

  • 創建后的目錄,默認權限是755。創建時,直接以選項參數給出其權限。
[root@localhost ~]# ls -ld /tmp/a/b/c
drwxr-xr-x. 1 root root 0 Dec 9 23:56 /tmp/a/b/c
[root@localhost ~]# mkdir -vp -m 700 /tmp/u/o/v
mkdir: created directory ‘/tmp/u/o’
mkdir: created directory ‘/tmp/u/o/v’
[root@localhost ~]# ls -ld /tmp/u/o/v
drwx------. 1 root root 0 Dec 9 23:59 /tmp/u/o/v

 

 

rmdir

  • 只能刪除空目錄。

 

[root@localhost ~]# rmdir /tmp/u/o/v
[root@localhost ~]# rmdir /tmp/u/o
[root@localhost ~]# rmdir /tmp/u

 

  • 這樣刪除豈不是很麻煩?空目錄刪除后,其上一組目錄為空時,自動刪除;

 

[root@localhost ~]# rmdir -pv /tmp/a/b/c
rmdir: removing directory, ‘/tmp/a/b/c’
rmdir: removing directory, ‘/tmp/a/b’
rmdir: removing directory, ‘/tmp/a’
rmdir: removing directory, ‘/tmp’
rmdir: failed to remove directory ‘/tmp’: Device or resource busy

 

文件管理: cp, rm, mv

cp

  • 源:文件、目錄
  • 目標:存在、不存在

源:單個文件

  • 目標存在
    • 文件:覆蓋目標文件。
    • 目錄:創建與原文件同名的文件,并復制源文件數據流至此文件;復制后原名;
  • 目標不存在:創建目標文件,并復制源文件數據流至此文件中:復制后重命名;

例如:

目標不存在:

[root@localhost ~]# mkdir test
[root@localhost ~]# cp /etc/fstab test/hi
[root@localhost ~]# cat /etc/fstab test/hi

目標存在為目錄:

[root@localhost ~]# cp /etc/inittab test
[root@localhost ~]# ls test
hi inittab

目標存在為文件:

[root@localhost ~]# cp /etc/issue test/hi
cp: overwrite ‘test/hi’? y
[root@localhost ~]# cat test/hi
\S
Kernel \r on an \m

[root@localhost ~]#

源為單個目錄:和-r選項同時使用

  • 目標不存在:創建空目錄,遞歸復制源目錄下的所有文件至此目錄中;
  • 目標存在:創建與原目錄同名的空目錄,遞歸復制源目錄下的所有文件至此目錄中;

例如:

目標不存在:

[root@localhost ~]# cp /etc/init.d/ testdir
cp: omitting directory ‘/etc/init.d/’
[root@localhost ~]# cp -r /etc/init.d/ testdir
[root@localhost ~]# ls 
anaconda-ks.cfg sql.sh testdir test.sql

目標存在為目錄:

[root@localhost ~]# ls testdir/
functions netconsole network README
[root@localhost ~]# cp -r /etc/init.d/ testdir
[root@localhost ~]# ls testdir/
functions init.d netconsole network README

  • cp命令是本身的別名,執行原命令:\COMMAND
  • 復制鏈接文件;-d
  • 歸檔復制:-a

例如:

[root@localhost ~]# type cp
cp is aliased to `cp -i’
[root@localhost ~]# ls testdir
functions init.d netconsole network README
[root@localhost ~]# cp /etc/fstab testdir/functions
cp: overwrite ‘testdir/functions’? n
[root@localhost ~]# \cp /etc/fstab testdir/functions
[root@localhost ~]#

 

復制鏈接:

[root@localhost ~]# file /etc/system-release
/etc/system-release: symbolic link to `centos-release’
[root@localhost ~]# cp /etc/system-release system
[root@localhost ~]# file system
system: ASCII text
[root@localhost ~]# cp -d /etc/system-release system.link
[root@localhost ~]# file system.link
system.link: broken symbolic link to `centos-release’

 

歸檔復制:-a 保留了: permownership、timestampscontext、xattrlinks、all 用于備份


rm

  • 所有不用的文件不建議刪除,而是移動到另一個目錄;
  • rm是rm的別名,別名同原名時,原命令被隱藏;此時執行原命令:\COMMAND
[root@localhost ~]# type rm
rm is aliased to `rm -i'  刪除時交互式確認
[root@localhost ~]# rm test/hi
rm: remove regular file ‘test/hi’? n
[root@localhost ~]# ls test
hi inittab
[root@localhost ~]# \rm test/hi
[root@localhost ~]# ls test
inittab


  • 遞歸刪除目錄;-rf
[root@localhost ~]# rm test
rm: cannot remove ‘test’: Is a directory
[root@localhost ~]# rm -rf test
[root@localhost ~]# ls test
ls: cannot access test: No such file or directory

 

mv

  • 類似于cp命令,只是復制后會刪除原文件;復制目錄使用-r選項,但移動無須使用-r;

例如:

[root@localhost ~]# ls
anaconda-ks.cfg fstab magedu sql.sh system system.link testdir test.sql
[root@localhost ~]# pwd
/root
[root@localhost ~]# mv testdir /root/ab
[root@localhost ~]# ls
ab anaconda-ks.cfg fstab magedu sql.sh system system.link test.sql

 

 

文件查看:cat, tac, more, less, head, tail

cat

  • 連接文件并顯示至標準輸出上;

例如:

[root@localhost ~]# file /etc/fstab 
/etc/fstab: ASCII text
[root@localhost ~]# file /etc/issue
/etc/issue: ASCII text
[root@localhost ~]# cat /etc/issue /etc/fstab
  • 給所有行編號:-n
[root@localhost ~]# cat -n /etc/issue /etc/fstab 
 1 \S
 2 Kernel \r on an \m
 3 
 4 
 5 #
 6 # /etc/fstab
 7 # Created by anaconda on Wed Dec 6 02:29:53 2017
 8 #
 9 # Accessible filesystems, by reference, are maintained under '/dev/disk'
 10 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
 11 #
 12 UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d / btrfs subvol=root 0 0
 13 UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0
 14 UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0
 15 UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0
  • 給非空白行編號:-b
[root@localhost ~]# cat -b /etc/issue /etc/fstab 
 1 \S
 2 Kernel \r on an \m


 3 #
 4 # /etc/fstab
 5 # Created by anaconda on Wed Dec 6 02:29:53 2017
 6 #
 7 # Accessible filesystems, by reference, are maintained under '/dev/disk'
 8 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
 9 #
 10 UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d / btrfs subvol=root 0 0
 11 UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0
 12 UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0
 13 UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0
  • 顯示$符:-E (Linux中行結束符為 $ )
[root@localhost ~]# cat -E /etc/issue /etc/fstab 
\S$
Kernel \r on an \m$
$
$
#$
# /etc/fstab$
# Created by anaconda on Wed Dec 6 02:29:53 2017$
#$
# 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=1c6a31f6-ebce-4324-bcb8-9bd036e5139d / btrfs subvol=root 0 0$
UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0$
UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0$
UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0$

 

tac

  • 和cat結果相反
[root@localhost ~]# tac /etc/issue /etc/fstab

Kernel \r on an \m
\S
UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0
UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0
UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0
UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d / btrfs subvol=root 0 0
#
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
# Accessible filesystems, by reference, are maintained under '/dev/disk'
#
# Created by anaconda on Wed Dec 6 02:29:53 2017
# /etc/fstab
#

more,less

  • 使用方法相同:SPACE, b, ^d, ^u, ^f, ^b, Enter, ^k(^表示Ctrl鍵)

 

head

  • -n # : 顯示前n行,默認顯示前10行;
[root@localhost ~]# head -3 /etc/issue 有趣的是和 -n 3相同;
\S
Kernel \r on an \m

[root@localhost ~]# head -n 3 /etc/issue
\S
Kernel \r on an \m

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

[root@localhost ~]#

 

tail

  • -n #: 顯示后n行,默認后10行;
[root@localhost ~]# tail -3 /etc/fstab 
UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0
UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0
UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0
[root@localhost ~]# tail -n 3 /etc/fstab 
UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0
UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0
UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0
[root@localhost ~]# tail /etc/fstab
# /etc/fstab
# Created by anaconda on Wed Dec 6 02:29:53 2017
#
# 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=1c6a31f6-ebce-4324-bcb8-9bd036e5139d / btrfs subvol=root 0 0
UUID=2be7b8fa-06a8-4bfc-8dfd-f16028231da9 /boot xfs defaults 0 0
UUID=1c6a31f6-ebce-4324-bcb8-9bd036e5139d /home btrfs subvol=home 0 0
UUID=b89ca20c-115e-478e-a26e-20933d3ddc97 swap swap defaults 0 0

文本處理命令: nano, cut, sort, tr, wc, diff, patch

nano

  • 全屏編輯器:
    • 目標文件不存在,自動創建之;
    • 目標文件存在,打開之;

 

cut

  • 文件截取工具;從文件的每一行截取片段;
  • -d ‘DELM’ 指定分割符
  • -f ‘LIST’ 挑選字段
    • LIST:
      • #:單個字段
      • #-#: 連續字段
      • #,#-#,#…離散字段

例如:

[root@localhost ~]# cut -d':' -f1 /etc/passwd 


[root@localhost ~]# cut -d':' -f1,3 /etc/passwd 


[root@localhost ~]# cut -d':' -f1,3-5,7 /etc/passwd

 

sort

  • 排序每一行,以ASCII碼編碼

例如:

[root@localhost ~]# cut -d':' -f3 /etc/passwd | sort
0
1
1000
1001
1002
11
113
12
14
170
171
172
173
2
27
29
3
32
38
4
42
  • 沒有按照數字大小排序,如何進行數字順序而非ASCII碼排序?
[root@localhost ~]# cut -d':' -f3 /etc/passwd | sort -n
0
1
2
3
4
5
6
7
8
11


  • 逆序:-r
[root@localhost ~]# cut -d':' -f3 /etc/passwd | sort -n -r
65534
1002
1001
1000
999
998
997
996
995


  • 去重:-u
[root@localhost ~]# history | cut -d' ' -f5 | sort -u

  • 以指定字段排序:-t ‘DEML’ -k ‘LIST’
[root@localhost ~]# sort -t: -k3 -n /etc/passwd

 

tr

  • 對位轉換,刪除字符

例如:

  • 對位轉換 tr ‘SET1’ ‘SET2’ 將SET1給出的字符對位轉換至SET2
[root@localhost ~]# echo "MageEdu" | tr 'a-z' 'A-Z'
MAGEEDU
  • 刪除字符
[root@localhost ~]# echo "MageEdu" | tr -d a
MgeEdu
  • 保留字符
~]# echo "MageEdu" | tr -dc a
a[root@localhost ~]# 


[root@localhost ~]# echo "MageEdu" | tr -dc a | xargs
a

wc

  • 行數統計
[root@localhost ~]# wc /etc/fstab 
 12 60 595 /etc/fstab
[root@localhost ~]# wc -l /etc/fstab 行
12 /etc/fstab
[root@localhost ~]# wc -w /etc/fstab 單詞
60 /etc/fstab
[root@localhost ~]# wc -m /etc/fstab 字符
595 /etc/fstab

擴展:

[root@localhost ~]# wc -l < /etc/fstab
12
[root@localhost ~]# cat /etc/fstab | wc -l
12
[root@localhost ~]# wc -l /etc/fstab | cut -d' ' -f1
12

diff

  • 生成補丁逐行比較文件中的內容
[root@localhost ~]# cat my.txt 
123
345
[root@localhost ~]# cat my.new 
123
345
799
  • 制作補丁
[root@localhost ~]# diff my.txt my.new > my.patch

patch

  • 打補丁
[root@localhost ~]# cat my.txt 
123
345
[root@localhost ~]# cat my.new 
123
345
799
[root@localhost ~]# patch -i my.patch my.txt
patching file my.txt
[root@localhost ~]# cat my.txt 
123
345
799
[root@localhost ~]# cat my.new 
123
345
799
  • 回滾:
[root@localhost ~]# patch -R my.txt my.patch 
patching file my.txt
[root@localhost ~]# cat my.txt
123
345

2、bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示。

命令執行狀態返回值

bash通過狀態返回值輸出其結果:

  • 成功: 0
  • 失敗: 1-255: 不幸的家族各有各的不幸;
[root@localhost ~]# ls /var
account cache db ftp gdm kerberos local log nis preserve spool var yp
adm crash empty games gopher lib lock mail opt run tmp www
[root@localhost ~]# echo $?
0
[root@localhost ~]# ls /varr
ls: cannot access /varr: No such file or directory
[root@localhost ~]# echo $?
2
[root@localhost ~]# lss /var
-bash: lss: command not found
[root@localhost ~]# echo $?
127

命令行展開

自動展開為當前有效用戶的家目錄: ~[USERNAME]

[root@localhost ~]# echo ~
/root
[root@localhost ~]# id centos
uid=1002(centos) gid=1002(centos) groups=1002(centos)
[root@localhost ~]# echo ~centos
/home/centos
[root@localhost ~]# id fedo
id: fedo: no such user
[root@localhost ~]# echo ~fedo
~fedo

可承載一個以逗號分隔的路徑列表,并能夠將其展開為多個路徑: { LIST }

[root@localhost ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10

[root@localhost ~]# mkdir /tmp/{a,b}
[root@localhost ~]# ls /tmp/{a,b}
/tmp/a:

/tmp/b:

3、請使用命令行展開功能來完成以下練習:
(1)、創建/tmp目錄下的:a_c, a_d, b_c, b_d

  • touch /tmp/{a,b}_{c,d}

(2)、創建/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

~]# mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var,lock,log,run}

4、文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息。

  • 文件
    • 元數據:屬性信息
    • 數據

獲取元數據:

[root@localhost ~]# stat anaconda-ks.cfg
File: ‘anaconda-ks.cfg’ 文件名
Size: 1637 Blocks: 8 IO Block: 4096 regular file

大小, 塊, IO塊,普通文件

Device: 23h/35d Inode: 116147 Links: 1

塊設備號, Inode號, 被硬鏈接的次數

Access: (0600/-rw——-) Uid: ( 0/ root) Gid: ( 0/ root)

訪問權限(mask/權限) UID, GID

Context: system_u:object_r:admin_home_t:s0

安全標簽

Access: 2017-12-10 00:26:40.038441041 +0800

訪問時間戳

Modify: 2017-12-06 02:45:03.427012688 +0800

修改時間戳
Change: 2017-12-06 02:45:03.427012688 +0800

改變時間戳

Birth: –

  • touch命令: 修改時間戳

默認會創建一個文件;

[root@localhost ~]# file a
a: cannot open (No such file or directory)
[root@localhost ~]# touch a
[root@localhost ~]# file a
a: empty

修改atime

[root@localhost ~]# touch -a anaconda-ks.cfg 
[root@localhost ~]# stat anaconda-ks.cfg 
 File: ‘anaconda-ks.cfg’
 Size: 1637 Blocks: 8 IO Block: 4096 regular file
Device: 23h/35d Inode: 116147 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2017-12-10 01:21:09.254267871 +0800
Modify: 2017-12-06 02:45:03.427012688 +0800
Change: 2017-12-10 01:21:09.254267871 +0800
 Birth: -

修改mtime

[root@localhost ~]# touch -m anaconda-ks.cfg 
[root@localhost ~]# stat anaconda-ks.cfg 
 File: ‘anaconda-ks.cfg’
 Size: 1637 Blocks: 8 IO Block: 4096 regular file
Device: 23h/35d Inode: 116147 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2017-12-10 01:21:09.254267871 +0800
Modify: 2017-12-10 01:21:44.839202055 +0800
Change: 2017-12-10 01:21:44.839202055 +0800
 Birth: -

不存在時,不創建文件

[root@localhost ~]# file b
b: cannot open (No such file or directory)
[root@localhost ~]# touch -c b
[root@localhost ~]# file b
b: cannot open (No such file or directory)

修改atime或mtime至指定時間;

[root@localhost ~]# touch -am -t 201211111111.00 anaconda-ks.cfg 
[root@localhost ~]# stat anaconda-ks.cfg 
 File: ‘anaconda-ks.cfg’
 Size: 1637 Blocks: 8 IO Block: 4096 regular file
Device: 23h/35d Inode: 116147 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2012-11-11 11:11:00.000000000 +0800
Modify: 2012-11-11 11:11:00.000000000 +0800
Change: 2017-12-10 01:23:14.967568140 +0800
 Birth: -

5、如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果?

Alias

  • 查看所有別名
[root@localhost ~]# alias
alias cp='cp -i'
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'
  • 定義別名
[root@localhost ~]# cls
-bash: cls: command not found
[root@localhost ~]# alias cls='clear'
[root@localhost ~]# alias
alias cls='clear'
alias cp='cp -i'
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'

  • 泉水別名
[root@localhost ~]# unalias cls
[root@localhost ~]# cls
-bash: cls: command not found

 

命令引用

命令執行結果:

1) $(COMMAND)

2)COMMAND

例如:

[root@localhost ~]# echo `pwd`
/root
[root@localhost ~]# echo $(date)
Sun Dec 10 01:28:42 CST 2017

強引用和弱引用

  • 1)變量會被替換為其值
  • 2)變量不會被替換為其值
[root@localhost ~]# echo "$SHELL"
/bin/bash
[root@localhost ~]# echo '$SHELL'
$SHELL

6、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄。

[root@localhost ~]# ls -d /var/l*[0-9]*[[:lower:]]

7、顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。

[root@localhost ~]# ls -d /etc/[0-9]*[^0-9]

8、顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄。

[root@localhost ~]# ls -d /etc/[^a-z][a-z]*

9、在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22。

[root@localhost ~]# touch /tmp/tfile-$(date +”%F-%H-%M-%S”)
[root@localhost ~]# ls /tmp/tf*[0-9]
/tmp/tfile-2017-12-10-01-36-08

10、復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。

[root@localhost ~]# mkdir -v /tmp/mytest1/
mkdir: created directory ‘/tmp/mytest1/’
[root@localhost ~]# ls -d /etc/p*[^0-9]
[root@localhost ~]# cp -a /etc/p*[^0-9] /tmp/mytest1/
[root@localhost ~]# ls /tmp/mytest1/
pam.d passwd- pinforc plymouth pnm2ppa.conf postfix prelink.conf.d profile protocols
passwd pbm2ppa.conf pki pm popt.d ppp printcap profile.d pulse

11、復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中。

[root@localhost ~]# mkdir -v /tmp/mytest2
mkdir: created directory ‘/tmp/mytest2’
[root@localhost ~]# ls -d /etc/*.d
[root@localhost ~]# cp -a /etc/*.d /tmp/mytest2
[root@localhost ~]# ls /tmp/mytest2

12、復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。

[root@localhost ~]# mkdir -v /tmp/mytest3
mkdir: created directory ‘/tmp/mytest3’
[root@localhost ~]# ls -d /etc/[lmn]*.conf
[root@localhost ~]# cp -a /etc/[lmn]*.conf /tmp/mytest3
[root@localhost ~]# ls /tmp/mytest3
ld.so.conf libaudit.conf locale.conf man_db.conf nfsmount.conf ntp.conf
lftp.conf libuser.conf logrotate.conf mke2fs.conf nsswitch.conf

 

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/89771

(1)
逆神陽逆神陽
上一篇 2017-12-09 20:46
下一篇 2017-12-10 09:36

相關推薦

  • 第三周:文本處理工具wc,cut,sort,uniq,tr,tee命令練習和用戶及組相關命令練習

    1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可; [root@app1 tmp]# who | cut -d" " -f1| uniq root dts centos 2、取出最后登錄到當前系統的用戶的相關信息; [r…

    Linux干貨 2016-09-27
  • CentOS環境下,ab性能測試功具介紹及使用

    網站性能壓力測試是服務器網站性能調優過程中必不可缺少的一環。只有讓服務器處在高壓情況下,才能真正體現出軟件、硬件等各種設置不當所暴露出的問題。 性能測試工具目前最常見的有以下幾種:ab、http_load、webbench、siege。 ab是apache自帶的壓力測試工具。ab非常實用,它不僅可以對apache服務器進行網站訪問壓力測試,也可以對或其它類型…

    Linux干貨 2017-07-22
  • 常用RAID級別淺析

    簡介:    RAID為獨立冗余磁盤陣列的簡稱,它可以通過軟件或硬件技術把多個較小的磁盤整合成一個較大的磁盤。從而實現較大的 磁盤存儲,容錯及數據保護功能,較快的數據讀寫等功能. 實現方式:      硬件實現方式:通過bios參數調整來實現      軟件實…

    2017-06-17
  • linux中權限管理

    權限的描述:           權限的意思就是用戶擁有的對系統支配能力的大小在linux中是嚴格控制用戶權限的,不同的用戶給予不同的權限,權限應遵循能少給就盡量少給的原則從而增加系統的安全性。 進程安全上下文:    進程對問件訪問權限的應用模型:進程的屬主與文件的屬主是否相同,如果相同…

    系統運維 2016-08-05
  • 0801課堂練習與作業

    1、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中      cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out 2、將當前系統登錄用戶的信息轉換為大寫后保存至/tmp/who.out文…

    Linux干貨 2016-08-02
  • Find命令的使用

    Find命令的基本用法 在Linux系統中find命令是一個強大文件查找類工具,它支持根據文件名,權限,文件大小,訪問以及修改時間查找,使用方法如下: find [option] [查找起始路徑] [查找條件] [處理動作] 起始路徑:指定查找文件或目錄的路徑,默認為當前目錄 查找條件:可根據文件名,權限,文件大小以及從屬關系查找文件 處理動作:動查找到的文…

    Linux干貨 2017-08-28

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-12-16 12:32

    學了rm之后不應該再有rmdir這個命令的疑問了~~后面實戰的部分也建議使用markdown~繼續加油

欧美性久久久久