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

learn more… | top users | synonyms

3
votes
2answers
2k views

find files not matching list of filename patterns

I find myself needing to find and identify extraneous files (out of about 900K files on a 2T drive). There are lots of files that I want to keep, and I have filename patterns for these known good ...
4
votes
2answers
2k views

recursive search for a pattern, then for each match print out the specific SEQUENCE: line number, file name, and no file contents

What I am after is almost exactly the same as can be found here, but I want the format "line number, separator, filename, newline" in the results, thus displaying the line number at the beginning of ...
2
votes
4answers
196 views

Recursively apply a command to modify all files in a directory

I have a command that reads a file, and outputs a modified version on stdout: ./convert /path/to/file How can I recursively apply this command to all files in a directory, and overwrite the ...
4
votes
4answers
268 views

Search mp3 collection for songs with a certain song length

How would I search a directory of mp3 files for songs between a certain length. Ex: findmp3 -min=03:00 -max=03:15 /music/mp3/ebm/ Would return all mp3 files in the emb/ directory having a song ...
1
vote
2answers
253 views

How to find certain files and move them to a new directory in the same command?

So I was looking around and all I have found is how to do this only if the directory is already made, which is this: find source -name '*.z' -exec cp {} destination \; But how can I make a new ...
2
votes
5answers
330 views

Delete all files in directories except those whose path are listed in a file

Given the following files: data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
0
votes
1answer
72 views

find /var/log/ -type f -name *.log doesn't return list of log files

Instead, it returns the following error: find: paths must precede expression: file1.log Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] ...
2
votes
1answer
330 views

ksh:Get files created on specific date in directory [duplicate]

I want get the files that were created on specific date in a directory > ll total 36 -rw-rw-r-- 1 tak tak 212 Oct 08 07:06 name.log -rw-rw-r-- 1 tak tak 494 ...
6
votes
3answers
113 views

Excluding . and .. from results in find and ls

Is there any way to prevent find and ls -l from listing . and .. in their results? I never care about seeing this result in the output, and it prevents me from effectively piping their output to wc -l ...
4
votes
1answer
431 views

How search for a file beginning with either a or z and ending with a or z?

I attempted find -name 'a*' 'z*' '*a' '*z' but it gave me the error code find: paths must precede expression: z* I know how to find files starting with a though z, or ending with a-z, but not ...
1
vote
1answer
243 views

find does not work on symlinked path?

If I run this command find $HOME/MySymlinkedPath -name "run*.sh" nothing happens, and gives no error ('MySymlinkedPath' is a symlinked path to another hard drive other then my $HOME one). These also ...
2
votes
2answers
231 views

Optimized way to list and delete files

I need to list and delete .php, .xml files. For this I am using find command. To list : find . -type f -name \*.php -print0 To delete : find . -type f -name \*.php -print0 | xargs -0 rm -r As I run ...
6
votes
2answers
594 views

How does this find command using “find … -exec sh -c '…' sh {} +” work?

@StephaneChazelas posted the following solution to this Q&A: Having some trouble using “find -exec {} +”. $ find . -iname "*.extension" -exec sh -c ' exec <command> "$@" <additional ...
4
votes
2answers
150 views

Find and differences between -perm /6000 and -perm /u+s

