Hot answers tagged

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 /.
pjammer's user avatar
  • 771
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 ...
friederbluemle's user avatar
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 ...
Gabriel's user avatar
  • 481
34 votes

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
  • 734
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 ...
user2526332's user avatar
27 votes

'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
  • 19.3k
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 "[!.]*"
reddot's user avatar
  • 398
26 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

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
25 votes

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 ...
Vomit IT - Chunky Mess Style's user avatar
24 votes

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 ...
Steven's user avatar
  • 27.6k
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)
5hack's user avatar
  • 311
21 votes

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,711
20 votes

Ack/Ag/Pt just list files?

With both ag and ack you just provide the -l flag. e.g. $ ag -l foo file.js
tom-james-watson's user avatar
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 {} +
Alex Shchur's user avatar
18 votes

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
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
Yezzo's user avatar
  • 161
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 ...
Tolani's user avatar
  • 263
15 votes

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,792
14 votes

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
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,704
11 votes

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
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 ...
Sami Kuhmonen's user avatar
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 ...
jlliagre's user avatar
  • 13.9k
11 votes

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
  • 386
11 votes

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
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 ...
sherrellbc's user avatar
10 votes

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
10 votes

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' ...
u1686_grawity'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

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