find is a command line utility to search for files in a directory hierarchy
26
votes
6answers
4k views
How can I find broken symlinks
Is there a way to find all symbolic links that don't point anywere?
find ./ -type l
will give me all symbolic links, but makes no distinction between links that go somewhere and links that don't. ...
23
votes
2answers
15k views
How can I find files with certain extensions
How can I use find to find all files that have a .xls or .csv extension? I have seen a -regex option but I don't know how to use it.
17
votes
1answer
649 views
Why doesn't 'find' show this file?
Using find with grep, one can locate files that match a pattern:
# find | grep error
./solr-modifiedSolr4/SolrPhpClient/phpdocs/errors.html
./error_log
./includes/classes/error_log
However, using ...
17
votes
4answers
708 views
Howto find duplicate files on disk
Is it possible to find duplicate files on my disk which are bit to bit identical but have different file-names?
16
votes
7answers
20k views
Looping through files with spaces in the names?
I wrote the following script to diff the outputs of two directores with all the same files in them as such:
#!/bin/bash
for file in `find . -name "*.csv"`
do
echo "file = $file";
diff ...
15
votes
3answers
2k views
How can I use two bash commands in -exec of find command?
Is it possible to use 2 commands in the -exec part of find command ?
I've tried something like:
find . -name "*" -exec chgrp -v new_group {} ; chmod -v 770 {} \;
and I get:
find: missing ...
14
votes
3answers
2k views
How to use find command to search for multiple extensions
I can get all jpg images by using:
find . -name "*.jpg"
But how can I add png files to the results as well?
14
votes
2answers
698 views
How to stop the find command after first match?
Is there a way to make the find command to stop right after finding the first match?
13
votes
3answers
603 views
locate vs find: usage, pros and cons of each other
In Linux and Unix systems there are two common search commands: locate and find.
What are the pros and cons of each? When one have benefits over the other?
13
votes
2answers
8k views
Find command: how to ignore case?
I am looking for file "WSFY321.c" in a huge directory hierarchy.
Usually I would use GNU find: find . -name "WSFY321.c"
But I do not know the case, it could be uppercase, lowercase, or a mix of both.
...
13
votes
5answers
577 views
How to remove the (1) from filenames using the find command
I recently converted all of my FLAC files to a lower sampling rate of 44.1 kHz and bit depth of 24 bits (because iPhone/iPod don't support anything above that) using XLD on my Mac OS 10.7 (Lion).
...
13
votes
2answers
1k views
How to apply recursively chmod directories without affecting files?
After I apply chmod -R to a directory, permissions are changed for everything within (files and directories). How can I add execute/search (x) permissions to directories without modifying the files?
12
votes
3answers
517 views
How to combine 2 -name conditions in find?
I would like to search for files that would not match 2 -name conditions. I can do it like so :
find /media/d/ -type f -size +50M ! -name "*deb" ! -name "*vmdk"
and this will yield proper result ...
12
votes
2answers
2k views
How do I pass a list of files to grep
I am using find and getting a list of files I want to grep through. How do I pipe that list to grep?
11
votes
2answers
486 views
gnu find and masking the {} for some shells - which?
The man page for gnu find states:
-exec command ;
[...] The string `{}' is replaced by the current
file name being processed everywhere it occurs in the
arguments to the command, ...
10
votes
2answers
835 views
Why the dot in find commands?
Typically, one sees find commands that look like this:
$ find . -name foo.txt
when the search is to begin from the current directory. I'm finding that on my machines (Ubuntu, Cygwin) I get the same ...
10
votes
6answers
324 views
How to find files with 100% NUL characters in their contents?
What is the Linux command-line command that can identify such files?
AFAIK the find command (or grep) can only match a specific string inside the text file. But I want to match whole contents, i.e. ...
10
votes
5answers
2k views
case-insensitive search of duplicate file-names
I there a way to find all files in a directory with duplicate filenames, regardless of the casing (upper-case and/or lower-case)?
10
votes
2answers
1k views
bash find xargs grep only single occurence
Maybe it's a bit strange - and maybe there are other tools to do this but, well..
I am using the following classic bash command to find all files which contain some string:
find . -type f | xargs ...
10
votes
2answers
544 views
Tar up all PDFs in a directory, retaining directory structure
I'm trying to create a compressed tarball that contains all PDF files that exist in one of my directories. The directory structure needs to be retained. Empty directories are not needed, but I really ...
10
votes
1answer
4k views
How to skip “permission denied” errors when running find in Linux? [duplicate]
Possible Duplicate:
How do I remove “permission denied” printout statements from the find program?
When I run this command in Linux (SuSE):
find / -name ant
I get many error ...
9
votes
3answers
3k views
How to run find -exec?
I'd like to find the files in the current directory that contain the text "chrome".
$ find . -exec grep chrome
find: missing argument to `-exec'
What am I doing wrong?
9
votes
1answer
214 views
Only find first few matched files using find?
Say there may be hundreds of *.txt files in a directory. I only want to find the first three *.txt files and then exit the searching process.
How to achieve this using the find utility? I had a quick ...
9
votes
3answers
4k views
find exclude directory
I am on Linux (Ubuntu) and I am would like to exclude certain directories (like .hg) when I am doing a
find | less
I tried the following to exclude the .hg directory from listing, but does not ...
8
votes
6answers
2k views
How do I list every file in a directory except those with specified extensions?
Suppose that I have a folder containing .txt, .pdf, and other files. I would like to list the "other" files (i.e., files not having the extensions .txt or .pdf). Do you have any advice on how to do ...
8
votes
6answers
482 views
Best way run a command on each file in a directory tree
There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?
8
votes
2answers
264 views
How does `find . -name *foo*` work?
I thought the wildcard * in the command find . -name *foo* is replaced by bash, and yet the command works unless *foo* matches something in the current directory, then it doesn't. It's confusing.
8
votes
5answers
1k views
find searching in parent directories instead of subdirectories
I'm nested deep in a file tree, and I'd like to find which parent directory contains a file.
E.g. I'm in a set of nested Git repositories and want to find the .git directory controlling the files I'm ...
8
votes
2answers
591 views
What's the + in find /path/ -exec command '{}' + do?
What's the + in find /path/ -exec command '{}' + do? as opposed to find /path/ -exec command '{}' \;
8
votes
2answers
1k views
How to remove all empty directories in a subtree?
How can I remove all empty directories in a subtree? I used something like
find . -type d -exec rmdir {} 2>/dev/null \;
but I needs to be run multiple times in order to remove directories ...
8
votes
2answers
320 views
find usage with -L
I have
link -> file
I do
find -L . -name 'link'
And get
./link
Why is that?
man find says:
-L : Follow symbolic links. When find examines or prints information about files, ...
8
votes
1answer
2k views
What's the {} in find /path/ -exec command '{}' do?
I'm curious as to what the {} in the following command is actually for?
Example Command:
find /foo/ -name "*.txt" -exec rm -v {} \;
The Man page provided a small blurb but it confused me a little ...
7
votes
4answers
467 views
How can I find a file whose name includes a given string, such as “abcde”?
Within a set of directories, how do I find a file whose name includes a given string, such as "abcde"?
7
votes
4answers
974 views
Executing user defined function in a find -exec call
I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1).
The following code doesn't yield any result:
function foo {
echo "Hello World"
}
find somedir -exec ...
7
votes
3answers
2k views
Getting size with du of files only
How can I get the size of all files and all files in its subdirectories using the du command.
I am trying the following command to get the size of all files (and files in subdirectories)
find . ...
7
votes
2answers
425 views
Use find command to convert markdown files to html
Lets suppose I have files on my harddisk having extensions as .md.
I want to convert all those files to .html through find and the -exec option.
The command to convert a markdown file to html is
...
7
votes
2answers
818 views
How can you move (or copy) all files to a directory with the same filename prefix?
Using Bash
So let's say I have a bunch of files randomly placed in a parent directory ~/src, I want to grab all the files matching a certain suffix and move (or copy) them to a ~/dist directory.
...
7
votes
1answer
3k views
Solaris equivalent for depth/prune?
I am trying to find some files inside a directory. By default, the find command is searching the directory which I have specified and it's sub directories.
I tried to use depth/maxdepth and prune, ...
7
votes
1answer
283 views
Got less output with print0 option on find?
I have read the man page and other references, but I am still confused by the behavior of find with -print0 option.
-print0 This primary always evaluates to true. It prints the pathname of
...
7
votes
2answers
206 views
Search MP3/Ogg files by tags/parameters from the command line
Is there any utility to search MP3/Ogg files by tags (or other characteristics) from the command line? (e.g. finding all audio files longer than 10 minutes with genre set to 'Rock').
I found this, ...
7
votes
2answers
6k views
How to find binary executables within a directory
How do I list all binary executable files recursively within a directory?
I use find command like this:
find /mydir/mysubdir -executable -type f
All executable files are listed (excluding ...
6
votes
6answers
276 views
Searching in many files
Is there some sophisticated technique to search strings in many files?
I tried this basic technique
for i in `find .`; do grep searched_string "$i"; done;
It doesn't look much sophisticated and ...
6
votes
3answers
1k views
Find -exec + vs find | xargs. Which one to choose?
I understand that the -exec can take a + option to mimic the behaviour of xargs. Is there any situation where you'd prefer one form over the other?
I personally tend to prefer the first form, if ...
6
votes
4answers
3k views
Finding a substring in files across subdirectories with a single built-in command?
In Windows, if I wanted to find a string across all files in all subdirectories, I would do something like
findstr /C:"the string" /S *.h
However, in Linux (say, Ubuntu) I have found no other way ...
6
votes
3answers
4k views
Pipe find into grep -v
I'm trying to find all files that are of a certain type and do not contain a certain string. I am trying to go about it by piping find to grep -v
example:
find -type f -name '*.java' | xargs grep -v ...
6
votes
3answers
974 views
Make find show slash after directories?
How can I make the find command show a slash after directories? For example, I want dir to show up as dir/ instead of dir. I'm using find . -print
6
votes
2answers
461 views
sync files recursively between two folders where files are less than 24 hours old
I want to find all the files under a directory which are within 24 hours then rsync those files with another server.
There are some old files that I do not want to transfer, however if those old ...
6
votes
3answers
3k views
How can I find all files that do NOT contain a text string?
What concise command can I use to find all files that do NOT contain a text string?
I tried this (using -v to invert grep's parameters) with no luck:
find . -exec grep -v -l shared.php {} \;
...
6
votes
4answers
297 views
Find images by size: find / file / awk
I've been trying to find png image files a certain height (over 500px). I know that file will return image dimensions. Example:
$ file TestImg1a.png
TestImg1a.png: PNG image data, 764 x 200, ...
6
votes
1answer
1k views
List of modified files of the past 24 hours
Is there a reliable way to have a system that mails me the list of files that were modified in the past 24 hours inside a set of directories? (like /home/*/public_html/* and /home/*/*domains/*)
