Jump to content

how to use the find command?

find ./ -maxdepth 5 -name 'file' search directory

 

I know what the find command is for in Linux. Used to search a directory, but I don't know how to use this command.

I tried to use this command but it doesn't work.

I guess it serves to search files in some directory or in a directory where other folders are?

 

I'm still sending a photo.

 

 

1.png

Link to comment
Share on other sites

Link to post
Share on other sites

You specified a -maxdepth parameter but didn't give it the value to use as max depth.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, Kilrah said:

You specified a -maxdepth parameter but didn't give it the value to use as max depth.

What does it mean? How to give it?

Link to comment
Share on other sites

Link to post
Share on other sites

How do I search for a file with lines in Linux?

 

How do I search file.txt with cpu lines?

 

So the idea is to search for the word cpu in the file with lines. What does the rulers mean?

I know you can do this with grep.
grep 'cpu' file.txt

 

But I don't know what the rulers mean. Maybe the find command needs to be done?

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, GamerGry123 said:

What does it mean? How to give it?

Quote
       -maxdepth levels
              Descend at most levels (a non-negative integer) levels of
              directories below the starting-points.  Using -maxdepth 0
              means only apply the tests and actions to the starting-
              points themselves.

https://man7.org/linux/man-pages/man1/find.1.html

Link to comment
Share on other sites

Link to post
Share on other sites

* threads merged *

 

Please keep the question in one thread.

If you need help with your forum account, please use the Forum Support form !

Link to comment
Share on other sites

Link to post
Share on other sites

26 minutes ago, GamerGry123 said:

What does it mean? How to give it?

See the post above for the description.

 

The command you pasted in the first post didn't work in your terminal because you didn't type it correctly and forgot the '5'...

 

Beyond the manpage you can usually just search for examples of what you want to do and find more easily understandable descriptions.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

21 hours ago, GamerGry123 said:

find ./ -maxdepth 5 -name 'file' search directory

 

I know what the find command is for in Linux. Used to search a directory, but I don't know how to use this command.

I tried to use this command but it doesn't work.

I guess it serves to search files in some directory or in a directory where other folders are?

 

I'm still sending a photo.

 

 

1.png

The basic syntax is

find DIRECTORY FLAGS search-term

sudo for example I want to find my xorg.conf file from anywhere on my live system. Well we need to index outside of our users /home so we need root's permission

sudo find

then we're indexing the system itself

sudo find /

then we need to tell find what we're trying to do, in this case find a file by name

sudo find / -name

then we need to add our search term

sudo find / -name xorg.conf

The easiest way to think of this is to not use find as a "lets find something" but rather "lets look for something here" but of course this is unix not dos so we're not looking, we're finding.

 

SO I want to 'find on / the name "xorg.conf" '

 

References:

man find

LearnLinuxTV

Chris Titus Tech

Linuxize

GNU.org

Link to comment
Share on other sites

Link to post
Share on other sites

Honestly, just don't use find. Its very complex and does so many needless things for an Indexer IMO.

 

Personally I use mlocate however there are newer alternatives these days.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

i mostly use locate combine with grep. find is annoying slow for large dir

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

On 3/12/2022 at 7:47 AM, Nayr438 said:

If you just want to search a file and return a line.

cat filename | grep string

 

This ^ is superfluous. grep can read the file so there is no need to pipe from cat.
Do:

grep [pattern] [file]


(no worries everyone makes this mistake, even me sometimes)
 

I actually like a lot of old Unix stuff but the syntax for find I do not.
This is just silly but necessary sometimes.

find ./ -iname "file.txt" -print 2>/dev/null

we can do better than that.. make a simpler syntax? You can't change find because it would break everything but a new command might be good here.. efind anyone..?

"Only proprietary software vendors want proprietary software." - Dexter's Law

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×