I have been trying to find setuid executables using a `one liner'. The line I first tried was: find / -perm /u+s -type f Then I found a line which is similar but gives different results: find / ...
1
vote
1answer
206 views

Brace expression does not work in find regex

I have two folders, CA01 and CA02 under current folder, foo: foo -+ | +-CA01 | +-CA02 When I type find . -regex ".*CA[0-9]+" -exec echo {} + Or find . -regex ...
5
votes
5answers
16k views

Why does find -mtime +1 only return files older than 2 days?

CentOS 5.9 I'm struggling to wrap my mind around why the find interprets file modification times the way it does. Specifically, I don't understand why the -mtime +1 doesn't show files less than 48 ...
4
votes
3answers
608 views

How to find a file with specific permission of a specific user?

How do I get a list of all the files which permission is "read and write" for a specific user. For example, when I go on the desktop of my mac, then right click on file "A", then "get info", then on ...
2
votes
4answers
400 views

Zgrep stop after first match when arguments are passed from xargs

I'm using this command to find patterns in zip files (similar to the one) suggested here http://superuser.com/questions/144926/unix-grep-for-a-string-within-all-gzip-files-in-all-subdirectories find ...
2
votes
1answer
159 views

Why is `find -name *.jks` not returning some files? [duplicate]

find . -name *.jks -print 2>/dev/null returns files of extension jks that do not have underscores as part of their name. Much to my surprise, I have just discovered that * does NOT substitute ...
0
votes
2answers
2k views

How can I find files and then use xargs to move them?

I want to find some files and then move them. I can find the file with: $ find /tmp/ -ctime -1 -name x* I tried to move them to my ~/play directory with: $ find /tmp/ -ctime -1 -name x* | xargs ...
3
votes
1answer
291 views

find multiple conditions with multiple execs

I'm trying to build a find command with multiple conditions that lead to multiple actions. It was suggested to me that I should use only one find command for efficiency. Here is what I have: ...
2
votes
4answers
2k views

How to delete directories based on `find` output?

I issue the following command to find the .svn directories: find . -name ".svn" That gives me the following results: ./toto/.svn ./toto/titi/.svn ./toto/tata/.svn How could I process all these ...
2
votes
2answers
77 views

open a file and copy the listed files to another folder

I have a file named file1.txtcontaining file names like below : filea.txt fileb.txt filec.txt I want to copy the files listed in file1.txt to another folder. What is the UNIX command to use? (the ...
7
votes
2answers
1k views

Find files that a user can not read?

I want to find files that a particular user will not be able to read. Assume the username is "user123" and they are in a group called "user123". I want to find files that, if they are owned by ...
2
votes
4answers
617 views

Scope of variables when calling function from find

In a bash script I define a function that is called from find. The problem is that the scope of variables does not extend to the function. How do I access variables from the function? Here is an ...
7
votes
3answers
4k 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 ...
2
votes
2answers
99 views

Filtering the result of the find command, so that it returns only directories

Is it possible to get only the results from find that are directory paths? Using find with some option, or using grep or some other utility the results are piped into as a filter? I thought something ...
0
votes
1answer
83 views

Problem with small bash script

I often run find in my code projects when I make a change somewhere and I have to find where it impacts other pieces of code, so I thought about writing a very small script to make this easier, call ...
5
votes
1answer
429 views

find -exec mv stops after first exec

While researching for this question: Find and move directories based on file type and date, I stumbled upon a problem of my own. First I created a bunch of directories with files in them: seq 10 | ...
3
votes
2answers
121 views

Exclude paths that make find complain about permissions

I need to generate a file list from a disk volume. Some of the directories (all hidden directories under the root directory) have strange permissions that causes find to complain. I try to exclude ...
1
vote
2answers
1k views

Find and move directories based on file type and date

I have a directory "New Movies" containing 200+ subdirectories "Movie Name (year)". The subdirectories "Movie Name (year)" contains a single video file (avi/mkv) and several related jpg/xml files. I ...
0
votes
2answers
465 views

Delete all files except certain subfolder [duplicate]

I want to recursively delete all files not accessed in a while in folder a, except all files in the subfolder b. find a \( -name b -prune \) -o -type f -delete However, I get an error message: ...
3
votes
1answer
490 views

find and rysnc?

I want to be able to search for files over 14 days and over 10k and than rsync those found files to a destination. Is there a way to combine these two commands? find ./ -mtime +14 -size +10k rsync ...
3
votes
1answer
208 views

Why does this one-liner clobber files?

I have written this to help me batch-encode some videos: find -name '*.mkv' -exec HandBrakeCLI -Z "Android Tablet" \ -c "1-3" -m -O --x264-tune film -E copy --decomb -s 1 -i {} \ -o `echo {} | tr ...
0
votes
2answers
144 views

