Explain Usage Of The Linux Left Bracket /usr/bin/[ Command

by on May 6, 2008 · 0 comments· LAST UPDATED May 5, 2008

in , ,

Q. I see [ command in /usr/bin directory. What is the /usr/bin/[ command used for?

A.This is test command and it is used to check file types and compare values.

General syntax is as follows:
[ EXPRESSION ]

For example, find out if /etc/passwd exists or not:
[ -f /etc/passwd ] && echo "Yes" || echo "No"
Regularly you write it as follows:

if [ -f /etc/passwd ]
then
   echo "Yes"
else
  echo "No"
fi

OR

if test -f /etc/passwd
then
   echo "Yes"
else
  echo "No"
fi

Read test or [ command man page for all other expressions.
man [
man test



If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , ,

Previous Faq:

Next Faq: