1

When I backup my files I want to create a Year, Month & Date folder to place the files into. I am just learning coding for linux so I apologies. This is what I have currently:

#!/bin/ash
chmod +x FTP.sh
DATE=`date +%Y-%m-%d`
PATH=/opt/bin:/opt/sbin:$PATH
SOURCE=/volume1/DOCS/documents/C59/tiffs
MKDIR=/documents/C59/$(date)

I am using a Synology NAS. I added the Date code but its giving me the following folder path:

/documents/C59/Tue/tiffs

user3797758
  • 829
  • 1
  • 14
  • 28
Chad78
  • 11
  • 2
  • Hello. Maybe you can use the **date** command to extract the time information and create a folder (dd_mm_yy). `mkdir $(date +"%D" | sed "s/\//_/g")` – klyone Sep 27 '16 at 16:11
  • Possible duplicate of [YYYY-MM-DD format date in shell script](http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script) – sashoalm Sep 27 '16 at 16:14
  • Sorry @sashoalm that didn't answer my question. I am getting Tue to appear in my folder path not Year/Month/Day – Chad78 Sep 27 '16 at 20:35

1 Answers1

0

In the bash script, use:

DATE=`date +%Y-%m-%d`

To create a folder, you can use:

mkdir yourFolderName

PS: search before asking a question, this has been answered many times already ;)

YYYY-MM-DD format date in shell script

Community
  • 1
  • 1
Julien
  • 3,613
  • 2
  • 23
  • 25
  • Thank you very much. Where would I place that though within the code. Sorry im very noobish with this. I am trying to learn :) thanks again. – Chad78 Sep 27 '16 at 16:14
  • Ok so when I place this code into my file this is what I get: documents/C59/Tue/tiffs – Chad78 Sep 27 '16 at 20:20