*
  Мысли   Галерея   Проекты   Тексты  
  Мысли   Галерея   Проекты   Тексты  
Giver: Веселые переименования  (2008-05-30 13:07:03)

Задача стояла — переименовать все файлы из .. c суффиксом jpg в файлы вида 00001.jpg и так далее. Делается это одной строчкой на баш:

C=0;for a in ../*.jpg;do C=$(printf "%04d" $(($C+1))); mv "$a" $C.jpg;done

Ничего особо сложного нет, просто заводим счетчик и понемного инкрементируем его. Функция printf занимается дополнением нулей. Иногда еще возникает задача просто сменить у файлов суффикс, или просто какую-нибудь простую замену, можно воспользоваться такой коммандой:

for a in *;do mv "$a" "`echo $a | sed -e 's/dat/avi/'`";done

Ну и последнее, есть множество файлов, которые нужно разложить по каталогам по определенному принципу, ну скажем по первой букве:

for a in *;do C=`echo $a | cut -c 1 `;[ -d $C ] || mkdir $C;mv "$a" $C/;done

Бывает удобно разложить файлы по дате создания, особенно если это фотографии с разных событий, которые хранятся в одном каталоге, тогда выходит нечто следущее:

for a in *;do C=`date -r "$a" +%y.%m.%d`;[ -d $C ] || mkdir $C;mv "$a" $C/;done

Фантазировать на эту тему можно безконечно. Но особенно приятно, когда shell избавляет от скучной ручной работы лишь одной строкой.


dobson от 2020-10-08 17:47:29:
9txQv4 http://pills2sale.com/ cheap viagra
Laurence от 2020-10-11 22:51:38:
Looking for a job generic drug for cialis Since January, state political leaders and economists have warned income tax revenues could swell in the second quarter and that the strength would likely not persist. The quarter encompasses April, when federal and most state taxes are filed.
Megan от 2020-10-11 22:51:39:
I never went to university motilium price philippines Dr. James Spencer, a dermatologist in St. Petersburg, Fla., and a board member for the American Academy of Dermatology, says that for those who are very sun sensitive, a white cotton T-shirt will likely not provide enough protection. Instead, Spencer recommends finding a shirt in a tighter weave or washing clothes with a sun protection rinse such as SunGuard wash, which claims to make clothes have a UPF of 30.
Mariah от 2020-10-11 22:51:40:
It's funny goodluck comprar generico do viagra em portugal * Telus Corp announced on Monday a new "Clear andSimple" pricing plan based on two-year, rather than three-year,contracts. The plan allows customers to pick a device and dataplans, and share it among multiple users with different devices.()
Ashton от 2020-10-11 22:51:40:
I love this site telmisartan and hydrochlorothiazide uses in telugu The melting pot of cultures and nationalities in the city certainly helps, he says, as the different communities are open to learning from one another. When it comes to training household staff, of any nationality, the British style is particularly valued.
Isiah от 2020-10-11 22:51:41:
The line's engaged muscle strength beanie babies He added that there are “very real risks in bringing a prosecution in which the prosecution would have to set out, effectively for the first time and to the criminal standard, the approach that should be taken by doctors before authorising an abortion”.
Nilson от 2020-10-11 22:52:28:
Through friends tacrolimus 1mg price House prices fell 16.3 percent in London after the financialcrash and by 16.6 percent across England and Wales, according toLand Registry data. While London prices have recovered to 6percent above their pre-crash peak, in the rest of the countrythey are still 10 percent below.
Elwood от 2020-10-11 22:52:28:
I'm retired betamethasone valerate cream i.p The case is still open, but according to a New York Times report on Thursday, JPMorgan is close to a deal with the SEC and British regulators, which is expected to be announced in the fall. The fate of a potential criminal case against JPMorgan or individuals who worked for the bank during the incident remains unclear.
Frank от 2020-10-11 22:52:29:
A pension scheme vita ex gold ke fayde hindi mein The generally held principle is that what we need to inspire us as children and impressionable young adults are "good" teachers in the Good Will Hunting or Dead Poets Society mould: benign, caring, paternal figures who will unlock our dormant creativity and nurture our blossoming genius. But often, a collision with a total bastard who hates everything about you is very useful training, and will serve you well throughout your life. Perhaps, in fact, he will be more useful than the empathetic Robin Williams figure, more inspirational in his own way - if only because you won't rest until you've proved the old git wrong.
Deangelo от 2020-10-11 22:52:29:
Not available at the moment coq10 200 mg solgar "Not only will our awards secure the immediate future of these particular buildings, it will also empower congregations to adapt them, where necessary, so they can be enjoyed more widely throughout the community and in turn enable them be more sustainable for the future," she said.