Linux command to create a date folder or file instance code


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
MKDIR date +% Y -% m -% d generate folder format yyyy MM DD
[[email protected] data]$ mkdir date +%Y%m%d
[[email protected] data]$ ls
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

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

Example 2:

Designated date folder cqs-2019-07-24

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

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


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

Recommended Today

Choose react or angular 2

Original addressChoosing between React vs. Angular 2The following is the translation of this article, which can be used at your choiceReactperhapsAngular2We need to help when we need to. React has become a cool representative in 2015, but angular.js has changed from a front-end framework that people love to a terrible devil (and not so terrible…) […]