1.printf格式化输出(format and print data)

语法:printf(选项)(参数)

参数

  • 输出格式:指定数据输出时的格式;
  • 输出字符串:指定要输出的数据。

格式替代符

  • %c ASCII字符。显示相对应参数的第一个字符
  • %d, %i 十进制整数
  • %e, %E, %f 浮点格式
  • %g %e或%f转换,看哪一个较短,则删除结尾的零
  • %G %E或%f转换,看哪一个较短,则删除结尾的零
  • %o 不带正负号的八进制值
  • %s 字符串
  • %u 不带正负号的十进制值
  • %x 不带正负号的十六进制值,使用a至f表示10至15
  • %X 不带正负号的十六进制值,使用A至F表示10至15
  • %% 字面意义的%
[root@test ~]# printf '%c\n'  1010
1
[root@test ~]# printf '%d\n' 123
123
[root@test ~]# printf '%e\n' 123
1.230000e+02
[root@test ~]# printf '%E\n' 123
1.230000E+02
[root@test ~]# printf '%f\n' 123
123.000000
[root@test ~]# printf '%g\n' 123
123
[root@test ~]# printf '%g\n' 123.123456
123.123
[root@test ~]# printf '%g\n' 123.000456
123
[root@test ~]# printf '%g\n' 123.00456
123.005
[root@test ~]# printf '%g\n' 123.00446
123.004
[root@test ~]# printf '%G\n' 123.00446
123.004
[root@test ~]# printf '%o\n' 101010
305222
[root@test ~]# printf '%o\n' 8
10
[root@test ~]# printf '%o\n' 8888
21270
[root@test ~]# printf '%s\n' abc
abc
[root@test ~]# printf '%u\n' -100
18446744073709551516
[root@test ~]# printf '%u\n' 100
100
[root@test ~]# printf '%x\n' 1010
3f2
[root@test ~]# printf '%x\n' -1010
fffffffffffffc0e
[root@test ~]# printf '%X\n' -1010
FFFFFFFFFFFFFC0E
[root@test ~]# printf '%X\n' 1010
3F2
[root@test ~]# printf '%%\n' 1010
%

转义序列

  • \a 警告字符,通常为ASCII的BEL字符
  • \b 后退
  • \c 抑制(不显示)输出结果中任何结尾的换行字符(只在%b格式指示符控制下的参数字符串中有效),而且,任何留在参数里的字符、任何接下来的参数以及任何留在格式字符串中的字符,都被忽略
  • \f 换页(formfeed)
  • \n 换行
  • \r 回车(Carriage return)
  • \t 水平制表符
  • \v 垂直制表符
  • \\ 一个字面上的反斜杠字符
[root@test ~]# printf 'abc\babc\n'
ababc
[root@test ~]# printf 'abc\cabc\n'
abc\cabc
[root@test ~]# printf 'abc\cabc\naaaa'
abc\cabc
aaaa[root@test ~]# printf 'abc\cabc\naaaa\nbadfas'
abc\cabc
aaaa
badfas[root@test ~]# printf 'abc\cabc\naaaa\fbadfas'
abc\cabc
aaaa
badfas[root@test ~]# printf 'abc\cabc\naaaa\fbadfas\n'
abc\cabc
aaaa
badfas
[root@test ~]# printf 'abc\cabc\naaaa\f\rbadfas\n'
abc\cabc
aaaa
badfas
[root@test ~]# printf 'abc\cabc\naaaa\f\rba\rdfas\n'
abc\cabc
aaaa
dfas
[root@test ~]# printf 'abc\cabc\naaaa\f\rbadfas\n'
abc\cabc
aaaa
badfas
[root@test ~]# printf 'abc\cabc\na\raaa\f\rbadfas\n'
abc\cabc
aaa
badfas
[root@test ~]# printf 'aaaa\tbbbn'
aaaa bbbn[root@test ~]# printf 'aaaa\tbbb\n'
aaaa bbb
[root@test ~]# printf 'aaaa\vbbb\n'
aaaa
bbb
[root@test ~]# printf 'aaaa\\bbb\n'
aaaa\bbb
[root@test ~]#

