LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-09-2007, 03:15 AM   #1
mrinal.kant
LQ Newbie
 
Registered: Jul 2005
Posts: 2

Rep: Reputation: 0
problem with find command


find . -name *.lex

This command lists the output from the current directory as expected, but not from the subdirectories. Also, the command shows error in running from any of the subdirectories.

Why?
 
Old 01-09-2007, 03:21 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
find . -name: the dot says "this directory". It's that simple. If you want it to recurse into sub-directories, replace the dot (.) with the directory name, such as:

find ~ -name *.lex, where ~ represents your home directory

or

find /home/<username> -name *.lex

If you wish to find in directories other than your home directory, expect errors because you may not have permission to read some of them. Su to root, then run the find command.

Last edited by bigrigdriver; 01-09-2007 at 03:22 AM.
 
Old 01-09-2007, 03:27 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
That command should be:
find . -name "*.lex"
 
Old 01-09-2007, 03:40 AM   #4
mrinal.kant
LQ Newbie
 
Registered: Jul 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Thanx jschiwal.
It works.
 
Old 01-09-2007, 04:31 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
To explain why you see this behaviour:
*.lex is expanded by the shell to all filenames with extension .lex in the current directory, after which the result is passed to "find".

So, if you have a directory with files "1.lex" and "2.lex", the parameters that "find" gets
are
find . -name 1.lex 2.lex
which is clearly not what you want.

By quoting the "*.lex" (either single or double quotes), you prevent the filename/wildcard expansion.
This means that "find" then gets the parameter "*.lex" literally, which it then uses to filter the names of objects (files/dirs) found.

Quote:
Originally Posted by bigrigdriver
find . -name: the dot says "this directory". It's that simple. If you want it to recurse into sub-directories, replace the dot (.) with the directory name, such as:
find ~ -name *.lex, where ~ represents your home directory
Sorry, but I disagree with this. "." is a valid directory and doesn't need replacing. "find" always recurses into sub-directories of a given directory (be that ".", ~/, /home/you/ or whatever), unless you limit it using the "-maxdepth" option.
 
  


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/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 06:30 PM
Problem with the #find command jbuckley2004 Linux - General 7 08-26-2005 06:51 PM
Find command ? hpladd Linux - Newbie 5 08-09-2005 10:42 PM
problem with the shell command "find zosimus Linux - Software 7 06-14-2005 05:28 PM
problem with find command in script cojo Linux - Software 3 05-26-2004 11:28 AM


All times are GMT -5. The time now is 07:48 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration