ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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'm writing a script that takes the date attribute of a file when it was created and appending it to the name. I'm pretty close to what I need, but the date appears in yyyy-mm-dd format and I want it to read mm-dd-yyyy. What I have done so far is something like
for ((i=1;i<=50;i++));
do fdate=`stat -c %y Video\ Snapshot\ $i.png|awk {'print$1'}`;
newname=Personname-$fdate-$i.png;
mv Video\ Snapshot\ $i.png $newname;
done
This works decently (I know it's not pretty - if someone has a better idea I'm all open!) but the date comes out in the yyyy-mm-dd format. How do I change it?
for ((i=1;i<=50;i++));
do fdate=`date --date=@$( stat -c%Y Video\ Snapshot\ $i.png|awk {'print$1'} )`;
newname=Personname-$fdate-$i.png;
mv Video\ Snapshot\ $i.png $newname;
done
Thanks for the code. The new file name has today's date appended to it not the day the file was created. This is close but still not what I'm aiming for.
Let me back up, maybe there's an easier way of doing this.
I take snapshots of my family members when I talk to them on Skype (I live overseas and my sister's kids are still young) and they get called "Video Snapshot x.png". I manually go through and use a for loop to change the date and rename the files.
For example;
for ((i=1;i<=49;i++));do mv Video\ Snapshot $i.png Family-7-19-2010-$i.png; done
then for the next day's pics
x=0; for ((i=50;i<=76;i++));do let x=x+1;mv Video\ Snapshot $i.png Family-7-23-2010-$x.png; done
What I'd like is a script that reads the date attribute and changes the filenames so they say something like Family-pics-mm-dd-yyyy-<number>.png without my manually going through the directory and figuring which numbers correspond to which dates. It's not a pain to do it manually but I thought it would be a good way to practice programming.
It is impossible to get the date of creation. That information is not stored by any kernel or file system. (You could potentially pull a hack by reading the EXIF data of your images..)
You used %y yourself which is date of last modification.
man stat:
Code:
%y Time of last modification
%Y Time of last modification as seconds since Epoch
Last edited by AlucardZero; 07-23-2010 at 07:43 AM.
It is impossible to get the date of creation. That information is not stored by any kernel or file system. (You could potentially pull a hack by reading the EXIF data of your images..)
You used %y yourself which is date of last modification.
man stat:
Code:
%y Time of last modification
%Y Time of last modification as seconds since Epoch
Sorry, I meant to say that the date they're modified is their date of creation. Now are there any other hairs to split here......
Incidentally, the question of how to swap the date goes unanswered. Any clues?
I take snapshots of my family members when I talk to them on Skype (I live overseas and my sister's kids are still young) and they get called "Video Snapshot x.png". I manually go through and use a for loop to change the date and rename the files.
I'm trying to find out how to make Skype take a snapshot in Linux.
No problems in the darkside, but can't find that option in Linux.
Using skype_static-2.1.0.81 with 32-bit Slackware.
Edit: noticed after a further read that the op must be taking snapshots in Windoze
Last edited by Bruce Hill; 08-29-2010 at 07:19 PM.
Yeah, I'm using Windows. Skype in Linux is just beta and the Windows version just runs a lot better. The other thing is that my wireless connection conks out on me in Linux, too. Never does that in Windows.
I hate to say it, but virtually all of my desktop functions in Linux are "beta", it's almost like desktop Linux is beta itself. I hate saying that, I really do, but I have all types of minor annoyances CONSTANTLY in desktop Linux that I haven't dealt with since Win98.
If I have one more video driver problem I might just ditch desktop Linux altogether. It's 2010 and I STILL deal with video driver problems in Linux! Dare I say it? Windows is more stable than ..... No, I just can't bring myself to say it, but these little ankle biter problems in desktop Linux are really getting to me (no problems with it as a server platform, not one).
Thanks for your reply ... only fanbois don't accept obvious reality.
Having to boot into Windoze to use Adobe InDesign and Photoshop
give me a great new appreciation and desire to get back into Linux.
I fully understand. At least Windows 7 has a better DE than the past ones;
and is a better OS all around than previous Mickey$oft offerings.
Skype, and QQ, beta for Linux are horrible, and haven't been updated in ions.
Can't blame them, as they must pay programmers to code for that. This shows
that the real hackers in *nix aren't playing games and doing a lot of desktop
stuff ... just look how horrible KDE is, and all the K* apps. It's not quite
achieved Win98 stability, but they keep adding graphic failure eye candy.
The pic with Linus is classic; not just because it looks like he's thumbs-upping Win7 but I've never seen him smile that big before!!
There are things I hate about Windows, too, of course (if my OS tells me one more damn time I can't disconnect my drive because it's being used when it's not....), but overall it just works better in my experience.
On the same computer, my Ubuntu partitions requires that I re-set my video resolution about 1 in 4 boots. I don't think I've ever had to do that on my Windows partition. And it pisses me off to no end to upgrade and suddenly programs stop working! Because the new version of Ubuntu uses lib-qmid.vtrx.1.03.0875 instead of lib-qmid.vtrx.1.03.873 suddenly a screen saver or other utility I love won't work. That's lame! WTF!!!
Don't get me wrong, I still love using Linux when it works. But I must say I spend more time configuring and tweaking Linux, whereas I spend more time actually using my computer more in Windows. It's refreshing how much work you get done when you don't have to chase down library files, old .deb files because apt-get repositories have been "updated" to remove your old, working programs, etc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.