66
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 /.
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 (for example if you are - like me at the moment - forced ...
38
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 ...
34
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 ...
29
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 ...
27
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).
26
votes
Exclude hidden files when searching with Unix/Linux find?
It seems negation glob pattern is not well known. So you can use:
find . -name "[!.]*"
26
votes
find / grep command without searching mounted shares
man find shows:
-xdev Don't descend directories on other filesystems.
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 ...
25
votes
Accepted
How to find and replace line(s) in multiple files using Notepad++?
Using Notepad++ to find a string on a line in a file, and replace that entire line with the match with another string
Instructions
Open Notepad++ and press
Ctrl+F and then from the Find in Files tab ...
24
votes
Accepted
Difference between '{}' and {} in find command?
For the bash shell, '{}' and {} are interchangeable. This is not be the case with all shells (such as fish).
Putting the argument in single quotes explicitly indicates that the curly braces should ...
21
votes
How can I find all files open within a given directory?
lsof has switches for doing this.
lsof +d 'directory' (will list open files in the folder)
lsof +D 'directory' (will list open files recursively)
21
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:
...
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
18
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 {} +
18
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 ...
16
votes
How to list all files in a Windows SMB network share
Try the command: smbclient //HOST/PATH -c 'recurse;ls' PASS -U USER
15
votes
How can I find files that are bigger/smaller than x bytes?
I think find might be useful alone without piping to AWK. For example,
find ~ -type f -size +2k -exec ls -sh {} \;
The tilde indicates where you want your search to begin and the result should ...
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
λ ...
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 {} \; -...
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 ...
11
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....
11
votes
Linux: How does file modification time affect directory modification time and directory access time?
Many questions, so I'm going to answer the "how does it work" part, not "how do I get this working."
This is dependent on the file system used. I'm answering based on ext[234], others probably work ...
11
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 ...
11
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 ...
11
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 ...
10
votes
Use of the "OR" Regex operator with the find command
Reading into the man page of find gives a bit of useful information:
The regular expressions understood by find are by default Emacs
Regular Expressions.
So, taking a look into the syntax of ...
10
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 ...
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' ...
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.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
find × 1032linux × 422
bash × 245
command-line × 160
unix × 118
grep × 91
macos × 73
shell × 62
regex × 60
search × 47
xargs × 46
microsoft-excel × 40
windows × 38
ubuntu × 36
shell-script × 26
find-and-replace × 26
sed × 24
microsoft-word × 22
exec × 21
terminal × 20
ls × 19
awk × 17
cp × 16
worksheet-function × 15
notepad++ × 15