Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create a date directory using shell

Shulou Source: shulou.com Published: 2022-06-03 12:52:01 10月01日 Update

This article mainly introduces how to use shell to create a date catalog, which is very detailed and has a certain reference value. Friends who are interested must read it!

You need to create a subdirectory (named after the year) in multiple directories (such as beijing shanghai tianjin guangzhou, etc.), then go to the subdirectory, create a new directory, and name it after the date of the current day.

The end result is as follows:

The code is as follows:

China/guangdong/china/guangdong/shenzhen/2010/1206china/guangdong/shenzhen/2010/1207china/guangdong/shenzhen/baoan/2010/1206china/guangdong/shenzhen/baoan/2010/1207china/guangdong/shenzhen/baoan/guangming/2010/1206china/guangdong/shenzhen/baoan/guangming/2010/1207

My realization:

#! / bin/bash read-p "PLEASE input country:" cou read-p "PLEASE input city:" city read-p "PLEASE input name:" name#echo "$cou,$city,$name" date=$ (date +% Y) # echo $date date2=$ (date +% m% d) # echo $date2 if [- d ". / $cou/$city/$name/$date/$date2"] Then echo "the dir is exit" else mkdir-p. / $cou/$city/$name/$date/$date2 fi

Effect:

[root@localhost hbshell] # test.sh

PLEASE input country:china

PLEASE input city:hangzhou

PLEASE input name:hb

# [root@localhost hbshell] # ll china/hangzhou/hb/2011/0321/

Total 0

The above is all the contents of the article "how to create a date Catalog using shell". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Catalog date content subdirectory subdirectory effects article code value interest multiple boy partner year more knowledge industry information information channel channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Shulou Information Apple Linux