DSC_9274.JPG will be renamed to 2014-10-26_16-23-32__DSC_9274.JPG
jhead is required Show Sample Output
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
for i in `ls`; do
This is a bad habit you want to get out of. If your filenames contain whitespace the script won't work. Here, this will work fine:for i in *; do
My improved for loop variable might contain whitespace, so I need to quote them "$i" Next, it's better to use $(command) rather than `command` The $(...) form can be nested. It doesn't matter here, but it's often useful. Then we have your substitutions. That's a very nice use of the shell, but "tr" is perfect:... | tr ': ' '-_'
That's quote, colon, space, quote, space, quote, dash, underscore, quote "tr" replaces all colons with dashes and then all spaces with underscores. That saves a lot of typing. My final worry is that my camera can take several pictures in one second. If you have multiple pictures taken in the same second, the last one will overwrite the others. My tidied command looks like this:for i in *; do date=$(identify -format %[exif:DateTime] "$i" | tr ': ' '-_'); mv $i ${date}__$i; done