Linuxdate usage tips #! /Bin/bashecho-e & quot; iwillusetouchcommandtocreate3files & quot; read-p & quot; inputfilename: & quot; fileuserfilename $ {fileuser:-& quot; f Linux date usage tips #! /Bin/bashecho-e "I will use touch command to create 3 files" read-p "input filename:" fileuserfilename =$ {fileuser: -"filename"} date1 = $ (date -- date = '2 days ago '+ % Y % m % d) date2 = $ (date -- date = '1 days ago '+ % Y % m % d) date3 = $ (date + % Y % m % d) file1 =$ {filename }$ {date1} file2 =2 {filename }$ {date2} file3 =3 {filename }$ {date3} touch "$ file1" touch "$ file2" the shell script above touch "$ file3" ls was used two days ago, one day ago, we joined the current date and the name entered by the user to create three files. . Filename =$ {fileuser:-"filename"} is used to determine whether the fileuser variable is null. if it is null, use filename instead. Date -- date = '2 days ago '+ % Y % m % d indicates that the date displayed two days ago is January 1, 20130908. if you want to represent the date of today, in this way, date = $ (date + % Y % m % d). If you want the expression, you can use % F, that is, date2 = $ (date -- date = '1 days ago '+ % F). This % F is equal to % Y-% m-% d, this is also acceptable, but it is too cumbersome. 1 days ago can also be changed to 1 months ago or 1 yeas ago. it must be noted that the later ++ must not be omitted.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.