An efficient UNIX shell-script…

If you use lot of Unix shellscripts in the VI editor, then here’s an efficient UNIX shell-script to compare two files & delete one of them if they are duplicates… Simple yet pretty handy, just check-up!


if(test $# -eq 2)
then
if(test -f $1 && test -f $2)
then
if(cmp $1 $2)
then
echo “files are same”
echo “$2 deleted”
rm $2
else
echo “files are not same”
fi
else
echo “one of them is not a file”
fi
else
echo “MY COMMAND: enter two file names”
fi

Sounds pretty ordinary, but just check up is that really what you do as well?

And sure thing if have a better way then share it here :)

Related posts:

  1. Some Unix Tricks
  2. Learn Unix in 10 minutes
  3. Linux & Unix Tricks
  4. 11 Unix Tricks
  5. Do not run this script, ever!

Filed Under: Linux and Unix

About the Author

Om is a dynamic entrepreneur, renowned author, and founder of Webfosys Networks Pvt Ltd that provides IT, content creation, SEO & Website Design services to several clients across the globe. He has written over 12,000 articles, and loves to write Tech Reviews and Auto Reviews Reach him 24/7 - om.thoke86@gmail.com

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.