博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux基础命令: mkdir和touch
阅读量:4349 次
发布时间:2019-06-07

本文共 4625 字,大约阅读时间需要 15 分钟。

一、mkdir(创建目录)

mkdir,该命令创建指定的目录名,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录.

在命令行内输入mkdir --help查看帮助信息.

[test@VM_0_15_centos ~]$ mkdir  --help Usage: mkdir [OPTION]... DIRECTORY...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 exitGNU coreutils online help: 
For complete documentation, run: info coreutils 'mkdir invocation'

选项介绍:

    -m: 对新建目录设置存取权限,也可以用chmod命令设置;

    -p: 可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录;

    -v:表示打印每一个创建的目录的信息。

    -z:从语义来看,是为每个ctx创建目录时设置SELinux级安全上下文。

    -help,-version一个是显示帮助信息,一个是显示版本号

[test@VM_0_15_centos ~]$ mkdir  mysql [test@VM_0_15_centos ~]$ lschmod  help  hosts  linux  maillog  mysql  passwd  python

-p参数,可以创建多级目录

[test@VM_0_15_centos ~]$ mkdir qq/ww/ee/ssmkdir: cannot create directory ‘qq/ww/ee/ss’: No such file or directory[test@VM_0_15_centos ~]$ mkdir -p qq/ww/ee/ss[test@VM_0_15_centos ~]$ ll  -d qq/ww/ee/ss/drwxrwxr-x 2 test test 4096 Aug 18 21:50 qq/ww/ee/ss/

-m 是管理权限的,-v 是显示创建信息的。

[test@VM_0_15_centos ~]$ mkdir  -v  dirmkdir: created directory ‘dir’[test@VM_0_15_centos ~]$ rm  -fr  dir/[test@VM_0_15_centos ~]$ mkdir  -m 700  dir[test@VM_0_15_centos ~]$ ll  dir/total 0[test@VM_0_15_centos ~]$ lltotal 100-rwxr-xr-x 1 test test 58544 Aug 18 18:40 chmoddrwx------ 2 test test  4096 Aug 18 21:54 dir

二、touch(创建目录)

touch命令主要用来修改文件时间戳,或者新建一个不存在的文件

[test@VM_0_15_centos ~]$ touch  --help Usage: touch [OPTION]... FILE...Update the access and modification times of each FILE to the current time.A FILE argument that does not exist is created empty, unless -c or -his supplied.A FILE argument string of - is handled specially and causes touch tochange the times of the file associated with standard output.Mandatory arguments to long options are mandatory for short options too.  -a                     change only the access time  -c, --no-create        do not create any files  -d, --date=STRING      parse STRING and use it instead of current time  -f                     (ignored)  -h, --no-dereference   affect each symbolic link instead of any referenced                         file (useful only on systems that can change the                         timestamps of a symlink)  -m                     change only the modification time  -r, --reference=FILE   use this file's times instead of current time  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time      --time=WORD        change the specified time:                           WORD is access, atime, or use: equivalent to -a                           WORD is modify or mtime: equivalent to -m      --help     display this help and exit      --version  output version information and exitNote that the -d and -t options accept different time-date formats.
-a 改变档案的读取时间记录。  -m 改变档案的修改时间记录。  -c 假如目的档案不存在,不会建立新的档案。与 --no-create 的效果一样。   -h ,不干扰引用 影响每个符号链接,而不是所有参考文件(只适用于系统的改变一个符号,时间戳)  -f 不会执行实际操作,是为了与其他 unix 系统的相容性而保留。  -r 使用参考档的时间记录,与 --file 的效果一样。  -d 设定时间与日期,可以使用各种不同的格式。  -t 设定档案的时间记录,格式与 date 指令相同。[[CC]YY]MMDDhhmm[.SS],CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则linux中touch命令参数将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时间.由于系统的限制,早于1970年1月1日的时间是错误的.  --no-create 不会建立新档案。  --help 列出帮助信息   --version 列出版本信息

创建一个文件

[test@VM_0_15_centos ~]$ touch  test.txt[test@VM_0_15_centos ~]$ ll  test.txt -rw-rw-r-- 1 test test 0 Aug 18 22:02 test.txt

 -m参数更改文件时间

[test@VM_0_15_centos ~]$ touch   -m  test.txt [test@VM_0_15_centos ~]$ ll  test.txt -rw-rw-r-- 1 test test 0 Aug 18 22:04 test.txt

-t参数指定时间创建文件

[test@VM_0_15_centos ~]$ touch   -t  201907102312.33  test.txt [test@VM_0_15_centos ~]$ ll  test.txt -rw-rw-r-- 1 test test 0 Jul 10 23:12 test.txt

-r参数

#将 file 的时间记录改变成与 referencefile 一样。touch -r referencefile file
[test@VM_0_15_centos ~]$ touch -r  b.txt  test.txt [test@VM_0_15_centos ~]$ ll  b.txt   test.txt -rw-rw-r-- 1 test test 0 Aug 18 22:12 b.txt-rw-rw-r-- 1 test test 0 Aug 18 22:12 test.txt

 

转载于:https://www.cnblogs.com/wzy23/p/11373833.html

你可能感兴趣的文章