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

learn more… | top users | synonyms

6
votes
2answers
134 views

How can I substitute into this shell command?

I have a find command that I want to substitute a list of GIDs into. Here's the command: find / -follow \( -group 39 -o -acl_group 39 \) -exec ls -ln {} \; 2> $HOME/error.39.log 1> ...
6
votes
2answers
173 views

fastest way to grep jar file for a particular name in it?

I am trying to find all the jars which has spring in its name. I am working with windows and using cygwin to run the linux commands. Does my below command looks right? find . -name "*.jar" -exec jar ...
6
votes
2answers
560 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 ...
6
votes
2answers
185 views

du command show a slash after directories?

How to use du command show a slash after directories? For example: du -ab /root/test/php-5.4.8/ Result: 1781 /root/test/php-5.4.8/main/internal_functions.c.in 973596 ...
6
votes
1answer
472 views

tar: how can I exclude intermediate directories but include leaf directories?

I want to create a tar file suitable for extracting into /. I've created a work directory that represents the root of the file system, and it has all the stuff I want included in the tar underneath, ...
6
votes
1answer
66 views

Expected behavior of `find -depth` if execute permission denied for subdirectory?

I'd like to know if I can rely on the behavior I am seeing when using find with -depth option and user does not have execute permission for a subdirectory. Assume the following directory structure: ...
6
votes
4answers
175 views

“find: .: No such file or directory” while using find on the current directory

Find command seems not to work at all. For example, I'm in a directory where there absolutely is file named index.php and I execute this: [root@server htdocs]# find . -name "index.php" find: .: No ...
6
votes
2answers
651 views

Find files that were not installed by the package manager

I'd like to get a list of all files in my Gentoo Linux system that were not installed by the package manager (Portage). This is because I want to keep my system as clean as possible, removing all ...
5
votes
4answers
11k views

List the files containing a particular word in their text

I would like to list the files recursively and uniquely that contain the given word. Example: Checking for word 'check', I normal do is a grep $ grep check * -R But as there are many occurrence ...
5
votes
5answers
13k 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 ...
5
votes
4answers
981 views

recursively chmod

I was trying to chmod folders and files with: find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; But I was wondering: How to do it in one line using find and excluding the ...
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 ...
5
votes
6answers
223 views

Use find to find certain directory and delete all files in it except one directory

I'm having the following problem. I have a directory structure and want to delete everything that is within a directory named Caches. Everything should be delete except all directories named ...
5
votes
2answers
4k views

how can I recursively delete empty directories in my home directory? [duplicate]

Possible Duplicate: How to remove all empty directories in a subtree? I create directories very often, scattered over my home directory, and I find it very hard to locate and delete them. ...
5
votes
3answers
168 views

How do I remove every file that has x in its title?

I have a lot of directory where there are hundreds of files. In every directory there are pairs of my_file-01.jpg and my_file-€01.jpg I want to remove every file that contains € sign in its title: ...
5
votes
2answers
232 views

Collect files using find

I currently have this script: find . -name '*.log' -print0 | xargs -0 tar zcf $file To collect all the "*.log" files. I would like to modify it to include also all the ".txt" files but I don't know ...
5
votes
4answers
3k views

find-command for certain subdirectories

Let's say I have a directory dir with three subdirectories dir1 .. dir3. And inside I have many files and other subdirectories. I'd like to search for a file inside, say with a *.c ending, but I'd ...
5
votes
3answers
386 views

Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can ...
5
votes
3answers
2k views

How store in a variable a file list that includes the backslash when needed?

Main question: I am writing a script to perform a backup. I make a list of files in the following way: LISTOFFILES=$(find ~ \( -name '*.[pP][dD][fF]' -o -name '*.[oO][dD][tT]' \)) The variable ...
5
votes
4answers
6k views

List symlinks in current directory?

This question talks about finding directories in a current diretory. The solution is basically: ls -d */ That's great but how can I easily list symlinks? Do I have to use something like find . ...
5
votes
3answers
3k 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 ...
5
votes
1answer
152 views

find usage - command line vs script

I am seeing different results from the find command between being run manually on the command line vs run in a script. If I run the following on the command line: find . -name '*.txt' ! -name ...
5
votes
2answers
490 views

How to make `find` output full absolute file names?

