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

learn more… | top users | synonyms

7
votes
2answers
2k views

recursively change file permission but not directories?

I was doing a mass recursive change of permissions of some files that I had migrated to a unix system. I changed them to ug+rw, but then I found that I could not traverse subdirectories. I looked at ...
5
votes
3answers
2k views

recursively copy only images and preserve path

I'm working on a website migration. I have a scrape of the site, with all the files and directory structure as you would see them in the URL. I want to pull all images, maintaining the directory ...
5
votes
2answers
867 views

Delete files while excluding files using find

This command is not DWIM-compliant: find . \( -name .svn -prune -false \) -o \( -empty -delete \) find: The -delete action atomatically turns on -depth, but -prune does nothing when -depth is ...
3
votes
3answers
2k views

executing multiple greps in a single find command

I want to use find command to find some files containing multiple patterns at the same time. I tried something like this: find . -name "*.xml" -exec grep -iH keyword1 + && grep -iH ...
8
votes
3answers
2k 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 ...
0
votes
1answer
235 views

Listing only the files in a folder and inside its subfolders

Is there a linux command for getting only the files in a folder and inside its subfolders? I have used the find command, but it is displaying all the files and folders. I am executing this shell ...
4
votes
3answers
9k views

list the timestamp of the files in “find” command

In bash, if I use $ find ./ -name "*.sqlite" , it will list all the sqlite files in current directory. I also want to see the modified time of the files, can anybody give me some help?
3
votes
2answers
1k views

How to search for a string only in textfiles? (recursively)

I can list all the textfiles (by mimetype) in a folder with: find . -type f -print0 | xargs -0 file -i | fgrep -i text | sed 's/:$//g' 2>/dev/null | awk 'BEGIN {FS=": "} {print $1}' Ok. But how ...
5
votes
4answers
4k views

Recursively rename files and directories

I'm using this command to rename files: for fname in *; do mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ') done But it only renames in the current directory. Let's say I have many ...
3
votes
4answers
2k views

rename character “â” of directory name?

I'm trying to rename rename character â of directory name to be blank. For example, directory with name how-â8093-to. This is the command I use, including some other modification find . -type d | ...
7
votes
1answer
7k 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, ...
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 ...
7
votes
3answers
1k views

Is it possible to nest a 'find -exec' within another 'find -exec'?

Something like the following is what I what I'm after, but my code doesn't work, no matter how I escape {} and + ; find ./ -maxdepth 1 -type d -name '.*' -exec \ find {} -maxdepth 1 -type f ...
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 ...
4
votes
2answers
6k views

How to list ALL directories according to their size? [without including the parent directory]

I have a bunch of random folders, some of them are hidden (beginning with a period). I want to list all of them, sorted by their sizes. I have something on the lines of this in mind: ls -d -1 -a */ ...
3
votes
2answers
1k views

Script to find files with a specific extension but NOT containing specific text

I am trying to write a script that basically searches recursively using find (or another method to) to find all files ending with *.p or *.w but does not contain sysvars.i or preprocess.i I am new to ...
7
votes
4answers
575 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"?
8
votes
2answers
389 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.
3
votes
2answers
3k views

How to find a writable file owned by root?

How can I find a file on my hard drive created by root that has write permissions?
2
votes
4answers
5k views

Deleting Lines Containing a Specified String in Different Files

Suppose there are two files in web/ named foo.php and bar.php. The 1st line of foo.php is "sdajgeSTRINGdsad" and the 10th line of bar.php is "gdfhu98324STRING". The task is to first locate these two ...
5
votes
3answers
811 views

Recursively Remove SVN files

I'm still learning the bash shell. I want to recursively find and remove svn files within the child directories of a given folder. I made the mistake of checking out instead of just cloning. So i'm ...
3
votes
3answers
367 views

How to grep recursive UNIX tree results along with each tree node?

Here is what I do tree -R /Applications/NetBeans/NetBeans\ 7.0.app/ | perl -e 'while (<>) { print if /java$/ }' but of course this doesn't return the result I want. What I want is to display ...
3
votes
2answers
675 views

Remove slashes/parent paths from filenames inside CSS and Javascript content

I need to go through all my css and js files and if there is a filename referenced that has any slashes (/) at all then the slash should be removed. What I want is: if any files referenced are ...
0
votes
1answer
284 views

which and find not working to locate ruby.exe path

From the home directory which ruby.exe & find ruby.exe return "no such file or directory" However, I'm able to execute .rb programs in rubymine.
1
vote
2answers
1k views

