Linux command to create a date folder or file instance code

Time:2020-10-24

Touch command: to create a file MKDIR command: to create a folder date command: get system time about date get system time option

  • %Y: Year
  • %m: Month
  • %d: Japan
  • %H: Hours
  • %M: Minutes
  • %S: Second

Example 1:

create folder

MKDIR date +% Y% m% d generate folder format yyyymmdd
[[email protected] data]$ mkdir date +%Y%m%d
[[email protected] data]$ ls
20190724 
MKDIR date +% Y -% m -% d generate folder format yyyy MM DD
[[email protected] data]$ mkdir date +%Y%m%d
[[email protected] data]$ ls
2019-07-24 
MKDIR date +% Y% m% d% H% m% s generate folder format yyyymmddhhmmss
[[email protected] data]$ mkdir date +%Y%m%d%H%M%s
[[email protected] data]$ ls
2019072413071563946550

create a file

Touch date +% Y% m% d file format: yyyymmdd
Touch date +% Y -% m -% d file format: yyyy MM DD

If the creation date format is yyyy MM DD, you can use% F to simplify it


mkdir date +%F
[[email protected] data]$ mkdir date +%F
[[email protected] data]$ ls
2019-07-24

Example 2:

Designated date folder cqs-2019-07-24


[[email protected] data]$ mkdir cqs-date +%F
[[email protected] data]$ ls
cqs-2019-07-24 

Note: back quotation mark is used for date, and space is used between date and + sign

summary

The above is a small series of Linux commands to create a date folder or file instance code, I hope to help you!