Posted: June 8th, 2009

bash scripting – rename many files at once

Category: technical

let say you have many files in a directory, and you need to rename them all at once. you can go the route and do each one by one. but man that takes way too long. why not a bash script? with bash you can easily rename all your files quickly at once.

first off go into the directory you want to do this in and choose the file extensions, let say we are doing this with images this will list all the *.jpg images in your directory

lanqy@lappy2000:~/$  for i in *.jpg; do echo $i; done

you can also list this way it does the exact same thing.

lanqy@lappy2000:~/$  for i in *.jpg; do echo ${i}; done

let say you want to rename a particular portion w/in the jpg image.
the wild cards can be places strategically.

lanqy@lappy2000:~/$ for i in *_blah_*.jpg; do echo $i; done

now that you have this, and you want to remove the “_blah”, test the waters with the “echo” command before the “mv” command

lanqy@lappy2000:~/$ for i in *_blah*.jpg; do echo mv "$i" "${i/_blah}"  ; done

the command below is the how you do a simple string replace

lanqy@lappy2000:~/$ do echo mv "$i" "${i/_blah}"

you are basically saying w/in $i, look for _blah and remove. if you put another slash afterwards it means replace with _meh

do echo mv "$i" "${i/_blah/_meh}"

thats all! have fun replacing files, oh yeah remove the echo when you want to execute it completely.

Posted: June 3rd, 2009

html tidy

Category: technical

first get it here.

wget the file over to your server.

then un-pack it and then run the following in the command line

make
make install

you might need to make a few directories on your server. because some the ones during the install process won’t be available.

after you are all finished, you can run tidy on any of your HTML files. it will search and clean up

here are a few commands you can use during the execution.
–more here–

Processing directives
——————–
  -indent or -i   indent element content
  -omit   or -o   omit optional endtags
  -wrap 72        wrap text at column 72 (default is 68)
  -upper  or -u   force tags to upper case (default is lower)
  -clean  or -c   replace font, nobr & center tags by CSS
  -numeric or -n  output numeric rather than named entities
  -errors or -e   only show errors
  -quiet or -q    suppress nonessential output
  -xml            use this when input is wellformed xml
  -asxml          to convert html to wellformed xml
  -slides         to burst into slides on h2 elements

Character encodings
——————
  -raw            leave chars > 128 unchanged upon output
  -ascii          use ASCII for output, Latin-1 for input
  -latin1         use Latin-1 for both input and output
  -iso2022        use ISO2022 for both input and output
  -utf8           use UTF-8 for both input and output
  -mac            use the Apple MacRoman character set


File manipulation
—————
  -config <file>  set options from config file
  -f <file>       write errors to named <file>
  -modify or -m   to modify original files

Miscellaneous
————
  -version or -v  show version
  -help   or -h   list command line options
You can also use blah for any config file option blah

Input/Output default to stdin/stdout respectively
Single letter options apart from -f may be combined
as in:  tidy -f errs.txt -imu foo.html

thanks more credit here

tidy