file management

dtx0

New member
This new section doesn't have much traffic, so to up it I'll start posting scripts every now and then that some might find useful.

For our first snippet, diskmap() maps out files greater than or equal to 50 MB (not MiB); the spinner uses braille because it works well with utf-8 consoles.
Code:
# diskmap
function diskmap() { ? ?
? ?(find / -size +50M 2>/dev/null -exec du -h {} \; | sort -n) &
? ?local pid=$! # Process Id of the previous running command
? ?local spinner='????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????';
? ?local i=0
? ?while kill -0 $pid 2>/dev/null; do
? ? ? ?i=$(( (i + 1) % 176 ))
? ? ? ?printf "\r${spinner:$i:1}"
? ? ? ?sleep .05
? ?done
? ?$NORMAL;
}




This next snippet renames all files lower-case, which can be useful at times.
Code:
alias rename_lowercase='for f in *; do mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done'




Ever wanted to see what kind of commands are available in your '/usr/bin' path? Well, here's a "cheat-sheet":
Code:
cheatsheet() {
? ? # cheatsheet for a bunch of commands!
? ? ls /usr/bin/ | xargs | less
}




This next command has nothing to do with the illicit drug "LSD". One of my friend's dad used this alias for only listing directories within a certain path. I, however, loved the alias so much that I modified it to meet my purposes:
Code:
alias lsd='ls -aFGlrZ'

Code:
# recursive agrep with fuzzy string matching =)
agrep_s() {
? ? if [ -z $1 ] ?|| [ -z $2 ]; then
? ? ? ? printf "\nAGREP USE:\tagrep <PATH> <QUERY>\n\n";
? ? else
? ? ? ? find $1 -type f -print -exec agrep -B -i $2 {} \;
? ? fi
}



That's all for now. Enjoy!