LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-15-2021, 07:36 AM   #1
serenap
LQ Newbie
 
Registered: Apr 2021
Posts: 1

Rep: Reputation: Disabled
Linux command "find"


Dear all,

I may be asking a basic question, but I could not find a satisfactory explanation online.
I use an Ubuntu 18.04 Operating System and I was in search of a folder that I knew it should have been there, but it was not, or at least it did not appear in the list when I was typing the command "ls". Then I used the command "find" {folder_name} and the folder suddenly appeared there after typing "ls".

Could someone explain to me why this happened and if it is really related to the command "find"?

Thank you very much in advance!
 
Old 04-15-2021, 03:49 PM   #2
pandanuma
Member
 
Registered: May 2005
Location: greatwhitenorth
Distribution: deb99+
Posts: 134
Blog Entries: 10

Rep: Reputation: 37
quick answer:
a search on duckduckgo for: linux find command
leads me to this...

The currently active path marks the search location, by default. To search the entire drive, type the following:

find / filename

it is my understanding that a simple: ls command only lists the current directory

welcome to lq
 
1 members found this post helpful.
Old 04-15-2021, 03:57 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Hard to imagine how the find command could make a folder appear. Are you sure you were in the same current directory when you did the first "ls"?
 
Old 04-15-2021, 04:17 PM   #4
dannybpng
Member
 
Registered: Sep 2003
Location: USA
Distribution: Fedora 35
Posts: 79

Rep: Reputation: 22
finding a directory

Since you did not give the full command line for the "ls" command, all I can think you may have done is this.

This lists nothing, if the folder is empty.
Code:
$ ls FOLDER_NAME
This lists the folder, if it exists.
Code:
$ ls -d FOLDER_NAME
FOLDER_NAME
This lists the FOLDER_NAME too and any other files or folders under the folder, if there are any.
Code:
$ find FOLDER_NAME
FOLDER_NAME
Just a thought.
 
1 members found this post helpful.
Old 04-15-2021, 08:04 PM   #5
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 214

Rep: Reputation: 112Reputation: 112
What am I missing?

In both of the replies so far, the find command was issued without telling it what to look for. I didn't think that worked.

I think you need to tell it what you want with

Code:
find / -iname filename
for a case insensitive search starting at the root for files named filename or

Code:
find . -type d -name Icons
for a search starting at the current working directory for directories named Icons.
 
Old 04-16-2021, 05:19 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by josephj View Post
In both of the replies so far, the find command was issued without telling it what to look for. I didn't think that worked.
Why? Recent versions of GNU find default to . as search root and to -print as action.
 
Old 04-16-2021, 05:22 PM   #7
A-Okay
LQ Newbie
 
Registered: Mar 2021
Posts: 22

Rep: Reputation: Disabled
Is it possible, that the file is hidden and that is why you can't see it?
 
2 members found this post helpful.
Old 04-18-2021, 06:55 PM   #8
bryan1024
LQ Newbie
 
Registered: Feb 2014
Location: USA
Distribution: Slackware
Posts: 19

Rep: Reputation: Disabled
By default, ls searches only the current directory (-R changes this). On the other hand, by default, find searches everything under the current directory. Therefore, if you have this structure:

/dir1/dir2/myfile

and you do 'ls' or 'ls myfile' from /dir1 (or from /), you will not find it. However, 'find myfile' will find it, but only show you the filename, not which directory it was found in. A more useful command in this situation would be 'ls -R|grep myfile'.

From your description, I'm not sure if this fits your problem, but maybe it'll help.
 
Old 04-18-2021, 08:08 PM   #9
pandanuma
Member
 
Registered: May 2005
Location: greatwhitenorth
Distribution: deb99+
Posts: 134
Blog Entries: 10

Rep: Reputation: 37
i think i might have misunderstood the question

are you trying to find out if this is normal behavior?
if your description of events is correct...
when you entered these commands in this order: ls, find foldername, ls
these were your results:

ls ---you did not see? the file listed
find foldername ---i am not sure what your result were?
ls ---for some strange reason the folder is now listed!

as long as you did not change directories, i would say this is not normal behaviour
am i on the right track? [i am far from an expert]
 
Old 04-19-2021, 01:29 AM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The only thinkable mechanism is an automount.
Check with df foldername if it's a separate (mounted) filesystem.
If yes:
The classic autofs always shows the folder. Only ls -l shows arbitrary attributes when not mounted.
I am not yet familiar with the x-systemd.automount - check for this option in /etc/fstab!
Another "late mount" mechanism might exist.
 
Old 04-19-2021, 10:52 PM   #11
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by serenap View Post
Dear all,

I may be asking a basic question, but I could not find a satisfactory explanation online.
I use an Ubuntu 18.04 Operating System and I was in search of a folder that I knew it should have been there, but it was not, or at least it did not appear in the list when I was typing the command "ls". Then I used the command "find" {folder_name} and the folder suddenly appeared there after typing "ls".

Could someone explain to me why this happened and if it is really related to the command "find"?

Thank you very much in advance!
Try:
  • Issue 'ls' as '\ls'. This will ignore any alias that's defined.
  • If the above works, issue "alias | grep ls" and see if there's an unusual alias defined that's affecting the way 'ls' is working. (For example, using some odd switch like '--hide=...'.) If you find an alias defined for 'ls', do you really need it? If it's defined systemwide and you can't -- or do not wish to -- remove it, you can override with an alias of your own:
    Code:
    alias ls='\ls'                              # The plainest vanilla ls you can get
    alias ls='\ls <other switches you prefer>   # Plain vanilla but customized by you
    alias ls='_ls'                              # Vanilla but uses /etc/DIR_COLORS
    (I ran across that last one in some documentation ages ago. Don't ask where; I've forgotten the source.)

    You'd need to put one of those in a file and source it in your .profile or simply include it in the .profile directly.


HTH...
 
  


Reply

Tags
failed



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to Find a File in Linux with the Find Command LXer Syndicated Linux News 0 01-10-2018 06:00 AM
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
How to find the core files in linux with out using "Find" command? shaktiman Linux - Newbie 11 08-02-2010 09:46 AM
How to find the core files in linux with out using "Find" command? shaktiman Programming 1 07-30-2010 10:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:50 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
Open Source Consulting | Domain Registration