2.mkdir:创建空目录

语法:mkdir (选项)(参数)

-p:parents如果目录存在则不创建也不报错,若不存在则创建需要的目录

[root@test ~]# ls
scripts
[root@test ~]# mkdir test/xxx/abc -p
[root@test ~]# ls
scripts test
[root@test ~]# tree test
test
`-- xxx
`-- abc 2 directories, 0 files

-v:verbose 详细信息,显示创建过程

[root@test ~]# mkdir -pv abc/bcd/dce/efg
mkdir: created directory `abc'
mkdir: created directory `abc/bcd'
mkdir: created directory `abc/bcd/dce'
mkdir: created directory `abc/bcd/dce/efg'

{}大括号展开

[root@test ~]# mkdir -pv xxx/{a,b,c}/bcd
mkdir: created directory `xxx'
mkdir: created directory `xxx/a'
mkdir: created directory `xxx/a/bcd'
mkdir: created directory `xxx/b'
mkdir: created directory `xxx/b/bcd'
mkdir: created directory `xxx/c'
mkdir: created directory `xxx/c/bcd'
[root@test ~]# tree xxx
xxx
|-- a
| `-- bcd
|-- b
| `-- bcd
`-- c
`-- bcd 6 directories, 0 files
[root@test ~]# mkdir -pv xxx/{a,b}_{b,c}_{d,e}
mkdir: created directory `xxx/a_b_d'
mkdir: created directory `xxx/a_b_e'
mkdir: created directory `xxx/a_c_d'
mkdir: created directory `xxx/a_c_e'
mkdir: created directory `xxx/b_b_d'
mkdir: created directory `xxx/b_b_e'
mkdir: created directory `xxx/b_c_d'
mkdir: created directory `xxx/b_c_e'
[root@test ~]# tree xxx
xxx
|-- a
| `-- bcd
|-- a_b_d
|-- a_b_e
|-- a_c_d
|-- a_c_e
|-- b
| `-- bcd
|-- b_b_d
|-- b_b_e
|-- b_c_d
|-- b_c_e
`-- c
`-- bcd 14 directories, 0 files

-m:指定文件目录的权限,直接指定权限不受umask影响

[qiuhom@test xx]$ ll
total 0
[qiuhom@test xx]$ mkdir test
[qiuhom@test xx]$ ll
total 4
drwxrwxr-x 2 qiuhom qiuhom 4096 Oct 19 15:26 test
[qiuhom@test xx]$ mkdir -m 400 test2
[qiuhom@test xx]$ ll
total 8
drwxrwxr-x 2 qiuhom qiuhom 4096 Oct 19 15:26 test
dr-------- 2 qiuhom qiuhom 4096 Oct 19 15:27 test2 

3.rmdir:删除空目录(remove directory)只允许删除空目录,非空目录删不了

[root@test ~]# tree aaa
aaa 0 directories, 0 files
[root@test ~]# rmdir aaa
[root@test ~]# tree abc
abc
`-- bcd
`-- dce
`-- efg 3 directories, 0 files
[root@test ~]# rmdir abc
rmdir: failed to remove `abc': Directory not empty

4.tree:查看文件系统树,查看目录树

[root@test work]# tree scripts
scripts
|-- auto_bak_log.sh
|-- auto_delete_log.sh
|-- batch_create_user.sh
|-- batch_delete_user.sh
|-- clear
|-- nginx_install.sh
`-- rsync_server_config.sh 0 directories, 7 files
[root@test work]# tree mysql_log/
mysql_log/
`-- mysql.log 0 directories, 1 file

5.touch:创建一个空文件,这个命令的主要作用是改变文件的时间戳(change file timestamps)

语法:touch [OPTION]... FILE...

-c:不创建文件,文件不存在不创建文件,默认不加-c 是文件不存在就创建文件,所有这个命令才有了创建文件的功能。

[root@test xxx]# ls
[root@test xxx]# touch -c abc
[root@test xxx]# ls

默认不加-c就是文件不存在就创建文件

[root@test xxx]# ls
[root@test xxx]# touch abc
[root@test xxx]# ls
abc

提示:创建文件,可以使用文本编辑器来创建

-a:只改变访问时间(access time)

[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:32:34.842999349 +0800
Modify: 2018-10-16 21:32:34.842999349 +0800
Change: 2018-10-16 21:32:34.842999349 +0800
[root@test xxx]# touch -a abc
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:32:34.842999349 +0800
Change: 2018-10-16 21:33:23.714999000 +0800

  提示:改变访问时间,文件的改变时间也会跟着发生改变,因为只要文件发生了改变,change所对应的时间也就会更新

-m:只改变修改时间(modify time)

[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:32:34.842999349 +0800
Change: 2018-10-16 21:33:23.714999000 +0800
[root@test xxx]# touch -m abc
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:37:13.442000125 +0800
Change: 2018-10-16 21:37:13.442000125 +0800

-t:指定时间

[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2018-10-16 21:37:13.442000125 +0800
Change: 2018-10-16 21:37:13.442000125 +0800
[root@test xxx]# touch -m -t 201010101254.33 abc
[root@test xxx]# stat abc
File: `abc'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 140554 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:33:23.714999000 +0800
Modify: 2010-10-10 12:54:33.000000000 +0800
Change: 2018-10-16 21:43:55.968996321 +0800

