Operating System - HP-UX
1763095 Members
2453 Online
108909 Solutions
New Discussion юеВ

find a file down 1 level only

 
SOLVED
Go to solution
S.C. Fun
Advisor

find a file down 1 level only

Hi, assuming that I have this directory structure:
/home/user1/projA/scheda
and a file namely "term" was found in both /home/user1/projA and /home/user1/projA/scheda

let say i want to seach a the file "term" in /home/user1/projA only but not any level down below, i use:
# find /home/user1 -name term
the output also show me the file under /home/user1/projA/scheda. what option should i use in find command to limit my search at certain level only? Thanks in advance.
6 REPLIES 6
Steven Sim Kok Leong
Honored Contributor

Re: find a file down 1 level only

Hi,

If it is just 1 level down as indicated in your query, then,

1) At the command line:

# ls /home/user1|grep term;for i in /home/user1/*;do if [ -d $i ];then ls $i|grep term;fi;done

2) As a script:
==========================
#!/sbin/sh

DIR=/home/user1
SEARCH=term

ls $DIR | grep $SEARCH
for i in $DIR/*
do
if [ -d $i ]
then
ls $i | grep $SEARCH
fi
done
==========================

Hope this helps. Regards.

Steven Sim Kok Leong
Stefan Farrelly
Honored Contributor

Re: find a file down 1 level only


You can use either;

cd /home/user1
ls */*term* (the first * means only go down 1 level, if you wanted 2 levels then do ls */*/*term*)
or
ls projA/*term*

or

ls /home/uers/projA/*term*

This will search only that directory.

Im from Palmerston North, New Zealand, but somehow ended up in London...
T G Manikandan
Honored Contributor
Solution

Re: find a file down 1 level only

Steve Steel
Honored Contributor

Re: find a file down 1 level only

Hi

make a script myfind like this

#myfind
#
#params dir and filename
dir=$1
file=$2
echo $dir"/"$(ls -1 $dir|grep $file$)


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
John Carr_2
Honored Contributor

Re: find a file down 1 level only


Hi

find -fsonly /home/user1/projA -name filename

John.
John Carr_2
Honored Contributor

Re: find a file down 1 level only

Please ignore my last response i mis read the question.

John.