I'm on a quest to locate a config file that fits these exact specifications: it should have been created or modified after March 3, 2020, have a size between 25KB and 28KB, and should likely have either a .conf or .cfg extension. I attempted using the command `find / -type f ( -name "*.conf" -o -name "*.cfg" ) -size +25k -size -28k -newermt 2020-03-03 2>/dev/null`, but I'm worried I might be overlooking something. I'm also curious about:
1. Other common directories where config files might be located besides /etc.
2. If I should switch from using -newermt to -cnewer.
3. How to adjust the command to check for file permissions as well.
5 Answers
It's crucial to think about where the config file might be based on the application or service it's for. Often, files are in specific directories expected by the software. Understanding who created or modified the file can also provide insight into where it might be located and why you need to search your whole system.
To improve your search, specify all the relevant filesystem mount points and use the `-xdev` option with your `find` command. Also, it's generally not useful to search locations like /tmp, /sys, or /proc. For timestamps, using `-mtime` might be a more traditional approach, but you can still play around with `-newermt` if that's what you prefer. Remember to run the command as root to access all directories.
Instead of a broad search, are you open to narrowing it down based on what the config file is for? That could save you time tracking it down.
Remember, running as root will give you access to more directories, which is important for a comprehensive search. The more permissions you have, the better your chances of finding that elusive file!
Try using `mlocate` instead of `find` for a quicker search. It maintains a database of files, allowing you to locate them faster. You could use a command like `locate --regex '.(conf|cfg)$'` to list candidates, and then filter them further by size and modification time using `stat` and `awk` after that. This way, you'll refine your results without wasting time searching through all directories.
Using the null character as a separator can handle spaces in file paths better. Consider using `locate -0 --regex '.(conf|cfg)$' | xargs -0r stat --printf "%n %s %Yn"` for more reliable results. This way, you still get a nicely formatted output that won't break on spaces.