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

learn more… | top users | synonyms

3
votes
6answers
1k views

Make directory copies using find

I have a directory with a bunch of subdirectories in it. Thus /usr/local/src/ccl/ccl-1.8/x86-headers$ ls elf gl gmp gnome2 gtk2 jni libc Each of these directories has a further subdirectory C ...
3
votes
1answer
1k views

How to find files that contain newline in filename?

I am trying to find files that have a newline in the filename. But I can't figure out what pattern to use. The following works, but is not very useful if I want to use it in indented code. find . -...
2
votes
5answers
919 views

How to grep all xml files that do not begin with “<”

How can I find all xml files in the current directory and all sub directories, that do not start with < in the first line. I have tried this, but the grep doesn't work: find . -type f -name '*....
2
votes
1answer
771 views

How to find text in files and only keep the respective matching lines using the terminal on OS X?

I am pretty new to the terminal and command lines, from what I have found out grep seems to be the right tool for search files for specific text strings. I have a folder with many huge text files and ...
2
votes
2answers
3k views

find: combining -path and -prune to exclude files and directories

I have a directory /srv/tftp/pxelinux.cfg and a file /etc/mtab. I want to exclude both from find. But whatever I do, either one always is not excluded find /etc /srv -path /srv/tftp/pxelinux.cfg -...
2
votes
2answers
89 views

How to Find All .tex Files in Directories in Recurse Grep?

I want to expand the recursive search of symlinks to include only .tex files find . -type l -name "Math*" -exec grep -d "recurse" word {} +. Failed pseudocode 1 find . -type l -name "Math*" \ -exec ...
1
vote
1answer
68 views

Why getting these “Permission Denied”s in POSIX find-grep readable?

I do in Posix find $HOME +perm 0666 -type f -exec grep -l "XSym" {} \; but get this which I do not understand find: ‘/home/masi/.dbus’: Permission denied grep: /home/masi/.viminfo: Permission denied ...
1
vote
2answers
290 views

How does 'find -exec' pass file names with spaces?

If I have a directory containing some files whose names have spaces, e.g. $ ls -1 dir1 file 1 file 2 file 3 I can successfully copy all of them to another directory like this: $ find dir1 -...
0
votes
2answers
69 views

How to Do this List Comparison with Find?

I do and get a list of files where I would like to delete many duplicate backup files find . -type f -name '._*' I would like to find those files which have a corresponding filename /home/masi/....
0
votes
1answer
9 views

How to Limit ContentMatches of Grep in List? [duplicate]

I know the thread here which proposals (... | cut -c 80) however give single letter outputs like n r s t p. I do # http://unix.stackexchange.com/a/293147/16920 find -L $(find . -type l -name 'Math*')...
9
votes
2answers
6k views

find usage with -L

I have link -> file I do find -L . -name 'link' And get ./link Why is that? man find says: -L : Follow symbolic links. When find examines or prints information about files, ...
7
votes
3answers
1k 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 ...
6
votes
4answers
591 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...
4
votes
2answers
1k 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. ...
4
votes
2answers
739 views

Find and regex

What am I doing wrong with this find expression? ; touch ook ooks ; find . -name 'ook' -or -name 'ooks' -type f ./ook ./ooks ; find . -name 'ook[s]?' -type f [returns nothing] ; echo $? 0
4
votes
5answers
622 views

How to prepend a particular text file contents to every text file in a directory and its subdirectories?

I hate to clutter my source code files with licensing/attribution comments but some times it is a requirement. So having dozens of source code files (organized in a tree of subdirectories) written I ...
4
votes
3answers
816 views

Find files in directory with paired names

I'm running tests of a variable-size-and-contents test set. Data files are added and removed frequently. I'm looking for an automated way of gathering a file list. All files are in subdirectories of ...
3
votes
1answer
329 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 ...
3
votes
3answers
669 views

How can I exclude all “permission denied” messages from “find” in Solaris

Hi previous questions on this topic contain answers for Linux but does not work for Solaris 10. find . ! -readable -prune Does not work in solaris since -readable is not POSIX. What is the POSIX ...
3
votes
1answer
188 views

GNU Find this but not that and do Sed?

Code find /tmp/ -type f \ \( -name "*.h" \) -o \( -name "*.cpp" \) -o \ \( \! -name "*.bak" \) -exec \ sed -i '1s/^/#...
3
votes
1answer
130 views

Finding empty directories recursively

How can I find every empty directory, let's say, on the /home/.../Desktop. Because I am on Solaris, I can't use the find . -empty -type d command. Is there any other way?
3
votes
2answers
3k views

`find -path` explained

The find command provides the option -path. I understand that one has to define where to start looking [commonly known as "path"]. Trying to figure out what it is used for, I found many examples using ...
3
votes
2answers
1k views

Select greatest numbered filename

Simple requirement but can't find anything online which can achieve it. I have a list of dated files as below... filename_20120101.dat filename_20120102.dat filename_20120103.dat I ...
3
votes
5answers
4k views

Open file found with 'find' command

This is probably an easy one, but I can't figure it out and it's pretty much not searchable. In a folder hierarchy I have exactly one file of type xyz. I want to find that file and open it with a ...
3
votes
1answer
503 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 ...
3
votes
2answers
1k views

Create Zip for each subfolder but containing only matched files

I am trying to figure out how to create a zip file for each subfolder containing only files that match my criteria. For instance I have: Folder1 Folder2 Folder3 Each folder contains the same set ...
3
votes
2answers
383 views

rm not deleting file, thinks its a directory

