1834394 Members
1706 Online
110066 Solutions
New Discussion

find command problem

 
SOLVED
Go to solution
j773303
Super Advisor

find command problem

I've a question aboutr find command. How can "find" don't search sub-directory. for example: find /var -name xxx.txt. Is it possible only search /var only? Thanks.
Hero
10 REPLIES 10
Sandman!
Honored Contributor
Solution

Re: find command problem

See if the find command listed below works:

# find /var -name "xxx.txt" ! -path "/var/*/*"
AwadheshPandey
Honored Contributor

Re: find command problem

find /tmp inve* -prune
/tmp
inventory1
inventory11
It's kind of fun to do the impossible
AwadheshPandey
Honored Contributor

Re: find command problem

find /var xxx.txt -prune
/var
xxx1.txt
xxx11.txt
xxx2.txt
It's kind of fun to do the impossible
Ganesan R
Honored Contributor

Re: find command problem

Hi,

If you want to search only in specific directory you can use ls or ll command instead of find.

#ll /var/*.txt

or goto that directory then search.

#cd /var
#ll *.txt

Hope this helps

Thanks
Best wishes,

Ganesh.
TY 007
Honored Contributor

Re: find command problem

Hello,

# cd /var

# du -s * > /tmp/var.txt

# more /tmp/var.txt

Thanks
Ernesto Cappello
Trusted Contributor

Re: find command problem

Hi j773303
You can follow these steps:

1) cd /var
2) ls -al | grep "filename"

Best regards.
Ernesto
Ernesto Cappello
Trusted Contributor

Re: find command problem

Hi j773303

One of the commands that everyone should master is the find command.

The first, and most obvious, use is find's ability to locate old, big, or unused files, or files that you forgot where they are.

The other important characteristic is find's ability to travel down subdirectories. If you wanted a recursive directory list, and ls doesn't have this option, use find.

BR.
Ernesto
Sp4admin
Trusted Contributor

Re: find command problem

Hi,

Cd /var
find . -name fimename

sp,
V. Nyga
Honored Contributor

Re: find command problem

Hi,

if you only want to find files 'xxx.txt' in a defined directory, then use the 'ls' command (or ll) and 'grep'.

ls /var|grep xxx.txt

No need to use find.

Volkmar
*** Say 'Thanks' with Kudos ***
Peter Nikitka
Honored Contributor

Re: find command problem

Hi,

an addition to Volker's solution: Keep in mind, that grep- and find/shell arguments use a different syntax when specifying pattern:
To get get all names starting with 'a' and ending in '.txt' use for
... find / shell:
find . -name 'a*.txt' ...
ls -d a*.txt

... grep:
ls /your/dir | grep '^a.*[.]txt$' or
ls /your/dir | grep '^a.*\.txt$'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"