Dolphin service menu help: preserve file timestamp
Dotan Cohen
dotancohen at gmail.com
Fri Dec 24 17:49:07 GMT 2010
On Sat, Dec 18, 2010 at 01:48, Alex Schuster <wonko at wonkology.org> wrote:
> Dotan Cohen writes:
>
>> On Fri, Dec 17, 2010 at 20:30, Alex Schuster <wonko at wonkology.org> wrote:
>>> Yes. Something like this (untested):
>>>
>>> #!/bin/bash
>>>
>>> while (( $# ))
>>> do
>>> date=$( ls -l --full-time "$1" |
>>> awk '{ print $6" "$7 }' |
>>> sed 's/.00000*//g' )
>>> iconv -f CP1255 -t UTF-8 "$1" > "$1-utf8"
>>> touch -d "$date" "$1-utf8"
>>> shift
>>> done
>>
>> Thanks. I have some googling to do, but I'll ask anyway:
>>
>>
>>> while (( $# ))
>> Does this mean to go through each CLI argument, something like foreach?
>
> Right. $# is the number of command line arguments, and (( x )) is true
> when $x is != 0. Alternatively, you could as well do it like this:
>
> for file in "$@"
> do
> # and use "$file" instead of "$1" (the first argument)
> done
>
>> What does the "shift" line do?
>
> It discards the first argument, and rotates the others. $2 becomes $1,
> $3 becomes $2, and so on.
>
>>> date=$( ls -l --full-time "$1" |
>>> awk '{ print $6" "$7 }' |
>>> sed 's/.00000*//g' )
>> This is pure genius, I was wondering exactly how difficult it would be
>> to get this info into a variable in the format that touch would use.
>
> This looks more complicated than it is. ls -l --full-time gives the full
> time of the file, and awk then outputs columns 6 and 7, which give date
> and time. The time also has the fraction of seconds, which the touch
> command will not understand, so we need the sed statement which replaces
> the dot and a sequence of zeroes with an empty string. Actually, I made
> a mistake, the dot needs to be escaped with a backslash, as a simlpe dot
> matches every character, similar to a questionmark in file specifications.
>
>>> If you want to replace the files, you could proabaly use recode, which keeps
>>> the time unless told otherwise:
>>> Exec=recode CP1255..utf8 %f
>>
>> Actually, this is _exactly_ what I need. Thanks!
>
> I thought so, but then I had already written the code :)
>
> Glad I could help,
>
> Wonko
Thanks. It took me some time to get to it, but the explanation was very helpful.
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
___________________________________________________
This message is from the kde mailing list.
Account management: https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.
More information about the kde
mailing list