There are lots of ways to find things in Linux/Unix. Remember that Linux is always a multi-user system, so if your account doesn't have access to know about the files you are looking for, then no command should display those to you.
The find command is quite extensive, but the manpage is complex and scary, so just search the web for "Top 50 Linux Find Commands" to see examples. https://www.baeldung.com/linux/find-command might be useful. find scans from the directory you specify in the command. You can specify multiple directories or just use '/' and have it scan everything. Almost any property of a file or directory can be specified in the command, but it does take a little thought to look for exactly what you want. I have about 20 different find commands that get used enough to have memorized over the decades, but often just get everything with the -ls option and use egrep to filter for and remove things in the list returned by find. Because find scans the file system, the performance of the storage will matter. OTOH, the results should be accurate at the time.
The locate command is bonehead simple when all you know is part of a filename. Locate is part of updatedb and scans the entire file system, building a DB of all files on it that aren't on temporary storage. The DB gets updated daily via cron, but you can force a sudo updatedb to run. locate returns answers nearly immediately since it doesn't have to scan the entire file system, but just a DB. If the files I seek have been on the system longer than 1 day, I'll start with locate.
Recoll is like a personal google for our computers. It uses helper tools to look inside files for the content. It also creates an indexed DB full of the contents and file properties. Recoll needs to be updated manually. This can be accomplished through the GUI Recoll tool as needed, or you can create a script and run that script automatically via cron daily or weekly or monthly. Recoll indexing is much heavier than locate's indexing, so I run it weekly in the middle of the night. On a system with about 45TB of storage, the recoll index can be large:
Code:
$ du -sh recoll-index/
12G recoll-index/
OTOH, searching for stuff based on what's inside is google-fast.
So, if I wanted to find all the modified files (not directories) in 2024, I'd use find and the mtime option. I think this is the command:
Code:
$ find / -type f -mtime -$(date "+%j")
If I wanted lots of time data along with the filename output, I'd add the -ls option:
Code:
$ find / -type f -mtime -$(date "+%j") -ls
Another way to to this that is less efficient would be
Code:
$ find / -type f -ls |egrep -w 2024
However, that will find files with 2024 in line, not just part of the date, so if a file size is 2024 or an inode is numbered 2024, those will be found too.
egrep -w looks for entire words, but it doesn't count numbers or punctuation, so '4312024' will be found too. Best to use the -mtime option with days ago calculated. Beware that find calculates "days" in a non-intuitive way. Best to carefully read the manpage about that, if you really care.
You can use explainshell.com to see what each option does if using the actual manpage on your system is scary. However, the local manpage will have documentation for the correct version of the programs on your system. No website will have that exact documentation. Most of the time, commands and options don't change too much, but over 5+ yrs, they do, often adding new options that are more convenient.
For example, I've been using find for 30 yrs and had never seen the -newerct option. So, I just checked and it isn't in the find command on my 20.04 or 22.04-based systems. So, either that option is a mistake or it is VERY new.
BTW, Linux/Unix doesn't really care about extensions. That's a common mistake made by people used to non-Unix-based OSes. "*.*" just insists that a file have a '.' in it. It won't find any files without a '.' in the name, which would remove nearly all compiled programs from being found. Use "*" if you want to find all files, or better, don't bother trying to specify any name at all.
Always remember that Linux names are case-sensitive, so if you don't know the exact case for a filename/directory name, it is best to force a case-insensitive search. That applies to locate, find, grep, egrep, and bash scripts (more things too).
Bookmarks