Posted: . At: 12:43 PM. This was 9 years ago. Post ID: 7992
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Some useful bash shell scripts for the Linux user.


This function will allow your computer to speak.

function shellspeak()
{
       mplayer "http://translate.google.com/translate_tts?tl=en&q=$(echo $@ | sed 's/\s/+/')" > /dev/null 2>&1;
}

A script that will change all files in a directory to lowercase filenames.

function lowercase()  # move filenames to lowercase.
{
    for file ; do
        filename=${file##*/}
        case "$filename" in
        */*) dirname==${file%/*} ;;
        *) dirname=.;;
        esac
        nf=$(echo $filename | tr A-Z a-z)
        newname="${dirname}/${nf}"
        if [ "$nf" != "$filename" ]; then
            mv "$file" "$newname"
            echo "lowercase: $file --> $newname"
        else
            echo "lowercase: $file not changed."
        fi
    done
}

A function that will check for all invalid symlinks in a directory.

function badlink()
# From Atomic magazine #43 August 2004. http://www.atomicmpc.com.au
{
	DEFAULT=$(tput sgr0);
	FILELIST=.badlink.list
 
	[ -e $FILELIST ] && $( rm -fr $FILELIST )
 
	function checklink()
	{
		for badlink in $1/*; do
			[ -h "$badlink" -a ! -e "$badlink" ] && echo \
			\"$badlink\" >> $FILELIST
			[ -d "$badlink" ] && checklink $badlink
		done
	}
 
	for directory in `pwd`; do
		if [ -d $directory ] ; then
			checklink $directory;
		fi
	done
 
	if [ -e $FILELIST ] ; then
		for line in $(cat $FILELIST); do
			echo $line | xargs -r rm | echo -e "$line \
			-removed"
			echo
		done
		rm -fr $FILELIST
	else
		printf "Bad symlinks not found.\n\n"
	fi
} # End Atomic function.

Get your network IP addresses easily with this simple function.

function my_ip() # get IP adresses. Bracket on next line C style...
{
    MY_IP=$(/sbin/ifconfig wlan0 | awk '/inet/ { print $2 } ' | sed -e s/addr://)
    MY_ISP=$(/sbin/ifconfig wlan0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://)
}

Get user information from the shell.

if [ -x /usr/bin/finger ] ; then
   INFO=$(finger -lmps $LOGNAME | sed -e "s/On/Logged in/g" | grep "since" )
else
   INFO=$(uname -msov)
fi
 
echo -ne "${INFO}\n"

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.