LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Old

Auxiliary script to rename multiple files adding a zero-padding to them

Posted 08-19-2014 at 12:37 AM by the dsc (linux-related notes)

From this blog:

http://www.walkingrandomly.com/?p=2850


Code:
#!/bin/bash
num=`expr match "$1" '[^0-9]*\([0-9]\+\).*'`
paddednum=`printf "%03d" $num`
echo ${1/$num/$paddednum}
Usage example:

for i in *.png;do mv $i `./zeropad.sh $i`; done


Possibly there's some syntax to do just that only with the "rename" command, though.
Member
Posted in Uncategorized
Views 1112 Comments 0 the dsc is offline
Old

[bash] "keep trying" command, even if exits with error, for at least 10 times

Posted 08-08-2014 at 10:40 PM by the dsc (linux-related notes)
Updated 08-08-2014 at 10:42 PM by the dsc
Tags bash

A script that tries to run a given arbitrary command N times, or until it exits with success. The commented parts are aborted attempts to make it figure whether the first parameter is a number instead of a command, and that would be used as the maximum number of attempts. Something went wrong, sometime I'll try to figure it out.

Quote:
#!/bin/bash
#input="$@"
# this program is stupid. It's declared to be in public domain by its author, who whishes to remain anonymous
...
Member
Posted in Uncategorized
Views 899 Comments 3 the dsc is offline
Old

Note to myself, for whenever I get an SSD...

Posted 08-06-2014 at 10:36 PM by the dsc (linux-related notes)
Tags ssd, swap

If it would still apply for future technology...

Quote:
Current good quality SSDs have built-in mechanisms to level the wear on the whole device so that their lives are maximised, but for something like Swap the inherent nature of that requirement will significantly ratchet up the number of Write cycles on any drive that hosts it, and that is still something I want to avoid on my SSD.

In reality it may not be a factor, but I'd rather spend a few dollars on more RAM to reduce
...
Member
Posted in Uncategorized
Views 1596 Comments 0 the dsc is offline
Old

Listing the average file size for all subfolders (+listing subfolders without ls or find)

Posted 08-03-2014 at 08:11 PM by the dsc (linux-related notes)
Updated 08-03-2014 at 09:04 PM by the dsc

A tiny "Frankenstein monster" one liner, adding a little bit from several sources/blogs/blog comments:

lsf | while read d ; do find ./"$d" -iname "*.*" -type f -printf "%k\n" | gawk '{sum += $1; n++;} END {print sum/n;}' |sed "s|$| -- $d|" ; done | sort -n

Where the first "command", "lsf" is actually a custom function:

Code:
lsf ()
{
for f in * ; do [ -d "$f" ] &&
...
Member
Posted in Uncategorized
Views 1129 Comments 0 the dsc is offline

  



All times are GMT -5. The time now is 10:55 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration