USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

find - - search for files in a directory hierarchy

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Command Line Commands
View previous topic :: View next topic  
Author Message
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Fri Dec 01, 2024 10:50 pm    Post subject: find - - search for files in a directory hierarchy Reply with quote

find - search for files in a directory hierarchy

One of the best references i've found on the net for the find utility is here: http://www.grymoire.com/Unix/Find.html

Simply put, "find" locates files. Like grep locates something IN a file, find locates files in directories. Also like grep, the odds of you memorizing all the options for find are slim to none Wink man find will of course give you the long list of available options to "find".

Example:
Code:
find . -iname *.html

This will find EVERY "html" file in the current directory and below. I remember this "-iname" as "In Name".

Code:
find . -perm 664

This will find EVERY file with the 664 permissions in the current directory and below. I also remember "-perm" as "Permissions"

That will get you started Smile FIND away ! Smile



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
JP
Linux Guru


Joined: 07 Jul 2024
Posts: 6671
Location: Central Montana

PostPosted: Sat Dec 02, 2024 1:10 am    Post subject: Reply with quote

Thanks crouse, you were the one who told me to use "locate" and "find", this just puts icing on the cake Wink.



_________________
Dell Box - Arch Linux
Dell Lappy - DreamLinux 3.5 - Default OS
Mepis 8.0 - Backup
Back to top
View user's profile Send private message Visit poster's website
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sat Dec 02, 2024 4:31 am    Post subject: Reply with quote

You can use find in combination with pipes, xargs, and then include -exec as an argument to execute various commands. Used in that way, you can do all kinds of incredible things, and you can be both powerful and dangerous. I have not really exercised the use of xargs more than once or twice, but it is nice to at least know of it when you need it. Xargs helps you deal with the issue of having too much wildcard or file expansion when you are running find commands against a large number of files expanded by your expression. Ever had the command line interpreter go berserk when you have more stuff on the line than it can handle? Xargs is there for just that scenario; maybe not something that comes up every day, but sure handy when you need it.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sat Dec 02, 2024 4:35 am    Post subject: Link to info on find with xargs Reply with quote

See http://www.kalamazoolinux.org/tech/find.html for some handy uses of the find command.

An excerpt: xargs

* Why do we need this "xargs" thing? It's in the presentation title! Smile
Answer: Speed and efficiency.
o The second line runs much faster than the first for a large number of files:
+ find / -name core -exec rm -f {} \;
+ rm -f $(find / -name core -print)
In other words, running "rm" once, with all the filenames on the command line
is much faster than running "rm" multiple times, once for each file.
o However, the second line could fail if the number of files is very large and
exceeds the maximum number of characters allowed in a single command.
o "xargs" will combine the single line output of find and run commands with multiple
arguments, multiple times if necessary to avoid the max chars per line limit.
+ find / -name core -print | xargs rm -f
o The simplest way to see what xargs does, is to run some simple commands:
+ find $HOME -maxdepth 2 -name \*.jpg -exec echo {} \;
+ find $HOME -maxdepth 2 -name \*.jpg | xargs echo



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
coastie
Moderator Bot


Joined: 24 Apr 2024
Posts: 3064
Location: The Fox Den in the Big Easy

PostPosted: Thu Aug 23, 2024 11:54 am    Post subject: Reply with quote

Found another good one for find

http://dmiessler.com/study/find/



_________________
Ubuntu on the thinkpad
Easy Peasy on the EEEPC
Desktop is down.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Thu Aug 23, 2024 2:47 pm    Post subject: Reply with quote

coastie wrote:
Found another good one for find

http://dmiessler.com/study/find/


Very good examples. Bookmarked.



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Command Line Commands All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse