SEE GRAPHICS DIR FOR GRAPHICS-SPECIFIC STUFF # chm to html extract_chmLib book.chm outdir # playlist for webserver echo "[playlist]" > playlist.pls echo "NumberOfEntries=X" >> playlist.pls c=0 && for i in `find path/relative/to/server/root/ -type f | sort`; do c=$((c+1)); echo "File$c=http://192.168.1.99/$i">>playlist.pls; done sed -i "/NumberOfEntries/s/X/$c/" playlist.pls # mp3s c=0 && for i in `find mp3/ -type f -name "*.mp3"|sort`; do c=$((c+1)); echo "File$c=http://192.168.1.101/$i">>mp3.pls; done # tempfile TMP=`tempfile` ls $TMP rm $TMP # loop for i in {c..f}; do echo $i; done # c, d, e, f for i in {1..8}; do echo $i; done # loop with filename spaces (example adds write permission to files) find . -print0 | while read -d $'\0' file; do chmod +w "$file"; done #chmod recursively find [dir] -type [f/d] -exec chmod [mode] {} \; ----------------- RANDOM BACKGROUND ----------------- BASH and XSRI: #!/bin/sh if [ -r "$1" ]; then img="$1"; else # choose a random PNG img=`ls $HOME/image/paper/overlay/*.* |sort -R |tail -1` #geom=`identify -format "%wx%h" $img` fi xsri --color=\#000000 --color2=\#222222 --emblem=$img --emblem-alpha=60 --geometry=-0-0 ----------------- PERL and BSETBG: To have a random image put the following in a file and save it as chooser.pl code: #!/usr/bin/perl @filenames = `ls ./images/*.jpg`; $size = $#filenames; $random = rand($size); print STDOUT $filenames[$random]."\n"; change ./images/*.jpg to point to a directory where you have images stored (but keep the *.jpg bit so it only searches for image files with a .jpg extension) make it executable by doing code: chmod +x chooser.pl and then in the ~/.fluxbox/init file change the following line so it reads as follows: code: bsetbg -f `/home/sab300/chooser.pl` Those are backticks. not apostrophes around /home/sab300 etc....obviously change that line to point to where you stored the chooser.pl file. ----------- GRUB APPEND ----------- cat /etc/grub.conf | while read cur_line do if [[ $cur_line = "timeout=30" ]] ; then echo "timeout=0" >> /tmp/grub-copy.conf else echo $cur_line >> /tmp/grub-copy.conf fi done mv /tmp/grub-copy.conf /etc/grub.conf ---------------- FIND AND REPLACE ---------------- #!/bin/sh # grab/check input OLD_VAL=$1 NEW_VAL=$2 if [[ ${OLD_VAL} == "" || ${NEW_VAL} == "" ]] then echo "No correct input given." echo "Exiting now." exit 1 fi # set textfile and tmpfile INFILE="text.file" TMPFILE="/tmp/text.file.tmp" # is value present HIT=$(grep "${OLD_VAL}" ${INFILE} | cut -f1) if [[ ${HIT} != "" ]] then # yep, present echo "First field: ${HIT}" sed "s/${OLD_VAL}/${NEW_VAL}/" ${INFILE} > ${TMPFILE} cp ${TMPFILE} ${INFILE} else # nope, not present echo "Could not find: ${OLD_VAR}" fi ----------------- OR: #!/bin/sh # grab/check input OLD_VAL=$1 NEW_VAL=$2 if [[ ${OLD_VAL} == "" || ${NEW_VAL} == "" ]] then echo "No correct input given." echo "Exiting now." exit 1 fi # set textfile and tmpfile INFILE="text.file" TMPFILE="/tmp/text.file.tmp" # on which line is value present (if any) LI_NO=$(sed -n "/${OLD_VAL}/=" text.file | sed -n '1p' ) # did we find a hit if [[ ${LI_NO} != "" ]] then # yep OLD_LINE=$(sed -n "${LI_NO}p" ${INFILE}) sed "${LI_NO}s/${OLD_VAL}/${NEW_VAL}/1" ${INFILE} > ${TMPFILE} cp ${TMPFILE} ${INFILE} NEW_LINE=$(sed -n "${LI_NO}p" ${INFILE} ) else # nope echo "Could not find: ${OLD_VAR}" fi echo "This has changed:" echo "Old line: ${OLD_LINE}" echo "New line: ${NEW_LINE}" ----------- COLUMN EDIT ----------- Ok, if they're in a block it should be possible to do something like: !} sed 's|5|4|' There is no colon preceeding this command. The '}' means until the end of of a block. You could also do something like: V}! sort -r This uses 'visual mode' to show what will be affected by your command. If the lines are not in a block of their of things get a little trickier... You need to specify a range to work on: :.,.+7! sed 's|5|4|' . means 'your current position' , means 'to' +7 means 'next seven lines' edit: cleaned it up a little... edit2: actually it doesn't have to be that tricky without a block neither: v2[arrow down, and perhaps End]! sort This sorts from your current position + the next two lines. _______________________________________ Here's a faster way (in the root of the directory you wish to get the sum of all file sizes): code: find . -printf %k"\n" | awk '{ sum += $1 } END { print sum }' For some strange reason, it's faster than du. . . It takes maybe two seconds to run on 208050 files. . . If you read the man pages, you could do some pretty cool stuff with this. . . -------------------------------------------------------- Do a lot of parsing log lines using cut, awk etc etc? Adding this function to your functionlib or .bashrc function sepsp() { tr -s" "|cut -d " " -f$@; } and now you can "cat | sepsp 2,6-". Saves you typing 19 chars each time. ____________________________________________________________________ Great feature of vim (heard there's something simliar in emacs) is folding, if you're a programmer. You can collapse and expand sections of code you specify, handy if you have a function thats 300 lines long or something works like this: first, turn it on by typing ":set fdm=marker", then surround the bit you want to hide with: //{{{ brief description here whatever you want to hide //}}} also works with: /*{{{ brief descriptinon */ whatever /*}}}*/ to hide or close a section, type "zo" to open, "zc" to close ____________________________________________________________________ # chmod according to directory or file (very basic) ls -1 | while read me; do if [ -d "$me" ]; then chmod 755 "$me" else chmod 644 "$me" fi done # Same thing, one-liner ls -1|while read me; do if [ -d "$me" ]; then chmod 755 "$me"; else chmod 644 "$me"; fi; done