LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > rainbowsally
User Name
Password

Notices


Rate this Entry

KDE Utils: cleanup, hlp

Posted 01-23-2012 at 07:16 AM by rainbowsally
Updated 01-23-2012 at 07:19 AM by rainbowsally

Features:
  • Cleanup old backup files quickly with feedback on operations being done.
  • Outstanding doc viewer that doesn't tie up your terminal.
--------------------
See the link below for the "how and why" to install these as symlinks in your HOME/bin folder. Need functions for 'browse', 'launch', 'tofile'? It's all here.
http://www.linuxquestions.org/questi...-tofile-34376/
--------------------

Often we end up with lots of files with tilde suffixes (~) after editing files. Here's a utility to descend several directory levels to quickly 'cleanup' these backups starting with the current directory.

file: cleanup
purpose: remove old backup files
Code:
#!/bin/sh

exists()  # not just a link
{
    if test -f "$1";then
    return 0    # ok
    else    return 1    # error
    fi
}

do_cleanup()
{
    for i in $1/*~
    do
        if exists "$i"; then
            echo "$i"
            rm -f "$i" >/dev/null
        fi
    done
    for i in $1/*.bak
    do
        if exists "$i"; then
            echo "$i"
            rm -f "$i" >/dev/null
        fi
    done

}


do_cleanup .
for i in * 
do 
    do_cleanup $i
done

for i in */*
do 
    do_cleanup $i
done

for i in */*/*
do 
    do_cleanup $i
done

for i in */*/*/*
do 
    do_cleanup $i
done

for i in */*/*/*/*
do 
    do_cleanup $i
done

# also remove the typical hidden backups
rm -f \.*~
rm -f */\.*~
rm -f */*/\.*~
rm -f */*/*/\.*~
rm -f */*/*/*/\.*~
rm -f */*/*/*/*/\.*~

echo
echo "done..."
echo
Here's a help display function similar to the 'browse' function but that opens info and man docs, beautifully formatted, for any linux command you need to look up.

file: hlp
purpose: view nice docs without tying up the terminal
Code:
#!/bin/sh

browser=konqueror
opt="info"

if [ "$1" = "-m" ];then
    opt="man"
    shift
else
if [ "$1" = "-i" ];then
    opt="info"
    shift
fi ;fi

if [ "$1" = "" ];then
  #update and view ~/bin docs
  echo "
  Please wait... updating ~/bin docs
  if this isn't what you wanted to do, add the subject
  you wanted help on on the command line
  "
  
  cd ~/bin
  ./update-docs.exec 2>/dev/null # suppress errors
else
  launch "$browser '$opt:$1' >/dev/null 2>&1" 
fi
Optimizations welcome. These are by now quite old but they work so I haven't felt much inspiration to rework them.

:-)
Posted in Uncategorized
Views 1342 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 09:40 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