6.stat:查看文件的详细属性

[root@test ~]# stat scripts
File: `scripts'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 131075 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:17:07.214995505 +0800
Modify: 2018-09-14 10:52:57.264000280 +0800
Change: 2018-10-16 21:17:01.983000675 +0800
[root@test ~]# stat abc
File: `abc'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 140544 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 21:23:40.826000125 +0800
Modify: 2018-10-16 21:19:30.404995317 +0800
Change: 2018-10-16 21:19:30.404995317 +0800

7.rm(remove)删除文件

语法:rm (选项)(参数)

-i:删除已有文件或目录之前先询问用户

[root@test xxx]# ls
abc
[root@test xxx]# rm -i abc
rm: remove regular empty file `abc'? y
[root@test xxx]# ls
[root@test xxx]#

-f:强制删除文件或目录(不询问用户)

[root@test xxx]# ls
bcd
[root@test xxx]# rm -f bcd
[root@test xxx]# ls
[root@test xxx]#

-r:递归处理,将指定目录下的所有文件与子目录一并处理

[root@test ~]# tree test
test
`-- xxx
`-- abc 2 directories, 0 files
[root@test ~]# \rm -r test
[root@test ~]# ls
scripts xxx

  说明:以上实例是因为rm是一个别名,它指向的命令是 rm -i  所有我用反斜线取消别名所指定的命令。

8.cp复制文件或目录

语法:cp(选项)(参数)

-d:只复制链接文件,不复制链接文件所指向的文件。

[root@test ~]# ls
scripts xxx
[root@test ~]# ll /application/
total 1512
drwxrwxr-x 9 root root 4096 Aug 31 17:08 haproxy-1.6.2
-rw-r--r-- 1 root root 1538976 Aug 15 15:53 haproxy-1.6.2.tar.gz
lrwxrwxrwx 1 root root 25 Jul 28 01:10 nginx -> /application/nginx-1.6.3/
drwxr-xr-x 11 root root 4096 Jul 28 01:10 nginx-1.6.3
[root@test ~]# cp -d /application/nginx /root/
[root@test ~]# ls -l /root/
total 8
lrwxrwxrwx 1 root root 25 Oct 16 21:58 nginx -> /application/nginx-1.6.3/
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 21:51 xxx

-f:强制覆盖文件(非交互)

[root@test ~]# ll xxx/
total 16
-rw-r--r-- 1 root root 4534 Oct 16 22:09 123
-rwxr-xr-x 1 root root 4534 Oct 16 22:04 sshd
[root@test ~]# \cp -f scripts/nohup.out xxx/123
[root@test ~]# ll xxx/
total 8
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 4534 Oct 16 22:04 sshd

  提示:\的作用是取消别名

-i:覆盖既有文件之前先询问用户;

[root@test ~]# ll xxx/
total 8
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 4534 Oct 16 22:04 sshd
[root@test ~]# \cp -i xxx/123 xxx/sshd
cp: overwrite `xxx/sshd'? y
[root@test ~]# ll xxx/
total 0
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 0 Oct 16 22:14 sshd