Delete files recursively that DON'T match regexp

I'm attempting to clean out a bunch of temporary files from a folder tree, but don't want to delete files that match some criteria, specifically executable files, .tpl files, and not the subfolder ...
23
votes
4answers
16k 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?
2
votes
3answers
203 views

How to find every file that includes a given function?

I am trying to list all of the files that include a function, e.g., matrixCal. How can I to do this in linux?
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 ...
4
votes
2answers
840 views

Why is bash completion of a symlink different than a directory?

I usually do a find with an environment variable as the path when searching for source code. Recently I replaced my environment variable with a symbolic link, and it broke Bash's shell completion. ...
3
votes
3answers
211 views

Use find to execute series of commands

I want to examine a directory and execute a command for each matching folder. The following find correctly returns the list I'm looking for. find . -maxdepth 1 -name "*.bitbucket" For each item ...
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 ...
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 ...
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 ...
4
votes
3answers
5k views

How to find files in subdirs and sort them by filename in a single command?

Result of a normal find using find . ! -path "./build*" -name "*.txt": ./tool/001-sub.txt ./tool/000-main.txt ./zo/001-int.txt ./zo/id/002-and.txt ./as/002-mod.txt and when sorted with sort -n: ...
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 ...
7
votes
3answers
2k views

Is there a way to find a file in an inverse recursive search?

So say I'm in a directory that is deep within a file structure, such as /home/cory/projects/foo/bar/bash/baz I know that in either the current folder baz or one of the folders above me (such as ...
3
votes
2answers
955 views

Find files with same name but different extensions, send to tgz

I have a large archive of edited images from my camera, each image is actually a pair of files - *.nef & *.xmp. I would like to go through all the folders and then zip these pairs into single tgz ...
2
votes
1answer
112 views

Script for opening corresponding pdfs for bibtex keys in Vim

Context I currently write research articles in LaTeX using Vim. I have bibtex keys in my articles like \cite{smith2000sometopic} and I have corresponding pdf versions of most articles in a subfolder ...
2
votes
1answer
46 views

Explain the output of -D rates in GNU find

I did ~/pythonsource1/python2.6-2.6.5$ find -D rates . -type d and got Predicate success rates after completion: [need type] -type d [0.4] [280/4350=0.0643678] -a [0.4] [280/4350=0.0643678] ...
6
votes
5answers
4k views

How to copy all html files from a directory tree to a single directory?

I want to copy all the .html files in myDir and its subdirectories to ~/otherDir. Here's what I tried (it doesn't work): $ find myDir -name *.html -print | xargs -0 cp ~/otherDir usage: cp [-R [-H | ...
6
votes
1answer
2k views

list files by symlink target

How do I get list of files (and then do something with that list) by filtering through the symbolic link target name, and not the symlink name? For example from the following list I'm only interested ...
22
votes
3answers
22k 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?
5
votes
4answers
4k views

Is it possible in unix to search inside zip files

I have 100s of directories and within those I have a few zip files. Now there are images named abc.jpg in those zip files. The zip files may be in any folder or in any subfolder so its difficult to ...
6
votes
5answers
5k views

How do I find which files are missing from a list?

I have a list of files that I want to check if they exist on my filesystem. I thought of doing this using find as in: for f in $(cat file_list); do find . -name $f > /dev/null || print $f done ...
7
votes
5answers
16k views

How copy and rename files found in “find” function Linux?

I have a folder named /home/user/temps which has 487 folders. In each folder I have a file called thumb.png. I want to copy all files named thumb.png to a separate folder and rename them based on ...
1
vote
0answers
90 views

How to search for file contents [duplicate]

Possible Duplicate: Finding a substring in files across subdirectories with a single built-in command? I know that I can use grep for a single file, but what about a whole directory tree?
2
votes
3answers
3k views

How can I loop through lines of a file and find files matching each line?

In a BASH shell, I would like to take the lines of a file (eg pattern.txt) and find the files on my system whose names contain the patterns in each line of my file. So, I have the following for loop ...
4
votes
2answers
758 views

find arcana: can't get pipe to work in -exec line

How do I pipe the results of a find through a sed to xform the stream, and then use that transformed stream as one of two arguments to a script? IE: find turns up file1.tiff (among others) sed ...
1
vote
3answers
984 views

A problem with find and grep

I have defined the following alias in ~/.bashrc: alias fg='find . -name $1 | xargs grep --color $2' in order to write fg "*.txt" " my_text " and find all file that have extension .txt and ...
38
votes
8answers
53k 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 ...