GeekInterview.com
Series: Subject: Topic:
Question: 17 of 55

Shell script

You have current directory containing set of directories which contain files.
One file can reside in many directories.
Write script which returns number of unique file names in
all the subdirectories of a current dir.
Asked by: Namataraginu | Member Since Jan-2008 | Asked on: Jan 31st, 2008

View all questions by Namataraginu

Showing Answers 1 - 6 of 6 Answers
rps1007

Answered On : May 12th, 2008

View all answers by rps1007

"ls -R|sort|uniq"  should work

Yes  3 Users have rated as useful.
  
Login to rate this answer.
sesethi

Answered On : Feb 15th, 2009

View all answers by sesethi

Shell script accepts parameters in following format

$1 would be the first command line argument, $2 the second, and so on

$0 is the name of the script or function

If your script has more than 9 params then accept in following way

${12} : 12th param

${18} : 18th param

  
Login to rate this answer.
sesethi

Answered On : Feb 15th, 2009

View all answers by sesethi

echo $string | cut -d” ” -f1 
echo $string | cut -d” ” -f2 
echo $string | cut -d” ” -f3

  
Login to rate this answer.
sesethi

Answered On : Feb 15th, 2009

View all answers by sesethi

set -x

input_string=$1

if [ -z "$input_string" ] ; then

echo "Please enter a Text along with the script namen"

exit

fi


reversed_string=$(rev $input-string)

if [ "$input_string" -eq "$reverse_string" ] ; then

echo "The String $input_String is a Palindrome"

else

echo "This string is not a palindrome"

fi

  
Login to rate this answer.
tangram

Answered On : Jan 27th, 2010

View all answers by tangram

ls -R | grep -v "/" | sort | uniq

grep -v "/"  -- is used to filter out directories

  
Login to rate this answer.
nishi11

Answered On : Feb 22nd, 2010

View all answers by nishi11

ls -pR | grep -v "/" | grep -v ":" | sort |uniq

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.