Tag Info

Hot answers tagged

25

From the findutils find manpage: If no expression is given, the expression -print is used (but you should probably consider using -print0 instead, anyway). (-print is a find expression.) The POSIX documentation confirms this: If no expression is present, -print shall be used as the expression. So find . is exactly equivalent to find . -print; ...


13

-print is the default action. Some find predicates are considered as actions as opposed to filters or conditions. For instance, -type f is not an action. -exec is an action even though it can also be used as a condition. Actions include -print, -exec and -ok. Some find implementations have other non-standard action predicates like the -print0, -printf, ...


7

They are the same, they both write out the entire directory hierarchy from the current directory. From POSIX find documentation: The following commands are equivalent: find . find . -print


4

Hard links. That's the only type for which its even possible to count. Pretty much every find option is something fairly trivially obtained for each file; the hard link count comes from stat (and is also displayed by ls, by the way). (To count symlinks, you'd have to examine every symlink and check where it points. But that's not even possible—symlinks can ...


3

In Linux there is no difference, but other systems (like AIX for instance) need -print if you want the output of the command displayed on your screen.


2

If your grep supports reading NUL-delimited lines (like GNU grep with -z), you can use it to test if anything was output by find: find /some/path -print0 | grep -qz . To pipe the data to another command, you can remove the -q option, letting grep pass on the data unaltered while still reporting an error if nothing came through: find /some/path -print0 | ...


2

The find version will also find files matching that name in subdirectories. Note you should quote or escape the * in the filename pattern; if the pattern matches a file in the local directory it will expand to that name and find will only find exactly that name. If it matches more than one filename then you will get an error because those multiple filenames ...


2

ls -ltr file*: This command just list the contents of the current directory in the long listing format (-l), sorted by modification time (-t) in reverse order (-r) of all files and directories beginning with file*. find ./ -name file*: That command searches trough the whole directory structure under the current working directory and all its subdirectories ...


1

For many years the find command did not have a default action. A common error was forgetting to add the -print option to your find command. I still to this day type it out of habit. But at some point it was added as the default action so now find . and find . -print are equivalent.


1

The shell will do filename expansion before either command is executed, so the results depends on what is in your current directory. To get what you want, I think you wouldwant to quote the * in the find command. check this example. $# First show all the files $# ~/tmp/stack$ find . . ./dir1 ./dir1/FileA ./dir1/FileB ./dir1/FileC ./dir1/filec ./dir2 ...


1

find does not sort the files, it lists them out in the order it finds them. It also traverses directories in the order it finds them. You cannot make any assumptions about the order but I believe it will be repeatable in the sense that if you run find again, you'll get the same order. On Linux, files are not stored in alphabetical order. Maybe they are on ...



Only top voted, non community-wiki answers of a minimum length are eligible