Quantcast
Channel: Gigarocket Forum - All Forums
Viewing all articles
Browse latest Browse all 1923

file management

$
0
0
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'

Note: the Z flag only works if SELinux is installed. Remove the 'Z' if there's no SELinux data.
 


If you have a good command of regular expressions, then, pcregrep and egrep are just fine. But, if you're lazy and you use agrep, you may want to try this out:
 
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!

Viewing all articles
Browse latest Browse all 1923

Trending Articles