I have a hard drive with windows loaded on it hooked up to my Linux machine for backing up some of the information. I want to delete one of the 'temporary internet files' folders and it deleted all ...
3
votes
4answers
2k views

Find the last occurence of a string in a given filetype in all subdirectories

I have multiple sub-directories each with different depths. I need to search for the last occurrence of a string in a specific file type (say *.out). How can I accomplish this? I have tried: grep -r ...
3
votes
5answers
5k views

Execute on the basename of a find command

Suppose I have a directory structure as follows test test/a test/b Now I want to execute a command, such that in the . folder I can execute a command on the basename of the files a and b. So ...
3
votes
2answers
3k views

How to search and replace strings matching a replacement list for multiple files

I have a file, say map.txt, containing a list of search strings and corresponding replacements: search -> replacement bigBone -> bb fishMarket -> fm dogCollar -> dc ... I need to ...
2
votes
1answer
173 views

find with -exec eval of $0 [duplicate]

In the following command I would like to know why $0 was evaluated to the file found by find and not the echo command. $ find . -type f -perm -u=x -exec bash -c ' /bin/echo $0 is the name of the ...
2
votes
3answers
161 views

Why are POSIX Find Parameters Different from Other Program styles?

Why is a parameter in the POSIX find command added with a single hyphen for multi-character parameter names, while most other programs use single hyphen to indicate multiple single-character flags, ...
2
votes
3answers
418 views

Find files that have a confirmed duplicate in same directory recursively

Say I have the following directory structure: root |-- dirA |-- file.jpg |-- file-001.jpg <-- dup |-- file2.jpg |-- file3.jpg |-- dirB |-- fileA.jpg |-- fileA_ios....
2
votes
2answers
1k views

comm fails on bash variable input

I have a script that's supposed to get the list of files of two directories, get differences and execute some code for certain files. These are the commands to get the file lists: list_in=$(find ...
2
votes
2answers
596 views

can regex capture groups be used in GNU find command?

With the GNU find command (GNU findutils 4.4.2), a regular expression can be used to search for files. For example: $ find pool -regextype posix-extended -regex ".*/mypackage-([a-zA-Z0-9.]+-[0-9]{1,2}...
2
votes
2answers
854 views

find all cpp files and list only those files with names that match a pattern (regex) does not work

I have a whole repository of files and I am trying to get a list of files that match a certain criteria. For example, let us say that I want to take all the files that have the string foo1 and foo2/...
2
votes
2answers
3k views

Use a parameter in a command argument

I run a find command to search files with a name containing perl: find /tmp -name '*perl*' /tmp/perl.pl /tmp/run-perl-stage.pl But when I set the perl name in a variable PARAMETER and run the find ...
2
votes
3answers
217 views

Find and rename files (including directories) whose filenames contain space [duplicate]

I have quite a number of files and directories with spaces in their filenames in my ext4 filesystems. How should I safely find and rename them? I have bash and am running Ubuntu. Is it possible ...
2
votes
2answers
2k views

Using find to list all files under certain directory

I'm trying to use a single line command that will find every directory (or sub-directory) named bin and will then print a list of all the files under it, but will not also list the directory names ...
1
vote
2answers
316 views

Does change of a file in a directory not change the time of the directory?

I want to find a file which I created recently, but I don't remember anything and can only guess it is under a directory indirectly with any possible depth. I inspected the times of all the ...
1
vote
1answer
50 views

Can I use Zsh's built-in wildcard matching to replace the use of `find` here?

This is a follow-up to another question I posted I use a script to automatically rename files according to a particular order: #!/usr/bin/env zsh pages=($(sed -n '/page_order/,/^$/ p' _config.yml | ...
1
vote
1answer
93 views

POSIX-compliant recursive grep with no errors for inaccessible directories

What script would allow me to grep a keyword and print the filename containing the keyword inside the file content, for example 'Carhart' inside all .sas files in all subdirectories? I tried something ...
1
vote
1answer
234 views

Using find -perm to find setuid files

I want to find list of all suid binaries. I use the command find / -perm 4000 However this does not give me any output. I understand that the SUID file may be in 4xxx permission mode. But if I ...
1
vote
2answers
1k views

Using exec in find over ssh from shell script

So, I am attempting to execute the following from within a shell script; ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit" When this runs, it ...
1
vote
2answers
3k 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 ...
1
vote
3answers
618 views

shell script for auto-touching files

I have written a shell script to touch all the files in the /tmp directory. However, there was an error message saying that /bin/touch: Argument list too long. What's the cause of the problem? #!/bin/...
1
vote
2answers
3k views

Cheapest way to find the oldest file (recursively) from a directory under heavy load

What is the least expensive way to find the oldest file in a directory, including all directories underneath. Assume directory is backed by SAN and under heavy load. There is concern that "ls" could ...
1
vote
1answer
691 views

Speeding a find rm command with test through parallelization

I want to recursively delete all files in directories and subdirectories with number of lines less than 10, and am currently using the following command find . -type f -name "*.txt" | while read; do ...
1
vote
4answers
293 views

Syntax error in a bash script that calls find

Where is the error in this script please: #!/bin/bash rep="git" files=`find' ${rep} '-type f` for f in ${files} do echo $f done When i run find git -type f alone in the shell, it works!
1
vote
2answers
94 views

how to delete (or keep) certain file extensions using busybox find?

I have a folder which contains files (various file extensions) and subfolders. I want to keep certain file extensions and delete the rest. e.g. keep all .txt and .jpg files and delete all other files....