The difference that quotation marks make in find command [duplicate]

When I have a nested directory find . -name "*.py" -print command gives me all the python scripts beneath current directory. However, find . -name *.py -print returns only the python scrips in current ...
1
vote
1answer
336 views

find and exec: why does this command not work?

I don't get why echo prints empty line (latest cygwin version): ~/tmp >find mydor/ -name "*php" mydor/es/c/packags.php mydor/etns/inx.php mydor/pacepors.php mydor/XAE.php ~/tmp >find mydor/ ...
5
votes
3answers
173 views

find all end subdirectories in a tree

given the following structure: oz123@debian:~/ $ tree . . ├── a │ ├── a1 │ ├── a2 │ └── a3 ├── a1 │ ├── a11 │ ├── a12 │ └── a31 ├── b │ └── b1 │ ├── b11 │ │ └── b21 │ ...
2
votes
2answers
994 views

Get list of all files by mask in terminal

I want to find all *.h,*.cpp files in folders with defined mask, like */trunk/src*. So, I can find separately *.h and *.cpp files: find . -path "*/trunk/src/*.h" find . -path "*/trunk/src/*.cpp" ...
3
votes
1answer
139 views

Variable declaration in parallel sh -c …

I've been trying to process the output of find with parallel, which in turn invoked a shell (some textual substitutions were needed). I observed some strange behaviour, which I cannot really explain ...
2
votes
3answers
4k views

How to find multiple strings in files? [duplicate]

I use the following command to find files with a given string: find /var/www/http -type f | xargs grep -iR "STRING1" But how can I find files which include "STRING1" OR "STRING2" OR "STRING3"? ...
3
votes
3answers
422 views

How to find file/directory names that are the same, but with different capitalization/case?

How can I list the file/directory names in a directory recursively that are the same, but with different capitalization/case? ex.: INPUT (not the ls command, the directories): [user@localhost ...
-1
votes
2answers
80 views

What's wrong with this tar command? [closed]

find /informatica/dev/SrcFiles* -mtime +7 -and -size +1M -exec tar -rvf files.8.2.2013.tar {} \; This command is running/working correctly and I'm not sure whats wrong. I want to find the files that ...
0
votes
2answers
102 views

find command and tar

find /informatica/dev/SrcFiles* -mtime +7 -and -size +1M -exec tar -cvjf> So I ran this command and I can't find the file after it was done running (probably because I never named it?). The ...
3
votes
3answers
963 views

How to find first match in multiple files

Is there a way for the find command to search for the first match or occurrence of a string or pattern within each of multiple files? I've been using the usual syntax: find dir -iname '*.ext' -exec ...
1
vote
2answers
103 views

find command help

I'm struggling using the find command that will allow me to find all files that were modified over 7 days ago and that are larger than 1 MB. Here's what I have - find /path/to/files* -mtime +7 | ...
3
votes
1answer
3k views

delete files matching pattern

I need to recursively remove all files in all subdirs where the filename contains a number followed by an 'x' followed by a number, at least two times. Example: I'd want to remove these files: ...
2
votes
3answers
154 views

mv files to a different path which is constructed via a regex replacement

I have a directory full of files stored in subdirectories according to their filename, i.e.: 20d1/d325/52d1/20d1d32552d1a95249e62662fbdf924dd72c4027.jpg ...
2
votes
1answer
73 views

find doesn't return expected files

I'm doing a search for files that contain ".anki" in their file name. root@t500:/home/some1# find / -name .anki /home/some1/.anki But there are other files in my home folder that contain .anki: ...
1
vote
0answers
23 views

find -exec {} vs. find -exec '{}' [duplicate]

I noticed in the man pages for find, that the {} always have single quotes around them. find -exec '{}' \; The description states: Notice that the braces are enclosed in single quote ...
2
votes
3answers
165 views

Find pattern and move

I'm wondering if anybody knows how to find a pattern and then move it to a different location. For example, I have many files named: odbc.ini_20110630 odbc.ini_20110639 odbc.ini_20110643 etc... I ...