LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 08-21-2006, 09:08 AM   #1
basak
Member
 
Registered: Jul 2006
Posts: 41

Rep: Reputation: 15
find exactly in that directory


hi
I want to use smth . like

if [ -e file ] ;then
-----
fi

statement but I want to know if that file exists under just some given directory(not including its subdirectories) instead of the current directory.I tried

var1=$(find givendirectory -name file)
if [ $var1 != "" ] ;then
---
fi

but of course that did not work because

1) find givendirectory -name file command does not search in only the given directory,it also looks in the subdirectories of it.
2) $var1 is never "" because if the file does not exits , the command does not substitude ""
to var1 ,it substitudes "find: he: No such file or directory"

is there a practical way to search under a given directory for whether a file exists?
 
Old 08-21-2006, 09:26 AM   #2
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 32
pass given directory as param1 and filename to param2
e.g.
./blah.sh dir file

Code:
#!/bin/bash

DIR=$1
FILE=$2

if [ -f "${DIR}/${FILE}" ] ; then
echo "$FILE exists in $DIR"
else
echo "$FILE does not exist in $DIR"
fi
exit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find in current directory ramanadyv Linux - Newbie 3 03-28-2006 11:12 PM
how to find out how big is a directory xpucto Linux - Newbie 7 10-04-2005 03:12 AM
How to find a string in a directory? iclinux Linux - Newbie 2 07-02-2005 09:20 AM
find size of directory naijaguy Linux - Newbie 3 03-04-2005 12:11 PM
How to find the directory of a binary (in C) DiscoStoo Programming 1 03-22-2002 04:29 PM


All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration