# find /home/xyz -name abc.txt
# vi
Simply you can do :
# find /home/xyz -name abc.txt -exec vi {} +
You can make an alias of above command and it in your profile file.
But if you have more then one abc.txt file and you want to open only one of them, you can use the following script.
# vi fvi
################################################################
#small script that finds the file given at command line and vi it
#needs improvement
if [ $# -ne 1 ]
then
echo "Usage: $0
exit 1
fi
result=`find . -name $1`
file=`echo $result | awk '{print $1}'`
if [ -n "$file" ]
then
vi $file
else
echo "$file not found"
fi
################################################################
How to use it
1) Copy the script to some folder where everybody can access it, like "/usr/bin/"
2) chmod 755 /usr/bin/fvi
Let say you want to find and vi abc.txt from /home/xyz
# cd /home/xyz
# fvi abc.txt
No comments:
Post a Comment