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

learn more… | top users | synonyms

14
votes
2answers
892 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, ...
34
votes
8answers
48k 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 ...
6
votes
5answers
1k views

How to clean up file extensions?

I have a directories with .MP3 files which I'd like to change the extensions to .mp3. What's the easiest way to do this? I'm think something along the lines of: find /RootPath -type f -iname "*.mp3" ...
3
votes
1answer
2k views

Rename All Files with a Certain Name

I'm trying to find certain files with the name "stringx" and replace the name (but not the extension) with "stringy". So basically for stringx.txt and stingx.cs, I'd want stringy.txt and stringy.cs. ...
18
votes
3answers
6k 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 ...
4
votes
2answers
320 views

`find` with multiple `-name` and `-exec` executes only the last matches of `-name`

When I'm using find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt" it finds all the types of file. But when I add -exec at the end: find . -type f -name "*.htm*" -o -name "*.js*" -o ...
5
votes
5answers
3k views

Recursive rename files and directories

I'm using below command for fname in *; do mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ') done ..but it only rename in current directory. Lets say I have many directories, and each ...
8
votes
5answers
9k views

How to report number of files in all subdirectories?

I need to inspect all sub-directories and report how many files (without further recursion) they contain: directoryName1 numberOfFiles directoryName2 numberOfFiles
10
votes
5answers
5k 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 ...
7
votes
4answers
546 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"?
6
votes
4answers
416 views

How to use find to remove *.py~ and *.pyc files at once?

I want to cleanup a directory (and subdirectories) from each occurrance of the .py and .pyc files. I tried the following find . -name '*pyc' -o -name '*py~' -exec rm -f {} \; which left out all pyc ...
4
votes
1answer
1k views

Deleting files by age

Is there a command to delete all the files in a directory that haven't been modified in N days? I need to clean up some old logs.
29
votes
5answers
11k 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?
9
votes
3answers
8k 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 ...
11
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 ...
8
votes
3answers
1k views

How do I remove “permission denied” printout statements from the find program?

find: `/root/.dbus': Permission denied find: `/root/.gconf': Permission denied find: `/root/.gconfd': Permission denied find: `/root/.gnome': Permission denied find: `/root/.gnome2': Permission denied ...
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?
8
votes
4answers
6k 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 ...
19
votes
3answers
4k 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 ...
10
votes
4answers
3k 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 ...
5
votes
4answers
2k views

find not recursive when file at top

Imagine a source tree. There are xml files everywhere. But since there is a XYZ.xml at the root of this tree it won't find my xml files. find -iname *.xml returns ./XYZ.xml instead of ...
4
votes
5answers
2k views

How do I perform an action on all files with a specific extension in subfolders in an elegant way?

My current best bet is: for i in $(find . -name *.jpg); do echo $i; done Problem: does not handle spaces in filenames. Note: I would also love a graphical way of doing this, such as the "tree" ...
56
votes
6answers
18k 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. ...
9
votes
2answers
777 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 '{}' \;
6
votes
7answers
15k views

How do I find text within a file and have it search multiple subfolders?

I'm looking for a function name and the folder structure is deep and there are a lot of files to look though. Usually I go with something like find * | grep functionname but is that the best way?
26
votes
2answers
6k 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?
6
votes
3answers
13k views

Getting all files that have been modified on a specific date

Is it possible to find all php files within a certain directory that have been modified on a certain date I'm using find /var/www/html/dir/ -mtime -28 | grep '\.php' to get files modified within ...
8
votes
3answers
5k 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 ...
6
votes
4answers
464 views

Delete all files in a directory whose name do not match a line in a file list

I have a directory with 1000+ files. In a text file, I have about 50 filenames, one per line. I'd like to delete all the files in the directory whose filenames don't correspond with an entry on the ...
4
votes
3answers
2k views

Manipulate file name piped from find command

I'm relatively new to Bash and am trying to do something that on the surface seemed pretty straightforward - run find over a directory hierarchy to get all of the *.wma files, pipe that output to a ...
4
votes
2answers
773 views

Find recursively all archive files of diverse archive formats and search them for file name patterns

At best I would like to have a call like this: $searchtool /path/to/search/ -contained-file-name "*vacation*jpg" ... so that this tool does a recursive scan of the given path takes all files with ...
3
votes
4answers
2k views

How to move the files based on Year

I need to move files based on a year. I used the find command find /media/WD/backup/osool/olddata/ -mtime +470 -exec ls -lrth {} \;|sort -k6 but for this command to successfully execute i need to ...
2
votes
2answers
325 views

Web front-end to find/grep/ack

In my lab, we are trying to build a web that allows the user to enter queries for find, ack, grep on a specific directory. The web would return an HTML with a table of a list of clickable files (click ...
7
votes
1answer
1k 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 ...
6
votes
3answers
158 views

Find the top 50 directories containing the most files/directories in their first level?

How can I use find to generate a list of directories which contain the most numbers of files. I'd like the list to be from highest to lowest. I'd only like the listing to go 1 level deep, and I'd ...
6
votes
5answers
1k 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, ...
5
votes
3answers
9k views

Find files which are created a certain time after or before a particular file was created

I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created. If I go with find -newer, that means I'd have to create a temporary ...
5
votes
3answers
2k views

Colored FIND output?

Is it possible to get colored output from the find command? That is, in the path of each found item, directories are blue, executable scripts are green, et cetera? I'm using version 4.4.2 of GNU ...
4
votes
1answer
2k views

Why is my find not recursive?

I am running the following command, but it is not performed recursively: find . -name *.java I know there are java files further down in the current directory but it is performing the find on the ...
4
votes
4answers
134 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
4
votes
3answers
3k views

Use a shell variable to execute a comand

I have a unix command in a variable, it looks like this: cmd="find /path/to/webpage -type f | grep -v .svn | xargs grep $@" `$cmd` find: paths must precede expression Usage: find [-H] [-L] [-P] ...
3
votes
3answers
532 views

Concatenating thousands of files: > vs >>

I found two seemingly contradictory answers on StackOverflow to the following questions: Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure) How do I ...
1
vote
4answers
416 views

Recursively rename e-mail files from .txt to .eml

Directory "$d" contains a few thousand e-mail files with the .txt extension. To open them in my e-mail client, I need to rename them to .eml Will this command rename them correctly: find "${d}" ...
0
votes
0answers
108 views

How to use find command with wildcard when current directory contains a match? [duplicate]

Possible Duplicate: find not recursive when file at top I'm having some confusion with the find command. If I type: find . -name *.xml or find ./ -name *.xml I receive a list of all ...
17
votes
3answers
15k 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?
7
votes
2answers
10k 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
6answers
8k 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 ...
7
votes
1answer
6k 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
7answers
1k views

Open a file given by the result of a command in vim

I find myself doing the following almost every day Run a find (find -name somefile.txt) Open the result in vim The problem is I have to copy and paste the result of the find into the vim command. ...
19
votes
1answer
717 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 ...