第二周 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 保留了: perm、ownership、timestampscontext、xattr、links、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
下一篇 2017-12-10

相關推薦

  • 8月9日sed(更新版)

    sed命令及vim基礎使用命令 處理文本的工具sed stream editor,行編輯器    sed是一種流編輯器,它一次處理一行內容。處理時,把當前處理的行存儲在臨時緩沖區中,稱為“模式空間”(pattern space),接著用sed命令處理緩沖區中的內容,處理完成后,把緩沖區的內容送往屏幕。接著處理下一行,這樣不斷重復,直到文件末尾。文件內容并沒有…

    Linux干貨 2016-08-15
  • N25第六周作業

    vim 是vi編輯的升級版,同樣有三種工作模式:編輯、命令和一般 模式 #:指定行號位置 #,#:指定多少行到多少行 #,+#:指定范圍,多少行開始,加#行 $:最后一行 .:當前行 .,$-1,當前行到倒數第二行 1,$:全文 %:全文 /從上往下,?:從下往上 搜索 /pattern/:從光標所在處起始向文件尾部第一次被模式所匹配到的行 s/要查找的內容…

    Linux干貨 2017-01-11
  • N22-第四周作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 # cp -r /etc/skel /home/tuser1 # chmod 700 /home/tuser1 2、編輯/etc/group文件,添加組h…

    Linux干貨 2016-09-06
  • linux 基礎目錄配置及用途說明

    bin -> usr/bin 一般存放root和一般用戶都可以使用的指令例如:cat, chmod, chown, date, mv, mkdir, cp, bash 等等常用的指令,同時還存放著單人維護模式下還能夠被使用的指令。 boot  這個目錄主要放置開機會使用到的文件,包括linux核心文件以及開機選單和開機所需要的配置文件。 de…

    Linux干貨 2017-08-19
  • Linux文件系統管理

    一、什么是文件系統     我理解的文件系統就是管理磁盤分區上數據的索引信息,其實文件系統就是一種應用程序,只不過是用來維護和管理分區上的數據而已,就跟操作系統是用來管理底層硬件一樣。不同的分區可以有不同的文件系統。 二、文件系統類型     在linux系統上主要有如下類型的文件系統: &nbsp…

    Linux干貨 2016-03-03
  • 基于Cobbler實現多版本操作系統自動部署

    前言     在生產環境中,當需要批量部署幾十甚至上百臺服務器時,實現自動化安裝操作系統尤為重要,按照傳統的光盤引導安裝是不可想象的;此前我們通過pxe+kickstart簡單實現了自動化安裝,但只能實現單一版本安裝,當需要部署不同版本或不同引導模式(BIOS、EFI)時,此種方式就不夠靈活。而Cobbler正是為了解…

    Linux干貨 2015-08-11

評論列表(1條)

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

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

欧美性久久久久