Of particular interest is -ls: find /path/to/folder -name '*bat*' -ls But there are also other actions whose purpose is to display results, besides -print. All the commands given above are equivalent to themselves with -print tacked on at the end.įind is often used to run commands based on the files found-often, commands that make changes. Getting Detailed Outputįind's default action if you don't specify one is -print. Often people think they want -type f, but really they want -xtype f. If you have a symlink to another symlink to a file, -xtype f will match it even though its direct target is another symlink rather than a regular file. find /path/to/folder -name '*bat*' -xtype f Provided you're not running find with -L flag, -xtype on a symbolic link tests the type of the file the link points to. That's actually even simpler: use -xtype instead of -type. That uses the -o operator and also parentheses for grouping (which must be quoted so the shell does not treat them specially otherwise you'll get a syntax error).īut suppose you only want to see symbolic links that ultimately point to a regular file (and not symbolic links to directories, device nodes, etc.). If you want to find both regular files and symbolic links, you can use: find /path/to/folder -name '*bat*' \( -type f -o -type l \) If you had a symbolic link that matched your search, wouldn't you want to know about it? but often not what you really want, especially if you're running find for the purpose of examining the output yourself. This is frequently recommended and sometimes quite appropriate. To find only regular files-and not folders, symbolic links, and special device nodes-you can use -type f. If you want to avoid matching files like embattled.c, you could use: find /path/to/folder -name '*bat.c' -o -name 'bat*.c' I noticed all your filenames have bat either at the very beginning or the very end of the part preceding the. If you only want to find files like that, use: find /path/to/folder -name '*bat*.c' If you want to search case-insensitively, so files containing BAT, bAt, and so forth are matched, use the -iname test instead of the -name test: find /path/to/folder -iname '*bat*' ( The shell expands ~ to your home directory's fully qualified path.) Broadening or Narrowing Your Search, Based on Name To search your home directory, use ~, or the full name of your home directory. To search in the folder you're currently in (e.g., that you've cded to), use. I have quoted the search pattern *bat* because, if the quotes were omitted and files match *bat* in the current directory, the shell will expand *bat* into a list of them and pass that to find. To find all files anywhere inside /path/to/folder whose names contain bat, you can use: find /path/to/folder -name '*bat*'
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |