[BL] rm -r and grep -r for busybox

Lee Forrest lforrestster at gmail.com
Thu Feb 8 10:27:47 EST 2007


Busybox doesn't have either of these options, both of
which are very valuable. rm -r allows you delete an
entire directory tree. grep -r allows you to search all
of the files in a directory tree.

#!/bin/sh

# rm-r.sh

# usage
# rm-r.sh  directory 

# show top of this script if any of the standard options
# used to see helpfiles are used as the first argument to script

if [ "$1" = "-help" -o "$1" = "-h" -o "$1" = "--help" ] 
then head `which rm-r.sh` 
exit 0; fi

#first delete all the regular files 

find "$1" -type f | xargs /bin/rm -f  && 

# then symbolic links

find "$1" -type l | xargs  /bin/rm -f  &&

# then character device files 

find "$1" -type c | xargs  /bin/rm -f  &&

# then block device files 

find "$1" -type b | xargs  /bin/rm -f &&

#then fifos (named pipes)

find "$1" -type p | xargs  /bin/rm -f  &&

# then sockets

find "$1" -type s | xargs  /bin/rm -f  &&

#next get the directories, but you have to feed the output
#of 'find /dir -type d' to xargs in reverse order or it
#won't work

find "$1" -type d | sed -n '1!G;h;$p' | xargs /bin/rmdir

# show top of this script if above command exits with any errors

if [ "$?" != "0" ] ; then head `which rm-r.sh` ; fi

------------------------------------------

#!/bin/sh

# grep-r.sh

# usage 
# grep-r.sh directory (grep options) "grep-string" 
# quotes  not necessary for simple strings of ordinary 
# characters without spaces

# show top of this script if any of the standard options
# used to see helpfiles are used as the first argument to script

if [ "$1" = "-help" -o "$1" = "-h" -o "$1" = "--help" ] 
then head `which grep-r.sh` 
exit 0; fi

find "$1" -type f | xargs  grep "$2" "$3" "$4" "$5" "$6" 2> /dev/null

# show top of this script if above command exits with any errors

if [ "$?" != "0" ] ; then head `which grep-r.sh` ; fi

---------------

Lee

-- 
BasicLinux: Small is Beautiful
http://www.basiclinux.com.ru




More information about the BasLinux mailing list