When I run find, it outputs relative (./-based) file names, but I need full absolute (/-based) names.
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 ...
5
votes
2answers
63 views

Where does the pattern occur in a match by find?

The manpage of find says: -name Base of file name (the path with the leading directories removed) $ find ~ -name bookmark | less returns nothing, while $ find ~ ...
5
votes
5answers
2k views

Faster way to delete large number of files

I have a directory where lots of cached files are getting generated very quickly. Since these are very small files, it is consuming all my inodes very quickly. Currently I am running the following ...
5
votes
2answers
1k views

Excluding a specific directory using a recursive 'ls'

I've been using the following command to list the most recently updated files (recursively) within a specific directory and order by modification time: $ stat --printf="%y %n\n" $(ls -tr $(find * ...
5
votes
3answers
714 views

Use find result without ./

I'm trying to use find to create a bunch of symlinks but using the result with {} includes ./ before each filename. How can I avoid that? find . -type l -name '*.h' -exec ln -s /sourcedir/{} ...
5
votes
2answers
1k views

Reformatting a large number of XML files

I'm manipulating a large number of XML files scattered throughout a nested directory structure. I tried the following (which almost works): $ find . -name "*.xml" -type f | xargs -- xmllint --format ...
5
votes
3answers
1k 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 ...
5
votes
3answers
1k 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
3answers
140 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 ...
5
votes
3answers
8k 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
2answers
2k views

missing argument to find -exec

I want to remove certain files using find and -exec. But unlikely bash tells me, that I'm "missing" some argument. find . -name *.png -exec rm {} /; what do I miss? same "missing argument" return ...
5
votes
2answers
1k views

Find command: Searching for executable files

What type of parameter/flag can I use with the unix find command so that I search executables? (if this question is better suited for another stackexchange forum, I welcome you telling me so) p.s. ...
5
votes
5answers
2k views

Delete all folders containing files which match pattern

I'm trying to delete all subdirectories of my current working directory which contain a rar file. My first attempt: find -name *.rar -exec rm -r {}/.. ';' failed because that is not a valid ...
5
votes
5answers
8k views

List files larger than {size} sorted by date

I want to solve the problem 'list the top 10 most recent files in the current directory over 20MB'. With ls I can do: ls -Shal |head to get top 10 largest files, and: ls -halt |head to get top ...
5
votes
4answers
3k 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 ...
5
votes
3answers
162 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 │ ...
5
votes
2answers
4k views

Looking for a Java class in a set of JARs with find, unzip, grep

I was trying to find the JAR containing a Java Class. JARs are in zip format. My first attempt was: $ find -name "*3.0.6.RELEASE.jar" | xargs -l1 unzip -l \ | grep stereotype.Controller ...
5
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
150 views

Mac OS X find/grep generating “unknown --devices option”

I am entering a command I have done often with Linux, Unix perfectly fine but with Apple Mac OS X 10.8 (and probably before) I get a grep: unknown --devices option when I attempt to run the following ...
5
votes
2answers
489 views

Find/ls caching

It seems as though the first time I run find or ls on a directory, it takes a while to work. But, each time thereafter, it is fast, as though a list of the directory's contents has been cached or ...
5
votes
1answer
953 views

Exclude directory in find

How can I find every file and directory matching a pattern, excluding one directory using find? Say I have the following file structure; . foo-exclude-me/ foo.txt foo-exclude-me-not/ ...
5
votes
1answer
409 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 | ...
5
votes
1answer
690 views

find . -size -1GB in Centos

In Centos, I have a text file in my home directory. The command find . -size -1M doesn't show my file but find . -size -1000k does show it. This problem just seems to be happening when I use the ...
5
votes
2answers
764 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 ...
5
votes
1answer
2k views

How to find files not of a certain type?

I'm trying to find out all of the different types of files in my unorganized music folder. I've been trying this command (to list files of types besides the ones I know are in there): find ...
5
votes
1answer
43 views

Can “find” command preserve access-time

I'm running the following command which is supposed to find specific directories according to their Access-Time metadata detail however for some reason the find command changes the access time of ...
5
votes
2answers
717 views

POSIX find all local files

I'm trying to write a cross-platform command line that will find all local files on a file system. My intention is to use the find command, using only POSIX parameters. Is there a way to skip ...