-l:对源文件建立硬连接,而非复制文件

[root@test ~]# ls -l xxx/
total 0
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 1 root root 0 Oct 16 22:14 sshd
[root@test ~]# cp -l xxx/sshd abc
[root@test ~]# ll
total 12
-rwxr-xr-x 2 root root 0 Oct 16 22:14 abc
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 22:06 xxx
[root@test ~]# ll xxx/
total 0
-rw-r--r-- 1 root root 0 Oct 16 22:11 123
-rwxr-xr-x 2 root root 0 Oct 16 22:14 sshd

  提示:我们可以看到sshd 前面硬链接数目增加了1.当然我们也可以用inode方式去看,如果连个文件的inode号一样 那么就说明他们是同一个文件。

[root@test ~]# ll -i xxx/sshd abc
135455 -rwxr-xr-x 2 root root 0 Oct 16 22:14 abc
135455 -rwxr-xr-x 2 root root 0 Oct 16 22:14 xxx/sshd

  说明:以上实例说明cp -l 是对文件创建硬链接,而非复制文件

-R/r:递归处理,将指定目录下的所有文件与子目录一并处理

[root@test xxx]# ls
[root@test xxx]# cp -r /etc/init.d/ /root/xxx/
[root@test xxx]# ls
init.d
[root@test xxx]# tree
.
`-- init.d
|-- DbSecuritySpt
|-- abrt-ccpp
|-- abrt-oops
|-- abrtd
|-- acpid
|-- atd
|-- auditd
|-- blk-availability
|-- cpuspeed
|-- crond
|-- functions ...

-s:对源文件建立符号连接,而非复制文件;

[root@test ~]# ll
total 12
-rwxr-xr-x 1 root root 0 Oct 16 22:14 abc
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 22:31 xxx
[root@test ~]# cp -s nginx_install.sh test
[root@test ~]# ll
total 12
-rwxr-xr-x 1 root root 0 Oct 16 22:14 abc
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
drwxr-xr-x 2 root root 4096 Oct 16 22:31 xxx
[root@test ~]#

-b:覆盖已存在的文件目标前将目标文件备份;

[root@test xxx]# ls
ttt
[root@test xxx]# \cp -b ../abc ttt
[root@test xxx]# ls
ttt ttt~
[root@test xxx]#

-v:详细显示命令执行的操作。

[root@test ~]# cp -v nginx_install.sh ooo
`nginx_install.sh' -> `ooo'

-p:保留源文件的属主,属组 和创建时间等属性

[root@test ~]# ls -l abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
[root@test ~]# cp -p abc ddd
[root@test ~]# ls -l ddd
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd

-a:归档复制,常用于备份参数的效果和同时指定"-dpR"参数相同

