
How to Find Files in Linux - Learning Terminal - Chris Titus Tech
video description
Date: 2022-03-20
Comments and reviews: 10
Gary
May I ask what distro you are using for these examples? It has always been my experience that you must quote wildcarded file names to prevent the shell from expanding the wildcard (which produces unexpected results and/or errors) and allows find itself to operate on the wildcards. Are you using - as the starting directory because you are limiting the search to your home directory? Starting with - returns absolute path names relative to your home directory, starting the path name with / returns absolute path names relative to /, starting with dot (.) returns relative path names relative to current directory. This is how I learned to use find (-print is technically correct but redundant in later versions of find.)
- find all files in my home directory that start with the string 'media':
cd; find . -name 'media-' -print
find /home/user -name 'media-' -print
find - -name 'media-' -print
- find all files in my home directory that contain the string 'media' (use of grep is not necessary and also forks additional processes):
cd; find . -name '-media-' -print
- find all files in the file system that contain the string 'media' (you will be restricted from certain directories as an ordinary user):
cd /; find . -name '-media-' -print
find / -name '-media-' -print
If any part of my comment is incorrect or inappropriate, I apologize in advance.
Oops, to be clear ... the strings apply only to the actual file name and -not- to the content of the file.
reply
May I ask what distro you are using for these examples? It has always been my experience that you must quote wildcarded file names to prevent the shell from expanding the wildcard (which produces unexpected results and/or errors) and allows find itself to operate on the wildcards. Are you using - as the starting directory because you are limiting the search to your home directory? Starting with - returns absolute path names relative to your home directory, starting the path name with / returns absolute path names relative to /, starting with dot (.) returns relative path names relative to current directory. This is how I learned to use find (-print is technically correct but redundant in later versions of find.)
- find all files in my home directory that start with the string 'media':
cd; find . -name 'media-' -print
find /home/user -name 'media-' -print
find - -name 'media-' -print
- find all files in my home directory that contain the string 'media' (use of grep is not necessary and also forks additional processes):
cd; find . -name '-media-' -print
- find all files in the file system that contain the string 'media' (you will be restricted from certain directories as an ordinary user):
cd /; find . -name '-media-' -print
find / -name '-media-' -print
If any part of my comment is incorrect or inappropriate, I apologize in advance.
Oops, to be clear ... the strings apply only to the actual file name and -not- to the content of the file.
reply
Cuttlefish
I've always preferred to enable globbing and use -ls -- - grep -i [stuff]- to find things, just cause I never got used to find. However, filtering by time and size does sound pretty powerful, but I'm not sure that I have a use for that. Reassuring to know that this video exists if I ever find myself needing this command! Great vid!
Edit: I realize that my preferred method probably isn't as efficient as whatever algorithms/methods the find command uses, and can probably do a full search without me having to think too hard about narrowing my search. Methods like using information directly from the system, rather than expanding my grep query into a massively clustered regex command.... I'll come back to this video the next time I lose something in my system!
reply
I've always preferred to enable globbing and use -ls -- - grep -i [stuff]- to find things, just cause I never got used to find. However, filtering by time and size does sound pretty powerful, but I'm not sure that I have a use for that. Reassuring to know that this video exists if I ever find myself needing this command! Great vid!
Edit: I realize that my preferred method probably isn't as efficient as whatever algorithms/methods the find command uses, and can probably do a full search without me having to think too hard about narrowing my search. Methods like using information directly from the system, rather than expanding my grep query into a massively clustered regex command.... I'll come back to this video the next time I lose something in my system!
reply
fresnoredemption
Not relative to this video but have a couple of Linux questions.
I am planning on rooting my Samsung Galaxy Tab E tablet and was wondering what Linux should I put on it (or should I keep the default and just get rid of the bloatwear)?
Also, when my daughter buys her aunt's laptop, I shall be having fun with her Chromebook and putting Linux on it. I was raised on computers and know basic programming (the logic behind programming but not the languages per say), which Linux should I install (realize it is a Chromebook so no heavy gaming on it)?
reply
Not relative to this video but have a couple of Linux questions.
I am planning on rooting my Samsung Galaxy Tab E tablet and was wondering what Linux should I put on it (or should I keep the default and just get rid of the bloatwear)?
Also, when my daughter buys her aunt's laptop, I shall be having fun with her Chromebook and putting Linux on it. I was raised on computers and know basic programming (the logic behind programming but not the languages per say), which Linux should I install (realize it is a Chromebook so no heavy gaming on it)?
reply
David
Chris, you should have used 'media-' between quotes.
If you had a file in your current directory named fi. 'media.jpg' then bash would have replaced your medi- with media.jpg and you would be looking only for that filename.
If you had two filenames starting with media, bash would have replaced media- with those 2 names and the find command would have thrown an error.
So I guess it is time for you to make a video talking about wildcards and globbing ;-)
reply
Chris, you should have used 'media-' between quotes.
If you had a file in your current directory named fi. 'media.jpg' then bash would have replaced your medi- with media.jpg and you would be looking only for that filename.
If you had two filenames starting with media, bash would have replaced media- with those 2 names and the find command would have thrown an error.
So I guess it is time for you to make a video talking about wildcards and globbing ;-)
reply
Cuttlefish
For people who think the least amount of characters typed in terminal is best, enable globbing and use -ls --- with grep. Less optimized than find (probably, idk), but quick and useful if you're already somewhere deep in your filesystem (don't use it in root dir; it grabs every file from every subdirectory and will take hours to finish, or give up after 5 minutes).
reply
For people who think the least amount of characters typed in terminal is best, enable globbing and use -ls --- with grep. Less optimized than find (probably, idk), but quick and useful if you're already somewhere deep in your filesystem (don't use it in root dir; it grabs every file from every subdirectory and will take hours to finish, or give up after 5 minutes).
reply
Gary
Thank you, even after using Linux for 10 years and trying to puzzle out man pages (which are complete, detailed, factual, and often utterly useless), I'd given up on finding via terminal (except for executables when I can use _whereis_ ) because I never got the command parameters right -- I'd either get no result, or the entire disk volume listed!
reply
Thank you, even after using Linux for 10 years and trying to puzzle out man pages (which are complete, detailed, factual, and often utterly useless), I'd given up on finding via terminal (except for executables when I can use _whereis_ ) because I never got the command parameters right -- I'd either get no result, or the entire disk volume listed!
reply
Amelio
Hey Chris,
From a Terminal beginners perspective i feel like you went really really fast in this video, id like to know what every bit of the command does and have time to comprehend that personally, like really overexplaining things would be helpful for it to stick in. Overall though its a wellmade video with great info, thanks :)
reply
Hey Chris,
From a Terminal beginners perspective i feel like you went really really fast in this video, id like to know what every bit of the command does and have time to comprehend that personally, like really overexplaining things would be helpful for it to stick in. Overall though its a wellmade video with great info, thanks :)
reply
Shriniwas
Awesome video on Linux -find- command. learned so much.
If you can, If possible can you make one video on Linux file system or file system hierarchy? and how it works?
Thanks for the video!
reply
Awesome video on Linux -find- command. learned so much.
If you can, If possible can you make one video on Linux file system or file system hierarchy? and how it works?
Thanks for the video!
reply
gilkesisking
Good stuff Chris. Additional options for find...
-perm 777 ( permissons )
-empty
-maxdepth ( how far down the tree you want to look )
locate command is another good one.
reply
Good stuff Chris. Additional options for find...
-perm 777 ( permissons )
-empty
-maxdepth ( how far down the tree you want to look )
locate command is another good one.
reply
Solo
You're killing it Chris!! I love these kinds of videos. However, I'd like them to be a bit more detailed for beginners like me. Also, longer tutorial from you is always awesome!
Cheers.
reply
You're killing it Chris!! I love these kinds of videos. However, I'd like them to be a bit more detailed for beginners like me. Also, longer tutorial from you is always awesome!
Cheers.
reply
Add a review, comment
Other channel videos















