find is a command line utility to search for files in a directory hierarchy

learn more… | top users | synonyms

63
votes
7answers
22k 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. ...
38
votes
2answers
34k views

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.
36
votes
8answers
52k 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 ...
32
votes
3answers
5k 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?
32
votes
6answers
14k 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?
27
votes
3answers
7k views

How to stop the find command after first match?

Is there a way to force the find command to stop right after finding the first match?
25
votes
2answers
32k 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. ...
24
votes
2answers
12k 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?
23
votes
4answers
15k 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?
22
votes
3answers
5k 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 ...
19
votes
3answers
7k 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 ...
19
votes
3answers
20k 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?
19
votes
1answer
738 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 ...
19
votes
3answers
1k views

Find a file when you know its checksum?

I have the md5sum of a file and I don't know where it is on my system. Is there any easy option of find to identify a file based on its md5? Or do I need to develop a small script ? I'm working on ...
17
votes
3answers
7k 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 ...
16
votes
2answers
3k 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?
16
votes
1answer
16k 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 ...
15
votes
3answers
17k 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 ...
14
votes
4answers
13k views

Sorting the output of “find”?

I need to be able to alphabetically sort the output of find before piping it to a command. Entering | sort | between didn't work, so what could I do? find folder1 folder2 -name "*.txt" -print0 | ...
14
votes
4answers
14k views

How can I use bash's if test and find commands together?

I have a directory with crash logs, and I'd like to use a conditional statement in a bash script based on a find command. The log files are stored in this format: /var/log/crashes/app-2012-08-28.log ...
14
votes
2answers
996 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, ...
13
votes
5answers
910 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
3answers
7k 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 . ...
13
votes
3answers
6k 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 ...
12
votes
6answers
9k 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 ...
12
votes
3answers
529 views

Two find commands comparison

Recently I received this find one-liner, but I'm not able to explain where the difference of the below two comes from: Example 1 [root@centos share]# find . -exec grep -i "madis" {} /dev/null \; ...
12
votes
3answers
20k views

How can I grep the results of FIND using -EXEC and still output to a file?

Better to explain on examples. I can: find . -name "*.py" -type f > output.txt But how can I store the output to the same file for: find . -name "*.py" -type f -exec grep "something" {} \ I ...
12
votes
3answers
5k 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 ...
12
votes
4answers
9k views

Sorting files according to size recursively

how to scan a folder recursively and find the largest files in the folder, and sort them by size. I have tried using ls -R -S but it tends to list the directories as well I need to scan the folders ...
12
votes
2answers
12k views

Bash: How to read one line at a time from output of a command?

I am trying to read the output of a command in bash using a while loop. while read -r line do echo "$line" done <<< $(find . -type f) The output I got ranveer@ranveer:~/tmp$ bash ...
11
votes
5answers
4k views

Alternative to find?

Is there an alternative find program with a more conventional CLI interface? find works and expects parameters in a painfully different way from most other utils. Clarification: I'm looking for a ...
11
votes
2answers
2k 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 ...
11
votes
4answers
4k 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 ...
11
votes
5answers
3k 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 ...
11
votes
3answers
3k 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 ...
11
votes
5answers
4k 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)?
11
votes
2answers
895 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 ...
11
votes
1answer
399 views

How to do `head` and `tail` on null-delimited input in bash?

find command can output names of files as a null-delimited strings (if -print0 is provided), and xargs can consume them with -0 option turned on. But in between, it's hard to manipulate that ...
11
votes
2answers
2k 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 ...
10
votes
5answers
1k 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
3answers
9k views

How can I move files by type recursively from a directory and its sub-directories to another directory?

What would be a good way to move a file type from a directory and all of its sub-directories? Like "move all *.ogg in /thisdir recursively to /somedir". I tried a couple of things; my best effort was ...
10
votes
1answer
2k 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 ...
10
votes
5answers
6k views

How do I recursively grep through compressed archives?

I'm trying to find out what modules use Test::Version in cpan. So I've used minicpan to mirror it. My problem is that I need to iterate through the archives that are downloaded, and grep the files ...
9
votes
1answer
400 views

Find a file where name starts with a capital letter

I'm trying to find all files for which there name starts with a capital letter. I have tried using the following command: find . -type f -regex '.*\/[A-Z][^/]*' It's finding paths with only ...
9
votes
3answers
2k views

identify files with non-ASCII or non-printable characters in file name

In a directory size 80GB with approx 700,000 files, there are some file names with non-English characters in the file name. Other than trawling through the file list laboriously is there: An easy ...
9
votes
2answers
795 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 '{}' \;
9
votes
1answer
340 views

Is it possible to use `find -exec sh -c` safely?

I'm trying to use find to echo 0 into some files, but apparently this only works with sh -c: find /proc/sys/net/ipv6 -name accept_ra -exec sh -c 'echo 0 > {}' \; But using sh -c with find -exec ...
9
votes
2answers
2k views

How to detect whether “find” found any matches?

Is there an idiomatic means to detect whether "find" found any matches? I'm currently using COUNT=`find ... | wc -l` if [ "$COUNT" -gt 0 ]; then but this seems a little indirect to me. Also, I'd ...
9
votes
2answers
3k views

Finding all “Non-Binary” files

Is it possible to use the find command to find all the "non-binary" files in a directory? Here's the problem I'm trying to solve. I've getting an archive of files from a windows user. This archive ...
9
votes
1answer
5k 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 ...