第二周 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 保留了: permownershiptimestampscontextxattrlinksall 用于备份


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.178linux.com/89771

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

相关推荐

  • 常见的文本处理工具及正则表达式的相关知识

    1.cat命令使用详解 cat [option]… [file]… -A equivalent=vET -b 非空行编号 -E 行为显示$ -n 显示所有行的行号 -s 行号并压缩连续空行为一行 -T 显示tab为^M 实例:显示a文件的行号及所有控制符 2.(1)head使用详解 head -n x 显示前x行 head -c x …

    Linux干货 2016-08-07
  • 命令别名以及元数据。

    命令别名alias: 命令别名:     获取所有可用别名的定义;         ~]# alias         定义别名:  &nb…

    Linux干货 2016-11-05
  • N21_第7周_磁盘及文件系统管理

    N21_第7周_磁盘及文件系统管理 作业题目: 1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;    (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳…

    Linux干货 2016-09-26
  • CentOS通过bind配置DNS服务器

    一、创建DNS主服务器 1、安装bind并配置主配置文件     主服务器为CentOS 7,主服务地址为172.16.11.55     安装bind [root@xinfeng ~]# yum install bind  &n…

    Linux干货 2016-04-18
  • 马哥教育网络21期+第三周练习博客

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who | cut -d' ' -f 1 | uniq 2、取出最后登录到当前系统的用户的相关信息。 [root…

    Linux干货 2016-07-26
  • keepalived+nginx 模型示例

    原理为: 调度器 利用 keepalived 保持高可用性,实现对系统的监控和VIP 的floating NGINX 利用upstream模块进行调度 关键点: keepalived 对NGINX 状态的监控: //利用配置文件中设定的脚本对调度器的nginx 进程的监控 实验步骤: 基于上一篇LVS-DR架构来做,具体LVS-DR架构请参考上一篇 先设置主…

    2017-05-13

评论列表(1条)

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

    学了rm之后不应该再有rmdir这个命令的疑问了~~后面实战的部分也建议使用markdown~继续加油