Talk:Find (Unix)
Linux only example
I've taken this edited text from the article for comments, because it only works for Linux. I've tested it on AIX, Solaris, and HP-UX. This is what I got, instead of the whole structure.
0 ./outputDirectory/{} 0 ./outputDirectory
Recreate a directory structure (without files)
This command finds the directories (-type d) within the current directory (.) and makes the new directories in the '~/outputDirectory'. The tilde (~) represents your home directory (e.g. /home/joeBloggs).
find . -type d -exec mkdir -p ~/outputDirectory/{} \;
My question is, should this be redone to work in all Unix flavors, or just left out? Gbeeker 12:31, 17 February 2006 (UTC)
- This appears to be related to the shell, rather than the OS. On bash, it works. On tcsh, it does not. This one works for tcsh:
find . -type d -exec mkdir -p ~/outputDirectory/'{}' \;
- The man page actually warns that both {} and ; may need escaping from the shell. Maybe we can just leave this example out, as the article already contains examples about executing a command for all files in a directory. - Liberatore(T) 15:10, 17 February 2006 (UTC)
- I thought that the ~user home directory was worth mentioning, so I worked it into another example. I also mentioned a bit about quoting, in case a space is a search term. The escaping ; and {} from the shell I did leave out. The Korn shell (ksh) allows escaping with a \ or single quotes. Unixguy 15:21, 20 March 2006 (UTC)
Alternatives to find
I am interested to hear of any alternatives to find. What programs are there that solves the same problems on Unix? I am not thinking of indexing programs such as Beagle. I find finds syntax archaic. For example, I don't think find works with xattrs. 213.67.93.121 21:58, 26 April 2007 (UTC)
- find's syntax is not "archaic". It is idiosyncratic, powerful, and difficult to master. Just because you haven't crested the extremely harsh learning curve yet doesn't mean it's obsolete. —Preceding unsigned comment added by 204.27.178.252 (talk) 18:22, 26 March 2009 (UTC)
- With the -exec parameter you can execute an arbitrary command, so I guess it's possible to make find work with Extended file attributes, provided you have a program (as opposite to just system calls or library functions) to check them. I am not aware of any direct alternative to find, but I guess there may be some (especially some providing a GUI frontend). Tizio 12:17, 28 April 2007 (UTC)
I removed the link to searchmonkey. Why reference it but Nautilus and Konqueror's built-in search tools, Beagle, Tracker, Strigi, etc. PuerExMachina 05:33, 16 November 2007 (UTC)
Tried to add
NOTE: You mistook + for -. The first line should be -4, the second +20. IEEE, IEEE (talk) 10:51, 7 April 2008 (UTC)
I tried to add
Search current directory for files modified less than 4 days ago and print long
find . -mtime +4 -exec ls -l '{}' ';'
Search for files modified more than 20 days ago and list long, oldest first
find . -mtime -20 -exec ls -lrt '{}' ';' but soon found to my dismay that my quest to deduce how you would do either of these in Linux still eludes me. They yield what seem to be files in the directory with random dates. --previous unsigned comments added by User:68.123.188.129.
- Both searches includes the current directory (.) Therefore, "ls -l {} ;" actually includes a listing of the current directory. The second command do not work also because when "ls -ltr" is run, its argument is already a single file, so this is equivalent to "ls -l". - Liberatore(T) 11:50, 7 March 2006 (UTC)
- You would have 2 options to get the files modified more than 20 days ago. First note that the find command scans the directory structure, and the ls command is run once for each file found, so the sort options for ls (-t and -r) have no effect, as Liberatore noted above.
- Add -type f finds only types of 'file', and not directories.
find . -type f -mtime -20 -exec ls -l '{}' ';'
- Or use the -d option to ls which will show the directory inode details, not the contents of the directory itself.
find . -mtime -20 -exec ls -ld '{}' ';'
- So, it is actually difficult to get these files sorted by date, but there are ways to do it. You may want to search the newsgroup comp.unix.shell, and see the FAQ for examples. --Unixguy 12:00, 24 April 2006 (UTC)
Formated printing with Find
is it possible to format the output of the -print switch for the find command? Abountu 17:27, 18 September 2006 (UTC)
this is a really useful page but the name is too generic, it should be something like "Find (Unix)". Agree? —Preceding unsigned comment added by Searchtools (talk • contribs) 00:38, 24 January 2008 (UTC)
3.4 Finding exact matches for times?
- Sigh,* sometimes Wikipedia articles are context-free. Is there a rationale for `find` having the ability to match 24-hour periods that start arbitrarily from the time it is run but not exact dates, such as "find all files modified between 9AM and 5PM on January 1 in my locale?" What's the shortest incantation to accomplish that without resort to perl? —Preceding unsigned comment added by 155.212.34.122 (talk) 23:42, 29 January 2009 (UTC)
Removal of "Windows commands" template
I removed the "Windows commands" template from the end of this article. While Windows does have a "find" command, it is much different than the UNIX command described in this article. The Windows "find" command (actually, it was part of MS-DOS before Windows existed) is actually more like the UNIX grep command. And the DOS/Windows find (command) as its own article, anyway. --Lance E Sloan (talk) 17:44, 24 February 2009 (UTC)
Error in Search_for_a_string section
The Search_for_a_string section says "The ... single quotes (' ') surrounding the braces ... needed to allow spaces and other special characters."
This is not technically true. The single quotes are not needed. The following is a Linux demonstration without single quotes surrounding the braces.
bash-3.2# mkdir 'directory with spaces' bash-3.2# echo -e 'Hello world\nthis is a test' >'directory with spaces/file with spaces' bash-3.2# find 'directory with spaces' -type f -exec grep -l test {} \; directory with spaces/file with spaces
-Ben Collver —Preceding unsigned comment added by 75.145.67.114 (talk) 16:21, 22 September 2010 (UTC)
Solaris version of find
The Solaris version of find does not support the -path or -ipath options, and probably has a number of other differences. Considering how widely used Solaris is, it should probably be noted in the article.
Jeff The Riffer (talk) 15:53, 15 November 2010 (UTC)
POSIX protection from infinite output
is this impossable becuse of the Halting problem.Confront (talk) 07:08, 19 January 2011 (UTC)