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

learn more… | top users | synonyms

5
votes
2answers
599 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.
7
votes
2answers
1k views

sync files recursively between two folders where files are less than 24 hours old

I want to find all the files under a directory which are within 24 hours then rsync those files with another server. There are some old files that I do not want to transfer, however if those old ...
2
votes
2answers
703 views

Find: combine -depth with -prune to feed cpio

I'm building a backup script where some directories should not be included in the backup archive. cd /; find . -maxdepth 2 \ \( -path './sys' -o -path './dev' -o -path './proc' -o -path ...
5
votes
1answer
5k views

How can I use `find` and sort the results by mtime?

I want to use find but sort the results reverse chronologically as with ls -ltr. Is this possible through any combo of flags or pipelines?
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
2
votes
2answers
1k views

How to find every symbolic link on a server?

I need to find every symbolic link on the server. The version is AIX 6.1. man find says -L Follow symbolic links But find -L is not a proper usage. Usage: find [-H | -L] Path-list ...
3
votes
1answer
116 views

'find' across directories named …/dirnameXX/… with XX variable

I am executing this command to find certain files in specific directory: find ./rgs/test/maesXX/master/stdlist -name \*.extract \ -mtime +30 \! -size 0 -exec ls -lrt {} \; where XX could be ...
3
votes
1answer
82 views

What is the best way to find directories that exactly match a string irrespective of the path?

Suppose I have the directories: /foo/ /A/B/C/foo/D/E/ /F/foo/G/H/foo/I/ How can get a result that lists all the directories whose basename exactly matches a given string (for example foo in here)? ...
1
vote
4answers
353 views

What is this Bash line supposed to mean?

find . -name "*.html" -exec grep -l somethingtobefound {} \; I was just wondering what the keywords "-name" "-exec" "-l" "{}" "\" and ";" were supposed to signify. Also, I commonly see ...
4
votes
1answer
137 views

Why does find:s -or fail when I add a -print0 at the end?

I am writing a little script the modifies some movies in a directory tree, and I would like to parse that tree with a bash for loop or similar. So I started to find the files with find -iname ...
7
votes
3answers
9k views

How can I find all files that do NOT contain a text string?

What concise command can I use to find all files that do NOT contain a text string? I tried this (using -v to invert grep's parameters) with no luck: find . -exec grep -v -l shared.php {} \; ...
7
votes
1answer
2k views

List of modified files of the past 24 hours

Is there a reliable way to have a system that mails me the list of files that were modified in the past 24 hours inside a set of directories? (like /home/*/public_html/* and /home/*/*domains/*)
6
votes
4answers
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 ...
6
votes
6answers
297 views

Searching in many files

Is there some sophisticated technique to search strings in many files? I tried this basic technique for i in `find .`; do grep searched_string "$i"; done; It doesn't look much sophisticated and ...
7
votes
4answers
5k views

How can I run a specific command for each find result?

How would one run a specific command for each file that was found by using the find command? For the purpose of the question lets say that I would simply like to delete each file found by find. I am ...
5
votes
3answers
3k 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 ...
4
votes
6answers
1k views

Grep a directory and return list with line numbers

I'm currently trying to learn more about bash scripting and all of that fun stuff, and I pieced together this little command: find $path | xargs grep -n $pattern | awk '{print $1}' While this DOES ...
5
votes
2answers
5k 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 ...
2
votes
3answers
3k views

Use find and tar together

I have a directory with many log files, with filenames like acct.20111001 up to acct.20111030. I want to zip them by running: tar -cvjf acct.20111001.bz2 acct.20111001 How can I use find to ...
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. ...
2
votes
2answers
10k views

Finding files containing certain strings under a directory [duplicate]

Possible Duplicate: How do I find text within a file and have it search multiple subfolders? I would like to find out all the files under mydir/ directory whose content contains the string ...
7
votes
4answers
11k views

How to find a file in the filesystem from the command line?

I'm fairly new to Linux, and I've now found myself in a situation where I'd like to find where a file (with a partially-known filename) is in the file system. I'd like to know how to do this from the ...
2
votes
1answer
1k views

find command with -execdir not reading flags?

I am trying to locate all .jpg picture files in my current directory and sub-directories and move them to another directory. I want the source files to overwrite the destination files, but that is ...
7
votes
2answers
6k views

How do I stop a find from descending into found directories?

I'm wanting to find all directories with a specific string so I can do another find on the files contained within. So I don't want to waste time on ./my-search-term/dir/my-search-term etc. How can I ...
3
votes
3answers
3k views

create md5 hash from a recursive file listing when some paths have spaces

I need to create an md5 hash of every directory and file inside of one main directory. The only thing that is keeping me from success is figuring out a way around files with a space in the path. I am ...
4
votes
3answers
872 views

Delete matching file from every subfolder of current dir

I used this one to copy file in every dir: find -type d -maxdepth 1 -print0 | xargs -0 -n1 cp .htaccess Now i need to do reverse one and delete file with matching name from every sub directory of ...
2
votes
2answers
1k views

Ignoring files that find cannnot search or open?

I searched for big files using this command on HP Unix: find . -type f -size +100000000c -exec ls -lrt {} \; The result came out somthing like this: -rw-rw-rw- 1 qa1wrk32 test 169263642 ...
4
votes
1answer
871 views

Which order does find command use to print out

What order does the find command use to print out a list of files? Is this order different across different Linux distributions or versions?
2
votes
3answers
1k views

How can I find all ascii files under one directory that have the word shirt in them? Starting from root

What command would I use to find all of the files under the girl directory that have the ascii text “shirt” inside the files, starting from the root directory?
9
votes
6answers
11k 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
2
votes
2answers
4k views

How to exclude a list of full directory paths in find command on Solaris

(Duplicated from Stack Overflow: http://stackoverflow.com/questions/7854975/how-to-exclude-a-list-of-full-directory-paths-in-find-command-on-solaris) I have a very specific need to find unowned files ...
11
votes
5answers
4k views

case-insensitive search of duplicate file-names

I there a way to find all files in a directory with duplicate filenames, regardless of the casing (upper-case and/or lower-case)?
1
vote
1answer
803 views

Finding files by their owner and file permissions

I'm trying to find files which are owned and have the primary group of root. Is there a parameter available to search for files like this? It's critical that all files in a certain directory not be ...
2
votes
4answers
1k 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 ...
13
votes
3answers
7k views

Getting size with du of files only

How can I get the size of all files and all files in its subdirectories using the du command. I am trying the following command to get the size of all files (and files in subdirectories) find . ...
5
votes
2answers
3k views

Spaces as line breaks from inline for loop command

Someone care to enlighten me as to why the spaces in the first command seem to be interpreted as line breaks? Also occurs substituting print for echo. $for l in $( find *.txt -exec head -1 {} \; ); ...
1
vote
2answers
582 views

find -exec on zsh: echo works as expected, print doesn't

I thought the following two commands would output the same thing, but they don't: Command 1: find . -name filename -exec print '{}' \; Command 2: find . -name filename -exec echo '{}' \; ...
6
votes
4answers
8k 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 . ...
1
vote
1answer
336 views

Error creating an alias for the find command [duplicate]

Possible Duplicate: How to pass parameter to alias? I am trying to shorten the find command, but getting an error: $ alias f='find . -name $1 -print' $ f JobConf.java find: paths must ...
3
votes
1answer
6k views

Difference between ctime 1 and ctime +1 in find command

If I run the following command: find . -name "*.jar" -type f -ctime +1 I get no results back, whereas if i run: find . -name "*.jar" -type f -ctime 1 I get results.
3
votes
1answer
297 views

Copy files in different subdirectories that excludes a string

I'm trying to copy all files of a type in a given directory and subdirectories but excluding files of a different type. find /var/ftp/pub/bs -iname "*foo*.foo" -exec cp {} /var/ftp/pub/bs1 \; ...
7
votes
6answers
18k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
4
votes
4answers
583 views

Find files without a number

I am trying to write a simple script that will iterate through all drives except sda. Right now I have this for i in $(find /dev/ -name "sd*" ! -name "sda*") do echo $i done However this ...
13
votes
3answers
22k views

How can I grep the results of FIND using -EXEC and still output to a file?

Better to explain on examples. I can: find . -name "*.py" -type f > output.txt But how can I store the output to the same file for: find . -name "*.py" -type f -exec grep "something" {} \ I ...
2
votes
1answer
149 views

Need to find a cronjob

I have a problem, some user ,and I'm not sure who, on one of my servers wrote a cronjob that executes every night at midnight. The cronjob creates a sql dump of a database which is then grabbed by ...
5
votes
6answers
10k 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 ...
24
votes
2answers
13k views

How do I pass a list of files to grep

I am using find and getting a list of files I want to grep through. How do I pipe that list to grep?
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
865 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 ...