Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to create 360 empty directories that each one of them has a date of the year\
e.g. 1st directory's title: 010103
2nd directory's title: 010203
etc
#!/bin/bash
YEAR_START=3
YEAR_END=32
for YR in $(seq $YEAR_START $YEAR_END); do
if [ $YR -lt 10 ]; then
for MONTH in $(seq 1 12); do
if [ $MONTH -lt 10 ]; then
mkdir 010"$MONTH"0"$YR"
else
mkdir 01"$MONTH"0"$YR"
fi
done
else
for MONTH in $(seq 1 12); do
if [ $MONTH -lt 10 ]; then
mkdir 010"$MONTH""$YR"
else
mkdir 01"$MONTH""$YR"
fi
done
fi
done
edit: I've done a bit of reading, and you can tweak the for loops so you end up with this instead:
Code:
#!/bin/bash
YEAR_START=3
YEAR_END=32
for YR in $(seq $YEAR_START $YEAR_END); do
if [ $YR -lt 10 ]; then
for MONTH in {1..12}; do
if [ $MONTH -lt 10 ]; then
mkdir 010"$MONTH"0"$YR"
else
mkdir 01"$MONTH"0"$YR"
fi
done
else
for MONTH in {1..12}; do
if [ $MONTH -lt 10 ]; then
mkdir 010"$MONTH""$YR"
else
mkdir 01"$MONTH""$YR"
fi
done
fi
done
Obviously, if you are going to increment the date, you will need something more elaborate inside the loop. I'm looking for the commands that would--eg--increment the date by 1 day.
EDIT: I type slowly....
I'm thinking there has to be a way to increment date by days, weeks, or months--I'll post if I find it.
Why 360? Is this supposed to be one directory for each day (there are 366 possible dates)? Should this be MMDDYY or DDMMYY? Do you want to have it follow the months such that months w/ 31 get 013103 (or 310103) and February 022803 (or 280203), etc. or do you simply want 360 directories with 010103 through 046003?
Do me a favor and run the command "ls *03 |wc -l" in the directory that you made all these directories in and let me know what the output is. I'm still not getting what it is you are trying to do.
I suspected there was something like this, but I could not find it in the man pages, "info date", ABS, or Google.
In particular, where do you find docs on the ability to do " + $n days"?
It's a good question. I have known this for a while, and I think I must have read it in a manual page at some point. It's something I have noticed - that the manual pages which ship with many distros seem to be somehow not very complete. In the case of Ubuntu, infotex is also absent, so I often see things like "full documentation is found in the info page", and then I can't view it.
For some reason I have never really liked info pages - I always preferred man pages. Maybe it's that they're all split up into sub-pages I prefer one long document. However, there is a lot of good information in there if you can work out how to navigate through it.
By the way, you can use konqueror as an info browser. Just go type info:/ in the location bar.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.