Display the history and optionally grep

Ever wondered how good it would be to have a command/function that would display the history or display the history with grep.

Would be really good right, well someone thought about this 🙂

$ h() { if [ -z \”$1\” ]; then history; else history | grep \”$@\”; fi; }

Place this in your .bash_profile and you can use it two different ways. If you issue \’h\’ on its own, then it acts like the history command. If you issue:

h cd

Then it will display all the history with the word \’cd\’

* View this command to comment, vote or add to favourites * View all commands by haivu

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/M_TyUNnb_IA/display-the-history-and-optionally-grep

\"Reblog

Working with FTP Directories.

If you have to manage some ftp site, I can understand you pain in managing the site with FTP. Specially if you are managing a site where you need to edit the files. Without shelling out some decent amount of money you will not get decent editor which can help you edit the files directly over ftp. So today I spent my time looking for a good solution and UREKA I found it.

download and install curlftpfs. mount your ftp directory onto some directory with a command like the below:
curlftpfs ftp://w/ak /mnt/ftp

Once done use your faviourite file manager of editor to manage it like  a local folder.

PS:: you can use netrc file demonstrated earlier to make sure you dont have to type the username and password.
Technorati Tags: Linux, FTP, edit, file, mount

Solaris Tips and Tricks

Find a list of Tips and Tricks here.

A nice trick to list the process which has opened a particular port is :

#!/bin/ksh
#
# 7-30-2003
# find from a port the pid that started the port
#
line=\’————————————————————————-\’
pids=`/usr/bin/ps -ef | sed 1d | awk \'{print $2}\’`

# Prompt users or use 1st cmdline argument
if [ $# -eq 0 ]; then
         read ans?\”Enter port you like to know pid for:  \”
else
         ans=$1
fi

# Check all pids for this port, then list that process
for f in $pids
do
         /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q \”port: $ans\”
         if [ $? -eq 0 ] ; then
                 echo \”$line\\nPort: $ans is being used by PID: \\c\”
                 /usr/bin/ps -o pid -o args -p $f | sed 1d
         fi
done
exit 0
Technorati Tags: port, solaris, process, script