Bash Tools
Here's my collection of simple *nix command line tools, written for bash.
clean
#!/bin/bash # # Removes editor backup files from the current directory i.e. those ending in "~" and # autosave files beginning and ending in "#" # rm *~ \#*\# 2>/dev/null echo -e "\n\n\n" ls --color
e (edit)
#!/bin/bash
##!/bin/bash
#
# Launches a text editor, gedit if you have an X display, otherwise
# it falls back to using nano.
#
if [ -z "${DISPLAY}" ]; then
nano "$@"
else
gedit "$@" &
filazyredirect
#!/bin/bash
#
# Takes stdin, and redirects is to a file once stdin has been closed
# (i.e. after the process that generates the input is complete)
#
# Usage :
# lazyredirect FILE
#
# Example :
# sort mylist.txt | lazyredirect mylist.txt
#
TMP_FILE="$1-lazyredirect~$$~"
cat > "${TMP_FILE}"
mv -- "${TMP_FILE}" "$1"mvlower
#!/bin/bash
#
# Renames all of the given files to lower case
# If the lower case name already exists, then a warning is given, and the rename does not happen.
#
for NAME in $*
do
NEW_NAME=`echo ${NAME} | dd conv=lcase 2>/dev/null`
if [ "${NAME}" != "${NEW_NAME}" ]; then
if [ -f "${NEW_NAME}" ]; then
echo '# Not moving "'${NAME}'" to "'${NEW_NAME}'" as "'${NEW_NAME}'" already exists.'
else
echo "mv ${NAME} ${NEW_NAME}"
mv -- "${NAME}" "${NEW_NAME}"
fi
fi
donena (nautilus)
#!/bin/bash
#
# Launches nautilus (gnome's file manager) for the current directory,
# or the one specified as the first parameter of the command.
#
nautilus "${1-.}"psg ( ps | grep )
#/bin/bash # # greps the output of ps # ps -aef | grep "$1"
