- Home
- Contact
-
Articles / Code
- HTML/CSS (2)
-
Scripts (17)
- Twitter & bash
- Generate sitemaps
- random floating point in bash
- Gmail script
- Python http POST requests
- Bashrc enhancements
- commandline <> nautilus
- Word Definitions
- Synonyms
- mysqld monitor
- remote server
- links and emailaddresses
- Apache Analyser
- remote ipaddress
- OOP Python
- mysql tuning
- diskspace notification
- Server Configuration (6)
- ICT-security (2)
Bashrc enhancements
» Articles / Code » Scripts » Bashrc enhancements
I mostly use the commandline, but try to avoid too much typing, so I created and collected lots of Bash enhancements to make my live somewhat easier.
To use it, add this to your bashrc ( ~/.bashrc ) file :
cdl() { cd "$1"; ls -l; }
ff () { find . -exec grep -q "${1}" '{}' \; -print; }
# ff: to find a file under the current directory
ff () { /usr/bin/find . -name "$@" ; }
# ffs: to find a file whose name starts with a given string
ffs () { /usr/bin/find . -name "$@"'*' ; }
# ffe: to find a file whose name ends with a given string
ffe () { /usr/bin/find . -name '*'"$@" ; }
# enquote: surround lines with quotes (useful in pipes) - from MervTormel
enquote () { /usr/bin/sed 's/^/"/;s/$/"/' ; }
# debug_http: download a web page and show info on what took time
debug_http () { /usr/bin/curl $@ -o /dev/null -w "dns:
%{time_namelookup} connect: %{time_connect} pretransfer:
%{time_pretransfer} starttransfer: %{time_starttransfer} total:
%{time_total}\n" ; }
# http_headers: get just the HTTP headers from a web page (and its redirects)
http_headers () { /usr/bin/curl -m 1 -I -L $@ ; }
#show contents of tar file
tarview() {
echo -n "Displaying contents of $1 "
if [ ${1##*.} = tar ]
then
echo "(uncompressed tar)"
tar tvf $1
elif [ ${1##*.} = gz ]
then
echo "(gzip-compressed tar)"
tar tzvf $1
elif [ ${1##*.} = bz2 ]
then
echo "(bzip2-compressed tar)"
cat $1 | bzip2 -d | tar tvf -
fi
}
# print your local ip-address
iplocal(){
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |
cut -d: -f2 | awk '{ print $1}' ;
}
alias mysqlx="mysql -u yourname -p"
alias sdn='shutdown -h -P now'
alias upgrade='apt-get update && apt-get upgrade'
alias ll='ls -l'
function ii()
{
echo -e "\nYou are logged onto "; hostname
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Disk space :$NC " ; df
echo -e "\n${RED}Memory stats :$NC " ; free
echo -e "\n${RED}Local IP Address :"; iplocal
echo
}
function repeat()
{
if [ $# != 0 ]; then
local i max
max=$1; shift;
for ((i=1; i < = max ; i++)); do
eval "$@";
done
else
echo "usage: repeat "
fi
}
function apts() # debian specific.
{
apt-cache search $1
}
function ds()
{
echo 'size of directories in MB'
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo 'you did not specify a directy, using pwd'
DIR=$(pwd)
find $DIR -maxdepth 1 -type d -exec du -sm \{\} \; | sort -nr
else
find $1 -maxdepth 1 -type d -exec du -sm \{\} \; | sort -nr
fi
}
# Opens a filebrowser starting from
# the current working directory
function ww()
{
#nautilus $(pwd)
nautilus ./
}
# remove line-numbers from a text/script
function rln()
{
if [ $# != 0 ]; then
sed -e 's/[0-9]*\ //' $1
else
echo "rln - remove linenubers from a textfile / script."
echo "usage: rln > "
fi
}
Post your comment
Comments
No one has commented on this page yet.
RSS feed for comments on this page | RSS feed for all comments