Skip to main content
68 votes

How do I find a file by filename in Mac OSX terminal?

find . -name '*.csv' for instance worked for me with wildcards. OP could also use find . -name '*.dmg' to check his current directory, assuming he was in /.
pjammer's user avatar
  • 791
41 votes

How can I find only the executable files under a certain directory in Linux?

I know the question specifically mentions Linux, but since it's the first result on Google, I just wanted to add the answer I was looking for. This is tested on macOS 10.12.5: find . -perm +111 -type ...
friederbluemle's user avatar
39 votes

How can I force only relative paths in "find" output?

You can use the %P format in the -printf directive: find ${rootDir} -name '*.doc' -printf "%P\n" will display in your example: subdir/test.doc second.doc You may then use this find list in a for ...
Gabriel's user avatar
  • 491
35 votes
Accepted

Find all directories that contain a certain character and print them out

The following commands perform the required query: find -name "*c*" -type d starts with the current directory (no need to specify directory in case of current directory) -name "*c*" - with name ...
Yaron's user avatar
  • 744
32 votes

How can I find all files open within a given directory?

lsof has switches for doing this: lsof +d '/path/to/directory' (will list open files in the folder) lsof +D '/path/to/directory' (will list open files recursively)
5hack's user avatar
  • 421
32 votes
Accepted

'Find' in all opened documents in Notepad++?

Press Ctrl + F, and then click "Find All in All Opened Documents": Alternatively, you can press Alt + O (as the 'O' is underlined).
Attie's user avatar
  • 20.2k
31 votes

"FIND: Parameter format not correct" and "FINDSTR: Write error" with Pipes

I was able to directly do what I needed to do with this syntax: find.exe """Find This""" *.log With the TRIPLE double quotes, I think 2 of them get consumed by POSH, leaving the single quote for ...
user2526332's user avatar
27 votes

find / grep command without searching mounted shares

man find shows: -xdev Don't descend directories on other filesystems.
penguinjeff's user avatar
26 votes

Unix/Linux find and sort by date modified

I have a simple solution that works for both FreeBSD (OS X) and Linux: find . -type f -exec ls -t {} +
Alex Shchur's user avatar
26 votes
Accepted

find command cannot find my files which do exist

~/.config/fish/functions is a symlink. Therefore it's about [emphasis mine]: -P Never follow symbolic links. This is the default behaviour. When find examines or prints information a file, and the ...
Kamil Maciorowski's user avatar
23 votes
Accepted

How to get rid of fractional seconds in find using -printf?

You can truncate the fractional part using the %.n formatting syntax, where n is an integer specifying the length of the string you want to keep. In your particular case, the incantation would be: ...
Larssend's user avatar
  • 3,801
21 votes
Accepted

find: "-exec rm {} \;" vs. "-delete" - why is the former widely recommended?

tl;dr: -delete is not required by POSIX, -exec is. Facts POSIX 1003.1 man page for find specifies -exec but not -delete. This means -exec should work virtually everywhere. I would be surprised ...
Kamil Maciorowski's user avatar
20 votes
Accepted

Ack/Ag/Pt just list files?

With both ag and ack you just provide the -l flag. e.g. $ ag -l foo file.js file2.py
tom-james-watson's user avatar
15 votes
Accepted

unix find command on cmder.exe in windows

Simplest solution is to create an alias to the find executable within the cmder installation folder: λ which find /c/WINDOWS/system32/find λ find --help FIND: FIND: Parameter format not correct λ ...
simlev's user avatar
  • 3,852
14 votes
Accepted

How to find files within a size range?

find -iname "*.zip" -size +$((60*1024*1024))c -size -$((70*1024*1024))c Do NOT use the abbreviations 60M and 70M as this will also exclude all files of size greater than 69MB including 69....
user3338098's user avatar
14 votes

What does '{} \;' mean in the 'find' command context?

{} has absolutely no meaning to bash, so is passed unmodified as an argument to the command executed, here find. On the other hand, ; has a specific meaning to bash. It is normally used to separate ...
jlliagre's user avatar
  • 14.2k
14 votes
Accepted

How to remove extension from pathname passed as {} in `find -exec`?

There is no mechanism in find itself that allows you to get a substring from whatever is substituted for {}. Even adding a suffix (like you did: {}.aac) may not be supported. POSIX says: A ...
Kamil Maciorowski's user avatar
14 votes
Accepted

In bash, how to find all copies of a given file in particular directories?

If I issue find /a_long_path_2 /a_long_path_3 -size 12345c -iname \*.doc, the list I get is too large to check manually via diff. Automation is needed. Add -exec cmp -s /a_long_path_1/foo.doc {} \; -...
Kamil Maciorowski's user avatar
12 votes
Accepted

Appending new lines to multiple files

There are few issues. >> in your first command will be interpreted by your current shell as a redirection to a file literally named {}, unless it's quoted. *.ovpn may be expanded by shell ...
Kamil Maciorowski's user avatar
11 votes

Linux command to find files changed in the last n seconds

The simplest way to do this is: find . -name "*.txt" -newermt '6 seconds ago' The -mtime -60s option, mentioned in an answer, doesn't work on many versions of find, even in 2016. -newermt is a much ...
shivams's user avatar
  • 1,754
10 votes
Accepted

How do I pass combined commands to 'find -exec'?

You can use a complex shell command in the argument to exec by explicitly invoking a shell there. find . -type f -name "*.txt" -exec sh -c 'grep FirstKeyWord "$1" | grep SecondKeyWord' -- {} \; This ...
Eric's user avatar
  • 374
10 votes
Accepted

'find' utility does not output all files when using wildcards

It's because of shell globbing. Try: find . -name "*.exe" When not quoted, *.exe expands to all *.exe files in the current directory, unless there are none. It so happens you have just one such a ...
Kamil Maciorowski's user avatar
10 votes
Accepted

Subshell won't work as indented

Subshells, like variables, are processed before the whole command line is run. The $() is interpreted by your parent shell, not by 'find', and no special treatment is given to 'find -exec' as 'find' ...
grawity_u1686's user avatar
9 votes

Faster alternatives to "find" and "locate"?

For a find replacement, check out fd. It has a simpler / more intuitive interface than the original find command, and is quite a bit faster.
Keith Hughitt's user avatar
9 votes

Find directories containing a certain number of files

Terdon's answer is generally well illustrative of the right approach, however here's a slightly shorter answer which only uses find and bash (doesn't need ls, wc and awk), and can also deal with files ...
eatnumber1's user avatar
9 votes
Accepted

Recursively find files with specific hard link count

In find there is the -links primary: -links n The primary shall evaluate as true if the file has n links. (source) To find regular files that have a hardlink count of 1, use: find . -type f -links 1 ...
Kamil Maciorowski's user avatar
9 votes
Accepted

Using find in macOS terminal with regex

There are a couple of issues here. Firstly, as John mentioned, -name does sub-string matching with globs, you need to use -regex, and secondly, there are regular expression dialect incompatibilities. ...
Thor's user avatar
  • 6,613
8 votes

Is there any way of making Ctrl+f in Chrome use the selected text, as per Firefox?

Actually the feature is there, at least on Mac OS. It's called "Use selection for Find" and it's bound to ⌘+E. Press ⌘+E ⌘+G to highlight all words equal to the selected! Press ⌘+E ⌘+F ⌘+G to ...
caesarsol's user avatar
  • 440
8 votes

Faster alternatives to "find" and "locate"?

As of early 2021 I evaluated a few tools for similar use cases and integration with fzf: tl;dr: plocate is a very fast alternative to mlocate in most cases. (GNU) find often still seems to be hard to ...
Thomas Luzat's user avatar
8 votes

How to ignore certain filenames using "find"?

By using "-not" and "-and": find . -type f \( \ -not -name "${1}" \ -and -not -name "${2}" \ \) In one line: find . -type f \( -not -name "${1}&...
Alberto Salvia Novella's user avatar

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