[qiuhom@test ~]$ ll
total 39636
-rw-r-S--- 1 root root 20163 Sep 20 18:36 a.txt
-rw-r--r-- 1 root root 4227297 Oct 14 11:19 bin.tar.gz
-rw-r--r-- 1 root root 50566 Oct 14 11:21 etc_rc_init.tar.gz
-rwsr--r-- 1 qiuhom qiuhom 177 Sep 12 10:55 mycron
-rw-r--r-- 1 root root 36277770 Oct 14 11:20 usr_bin.tar.gz
[qiuhom@test ~]$ cp -a bin.tar.gz test
[qiuhom@test ~]$ ll
total 43768
-rw-r-S--- 1 root root 20163 Sep 20 18:36 a.txt
-rw-r--r-- 1 root root 4227297 Oct 14 11:19 bin.tar.gz
-rw-r--r-- 1 root root 50566 Oct 14 11:21 etc_rc_init.tar.gz
-rwsr--r-- 1 qiuhom qiuhom 177 Sep 12 10:55 mycron
-rw-r--r-- 1 qiuhom qiuhom 4227297 Oct 14 11:19 test
-rw-r--r-- 1 root root 36277770 Oct 14 11:20 usr_bin.tar.gz
[qiuhom@test ~]$ stat bin.tar.gz
File: `bin.tar.gz'
Size: 4227297 Blocks: 8264 IO Block: 4096 regular file
Device: 803h/2051d Inode: 135931 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-10-16 23:47:19.533000125 +0800
Modify: 2018-10-14 11:19:50.026000238 +0800
Change: 2018-10-14 11:19:50.026000238 +0800
[qiuhom@test ~]$ stat test
File: `test'
Size: 4227297 Blocks: 8264 IO Block: 4096 regular file
Device: 803h/2051d Inode: 140564 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ qiuhom) Gid: ( 500/ qiuhom)
Access: 2018-10-14 11:30:35.254999044 +0800
Modify: 2018-10-14 11:19:50.026000238 +0800
Change: 2018-10-16 23:47:19.536000125 +0800

  提示:因为执行cp命令 会访问源文件,所有属性里的访问时间会发生变化,而目标文件的访问时间和修改是件和源文件被访问前的时间一样。应为生成新的文件,所以目标文件的改变是见和源文件的访问时间一样,两者是同时发生的。

9.mv(move)移动文件

语法:mv(选项)(参数)

mv SRC DEST
mv -t DEST SRC

移动单个文件到指定文目录

[root@test ~]# ls
aaa abc ddd jjj nginx_install.sh ooo scripts test xxx
[root@test ~]# mv abc xxx
[root@test ~]# ls
aaa ddd jjj nginx_install.sh ooo scripts test xxx
[root@test ~]# ls xxx
abc ttt ttt~

移动多个文件到指定目录下

[root@test ~]# ll
total 20
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rwxr-xr-x 1 root root 0 Oct 16 22:39 jjj
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
-rw-r--r-- 1 root root 693 Oct 16 22:35 ooo
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
drwxr-xr-x 2 root root 4096 Oct 16 22:42 xxx
[root@test ~]# mv ddd jjj nginx_install.sh test ooo xxx
[root@test ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
drwxr-xr-x 2 root root 4096 Oct 16 22:44 xxx
[root@test ~]# ll xxx
total 8
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rwxr-xr-x 1 root root 0 Oct 16 22:39 jjj
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
-rw-r--r-- 1 root root 693 Oct 16 22:35 ooo
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rwxr-xr-x 1 root root 0 Oct 16 22:34 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~ 

当目标文件是文件是会覆盖其目标文件

[root@test xxx]# ll
total 8
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rwxr-xr-x 1 root root 0 Oct 16 22:39 jjj
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rw-r--r-- 1 root root 693 Oct 16 22:35 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~
[root@test xxx]# mv jjj ttt
mv: overwrite `ttt'? y
[root@test xxx]# ll
total 4
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~

  提示:可以看到ttt文件的大小发生了改变,说明ttt原有的数据被jjj给覆盖了

当源文件是多个文件时,目标文件必须是目录

[root@test xxx]# ll
total 4
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
-rw-r--r-- 2 root root 693 Jul 28 01:16 nginx_install.sh
lrwxrwxrwx 1 root root 16 Oct 16 22:31 test -> nginx_install.sh
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
-rwxr-xr-x 1 root root 0 Oct 16 22:33 ttt~
[root@test xxx]# mv abc ddd ttt
mv: target `ttt' is not a directory
[root@test xxx]# mv abc ddd ttt ..
[root@test xxx]# ls
nginx_install.sh test ttt~
[root@test xxx]#

-t:指定目标目录(这里必须是目录,文件不行)

[root@test xxx]# ls
nginx_install.sh test ttt~
[root@test xxx]# mv -t /tmp test nginx_install.sh ttt~
[root@test xxx]# ll
total 0
[root@test xxx]# ls /tmp
Gtcpe gates.lod nginx_install.sh test_dir yum_save_tx-2018-10-13-19-486q4O6n.yumtx
conf.n moni.lod test ttt~

在同目录下,可以更改文件名

[root@test ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 ddd
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
[root@test ~]# mv ddd abc
[root@test ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx

10.install :复制文件和设置属性

-d:创建目录

[root@test ~]# ls
aaa abc scripts ttt xxx
[root@test ~]# install -d bbb/cccc/ddd
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
[root@test ~]# tree bbb
bbb
`-- cccc
`-- ddd 2 directories, 0 files

  提示:这个创建目录和mkdir -p类似

-m:指定权限,默认是rwxr_xr_x权限(755)

[root@test ~]# install -m 644 abc jjj
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx

-t:指定目标目录

[root@test ~]# ll xxx
total 0
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 22:50 xxx
[root@test ~]# install -t xxx ttt abc jjj
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 23:06 xxx
[root@test ~]# ll xxx
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt

  提示:目标必须是目录 ,不能是文件

-g:指定目标文件的属组

[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 23:06 xxx
[root@test ~]# install -g qiuhom jjj ccc
[root@test ~]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 16 22:36 aaa
-rwxr-xr-x 1 mysql qiuhom 0 Oct 16 22:14 abc
drwxr-xr-x 3 root root 4096 Oct 16 22:59 bbb
-rwxr-xr-x 1 root qiuhom 0 Oct 16 23:10 ccc
-rw-r--r-- 1 root root 0 Oct 16 23:03 jjj
drwxr-xr-x 3 root root 4096 Sep 14 10:52 scripts
-rwxr-xr-x 1 root root 0 Oct 16 22:39 ttt
drwxr-xr-x 2 root root 4096 Oct 16 23:06 xxx

  提示:复制前指定ccc 为qiuhom组的权限

-o:指定目标属主

[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
[root@test xxx]# install -o qiuhom abc ddd
[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 qiuhom root 0 Oct 16 23:13 ddd
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt

  提示:指定目标文件ddd的属主为qiuhom

-v:输出命令执行过程

[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 qiuhom root 0 Oct 16 23:13 ddd
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt
[root@test xxx]# install -vm 400 ddd fff
`ddd' -> `fff'
[root@test xxx]# ll
total 0
-rwxr-xr-x 1 root root 0 Oct 16 23:06 abc
-rwxr-xr-x 1 qiuhom root 0 Oct 16 23:13 ddd
-r-------- 1 root root 0 Oct 16 23:16 fff
-rwxr-xr-x 1 root root 0 Oct 16 23:06 jjj
-rwxr-xr-x 1 root root 0 Oct 16 23:06 ttt

Linux命令实战(二)的更多相关文章

  1. Linux命令-文本编辑(二)

    Linux命令-文本编辑(二) Linux mtype命令 mtype为mtools工具指令,模拟MS-DOS的type指令,可显示MS-DOS文件的内容. 语法: mtype [-st][文件] 参 ...

  2. Linux命令-文件管理(二)

    Linux命令-文件管理(二) Linux gitview命令 Linux gitview命令用于观看文件的内容,它会同时显示十六进制和ASCII格式的字码. 语法:gitview [-bchilv] ...

  3. Linux命令(二)——目录和文件管理命令

    一.Linux系统的目录结构 1.根目录(/):顶层目录,某些系统中的唯一分区. 2./bin命令文件目录:包含Linux命令的二进制可执行文件. 3./boot目录:存放系统的内核文件和引导装载程序 ...

  4. Linux 命令(二)

    man help:线上查询及帮助命令 命令  --help:简单帮助 help  cd:查看一些Linux命令行的一些内置命令 文件和目操作命令(19个) ls  cd  cp  find  mkdi ...

  5. Java开发人员必须掌握的Linux命令(二)

    子曰:"工欲善其事,必先利其器." 学习应该是快乐的,在这个乐园中我努力让自己能用简洁易懂(搞笑有趣)的表达来讲解让知识或者技术,让学习之旅充满乐趣,这就是写博文的初心. 本篇的旅 ...

  6. 【Linux】好玩的Linux命令(二)

    关于Linux talk:http://man.linuxde.net/talk 下面文章转自:http://www.oschina.net/translate/11-lesser-known-use ...

  7. Linux命令实战(一)

    1.pwd(printing working directory)打印当前工作目录路径 [root@test sysconfig]# pwd /etc/sysconfig 2.ls(list)列出当前 ...

  8. Linux学习Day3:新手必须掌握的Linux命令(二)

    今天学习的命令都是运维工作中经常要用到的,非常实用,必须要用心学习,争取把这些命令烂熟于心,具体内容如下: 一.系统状态监测命令 1.ifconfig命令 用于获取网卡配置与网络状态等信息. [roo ...

  9. 软件测试人员需要掌握的linux命令(二)

    2 设备管理 2.1 mount 名称 : mount 使用权限 : 系统管理者或/etc/fstab中允许的使用者 使用方式 : mount [-hV] mount [-fnrsvw] [-t vf ...

随机推荐

  1. python 中的一点新知识

    逻辑行与物理行 所谓物理行(Physical Line)是你在编写程序时 你所看到 的内容.所谓逻辑行(Logical Line)是 Python 所看到 的单个语句.Python 会假定每一 物理行 ...

  2. Spring Boot WebFlux 集成 Mongodb 数据源操作

    WebFlux 整合 Mongodb 前言 上一讲用 Map 数据结构内存式存储了数据.这样数据就不会持久化,本文我们用 MongoDB 来实现 WebFlux 对数据源的操作. 什么是 MongoD ...

  3. API---文件操作

    CreateFile() 介绍: 功能:打开或创建以下对象,并返回可访问的句柄: 控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道. 函数原型:HANDLE CreateFile ( ...

  4. Oracle11g安装与基本使用

    目录 安装 修改用户密码 配置文件修改 使用PLSQL连接Oracle数据库 如何执行SQL 语句 本教程基于oracle11g和PLSQL进行 下载资源见百度网盘链接:https://pan.bai ...

  5. iOS开发请您把握现在 — 面向未来学习

    iOS开发请您把握现在 — 面向未来学习 这一篇文章,如果你是一名iOS开发正好也处于开发晋升瓶颈迷茫期,不妨停下你的脚步,花五分钟看看,兴许有你需要的!文章结尾有彩蛋 群里常见的唱哀 iOS现在到底 ...

  6. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

    配置spring+shiro时,启动tomcat报错异常 严重: Context initialization failedorg.springframework.beans.factory.Bean ...

  7. 实用Linux控制台命令

    实用Linux控制台命令 screen 例如用Xshell连接 服务器 screen -ls 列出当前用户所有的screen screen 回车直接创建新的screen screen -S scree ...

  8. python wraps的作用

    1.__name__用来显示函数的名称,__doc__用来显示文档字符串也就是("""文档字符串""")这里面的内容 2.首先我们来看不加@ ...

  9. VS Code断点调试PHP超详细萌新教程

    AppServ安装 1. 下载 2. 安装,一路默认设置顺便设置sql密码即可.这里建议不要修改端口,后续教程默认80端口. 3.点我测试,有下图则恭喜你AppServ安装完成. Xdebug配置 1 ...

  10. Https 与 iOS 信息安全

    转载自:swift-cafe 什么是 Https 咱们从最直观的说起. 我们平时在用电脑访问网页的时候,有时候会在地址栏的左边多出一个小锁的图标,就像这样: 这是大多数主流浏览器的一个通用做法,当我们 ...