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

learn more… | top users | synonyms

3
votes
3answers
32 views

How can I do a breadth-first search using `find`?

The -depth primary to find causes it to perform a depth-first search. However, the default sequence is not a breadth-first search. The default sequence could be informally described as a ...
5
votes
7answers
9k views

Sort the files in the directory recursively based on last modified date

Sort the files in the directory recursively based on last modified date I have modified a lot of files in my directory want to know what are those files by sorting them by the last modified date ...
2
votes
2answers
44 views

Delete directories that contain a certain file

I want to find all directories that contain a certain file and then delete those directories. With find . -name thatcertainfile -execdir pwd \; I get a list of all the directories I want to delete, ...
54
votes
5answers
30k views

Find duplicate files

Is it possible to find duplicate files on my disk which are bit to bit identical but have different file-names?
1
vote
2answers
30 views

Rename all the files with a specific extension in all the subdirectory [duplicate]

I have a lot of directories. Each one of these has a file with a specific extension .ext. I want to rename these files. Example: // Note: The names are random, can have spaces and special ...
3
votes
1answer
114 views

How to merge these commands into one?

This is what I am wanting to do: Convert a folder of HTML files into markdown, also copying over the the xml metadata of each of the HTML files by converting into YAML. I have done research and come ...
1
vote
4answers
60 views

Why is it find dir -name file and not find -n dir file?

I've searched around for this but I couldn't find anything on it. I've always wanted to know, why is it that most other built in bash commands have the format of command -flag arg1 arg2, i.e. cp -r ...
4
votes
1answer
36 views

`find` return value: Is the find man page wrong?

The find man page says: -execdir command {} + always returns true, while -execdir command {} ; returns true only if command returns 0. and EXIT STATUS find ...
19
votes
4answers
16k 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 ...
-4
votes
0answers
29 views

how to remove all folders but one with a script? [on hold]

i'd like to ask how to achieve this: i have an ubuntu server that takes backup every 48 hours.it creates a folder in a form like "26 04 2016". what i want to do? delete all folders EXCEPT one,in case ...
0
votes
2answers
26 views

Having trouble deleting specific directories within a specific parent directory

I’m using Amazon Linux, bash shell. I’m trying to write a statement that will delete all child directories named “target” within a specific master directory. I would like to write things such that ...
7
votes
7answers
4k 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 ...
2
votes
1answer
37 views

How do I search find files and compress if greater than 500M

I need to find files greater than 500M and older than 1 day and I need to compress those files. Also I need to omit files with .gz extension. How can it be achieved?
1
vote
1answer
37 views

Is there a standard abbreviation for 'find . -name foo' or do I need a function for this?

I recently used find . -name some-file-name a lot and decided that it's time to abbreviate this with a function (fb stands for find below): function fb() { find . -name "$1" } This seems to work ...
1
vote
1answer
14 views

How do I get a count of files in a directory (recursively) but exclude directories with a certain name

This is very similar to this question, but I need to take it a bit further. I'm using a synology drive and there are tons of @eaDir directories which I want to ignore (and the files in those ...
4
votes
6answers
2k views

Use mogrify to resize large files while ignoring small ones

I'm running the following command: mogrify -resize '400x400>' *.png Notice the ">". Supposedly it will ignore smaller files, but although it doesn't resize them, it edits them (modification date ...
13
votes
4answers
10k views

Executing user defined function in a find -exec call

I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1). The following code doesn't yield any result: function foo { echo "Hello World" } find somedir -exec ...
3
votes
3answers
59 views

Using grep/sort/find to extract unique values

I have a bunch of text files that are named in YYYYMMDD.Txt format (so today would be 20160420.Txt). Each file is basically a log that contains a timestamp and and a unique ID, each value is ...
3
votes
2answers
77 views

execute command from find called by find

Is there a way to call find recursively? I would like to search for files matching a given pattern only in directories matching another pattern. Basically: for each (sub)directory D matching ...
0
votes
1answer
52 views

Find not working

The find command is not working as expected on my OSX with oh-my-zsh. A few examples: $ find . -name test find: .: Invalid argument $ find usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... ...
1
vote
1answer
35 views

Rewrite a find command that uses sed -i for AIX

I have a script that searches for a string and replaces it via the sed command. If that string contains special characters, the script will escape them (except for the slash because it's my current ...
0
votes
0answers
17 views

To Open Find's resulted PATH by Click in Viewer?

I am trying to replace Finder/spotlight/mdfind in OS X because of false search of .tex files as discussed in the thread How to search LaTeX -documents in Spotlight? I do ...
2
votes
2answers
32 views

Instead of using ls, how does it make work with `find`?

I have this command: ls -Ra | grep -cve/ -e'^\.*$' and I would like to do exactly the same with find I tried this find . -name "^\.*$" -o -print | wc -l but the problem is, if I create new file ...
4
votes
3answers
343 views

What's the quickest way to find duplicated files? [duplicate]

I found this command used to find duplicated files but it was quite long and made me confused. For example, If i remove -printf "%s\n", nothing came out. Why was that? Besides, why they used xargs ...
2
votes
2answers
15 views

How to ignore passed directory in find command directory search?

I'm trying to perform the same process on all subdirectories. This should exclude the current directory, but I'm still matching on that and I don't know why. # Make a dummy file tree to test with ...
5
votes
5answers
509 views

Is it possible to run ls or find and pipe it through stat?

Is there a way to run ls or find to get the list of files within a directory and then run stat to get all of the specific information (i.e. File Group, File Name, File Owner, File Size (displayed in ...
0
votes
1answer
27 views

How could I quickly find a recursive symbolic link? [duplicate]

I am experiencing an issue with a indexing program running much longer than expected. I want to rule out the possibility of a recursive symbolic link. How could I find a symbolic link that is ...
0
votes
1answer
30 views

How to generate a text report in Linux?

I have a command I'm using to find all of the *.xml files on our server. I'm using: find -type f -exec grep -il "xml" {} \; This is great, but there are maybe a thousand files like this on the ...
1
vote
1answer
45 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ...
2
votes
5answers
9k 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 ...
0
votes
1answer
27 views

How do I count the number of files in all subdirectories and add the counts together

I am trying to count the number of file in each directory/subdirectory, add them together and get a total which I can then compare to another directory: #!/bin/bash echo "Checking directories for ...
2
votes
2answers
63 views

find: delete folder and sub folders but add exception to two files

I am trying to use the find command to do the following: Delete a whole folder with files, folders and subfolders except for 2 files, here is an example of what I need: test/folder1/file1.txt ...
-1
votes
1answer
22 views

Operator precedence in a find command?

See below example: $ ls -1p appledir/ applefile orangedir/ orangefile $ find . -type f -name apple\* ./applefile $ find . -type f -name orange\* ./orangefile $ find . -type f -name apple\* -o -name ...
7
votes
1answer
3k 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/*)
1
vote
2answers
46 views

Read files from directory and organize them by extentsion into corresponding folders

I'm trying to create a bash function script that will allow me to create multiple directories with the names below. I'm also trying to organize files by extension into their corresponding folders ...
1
vote
2answers
50 views

find all hard linked files between two directories

How do I find if any files among two or more directories are hard linked? In other words, do any files under two or more directories refer to the same file? Similar to How to find all hard links to ...
1
vote
1answer
43 views

Why does `find -size -1G` not find any files?

When I issue: find / \( -type f -size +10M \) -and \( -type f -size -1G \) I don't receive any results; however, when I type: find / \( -type f -size +10M \) -and \( -type f -size -1000M \) ...
1
vote
3answers
54 views

Is there a faster way to find specific files than using find?

I have to find in a folder the files not having certain permissions (755). The sub-directory has other sub-directories containing in total millions of files, and the find ./ -not -perm 755 command it ...
1
vote
4answers
217 views

Bash command help to “search and replace” file in changing directory tree

The Scenario: I've built a collection of files for research in a central repository on my server. I'm continually curating the repo changing the directory's tree structure by renaming and moving ...
0
votes
3answers
186 views

find -exec ls -lR {} \; returns every item twice

Background: I'm currently writing an archiving script, which creates gzipped tarballs from some folders and their contents. It should be able to synchronize the gzipped archives with the sources ...
0
votes
1answer
41 views

Why does 'find -mtime +1' include today's files when used in a script? [closed]

I'm using the following find command in a script: find . -type f -mtime +1 When I use it from an interactive shell, this gives only old files, but in the script it also gives today's files. Why? ...
3
votes
1answer
49 views

Limit POSIX find to specific depth?

I noticed recently that POSIX specifications for find do not include the -maxdepth primary. For those unfamiliar with it, the purpose of the -maxdepth primary is to restrict how many levels deep find ...
3
votes
2answers
312 views

Finding duplicate files by name ignoring the case in subdirectories

How is it possible to list duplicate file names on a Linux system ignoring the case including all subdirectories Files should not be compared by their content but only by their names. The output ...
0
votes
2answers
31 views

Create a list of files in a directory with a certain char

I would like to be able to list all files within a folder which have a certain character as the third character. For each file, I then want to be able to perform an action, maybe delete or move. ...
6
votes
4answers
1k views

Find recursively all archive files of diverse archive formats and search them for file name patterns

At best I would like to have a call like this: $searchtool /path/to/search/ -contained-file-name "*vacation*jpg" ... so that this tool does a recursive scan of the given path takes all files with ...
1
vote
1answer
28 views

Remove certain types of files except in a folder

I have a command in my makefile for clean: rm -rf */*.o */*.cmo */*.cmi */*.cmx */*.cma */*.cmxa */*.annot Now I would like to write a cleanpartial that removes these files except those in the ...
1
vote
1answer
30 views

Substitute with `…` multiline output of find command [duplicate]

I need to substitute output of find command to another command to process every found file, e.g.: mdls `find ~/target_dir/ -iname '*some*' -depth 1` (mdls is a command in OS X which get metadata ...
3
votes
2answers
88 views

Filter files generated by `find` by parsed output of `file` command

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command. ...
11
votes
1answer
2k views

Find a file where name starts with a capital letter

I'm trying to find all files for which there name starts with a capital letter. I have tried using the following command: find . -type f -regex '.*\/[A-Z][^/]*' It's finding paths with only ...
0
votes
0answers
6 views

Why find is not finding some folders with spaces?

find -name "* *" -type d | rename 's/ /_/g' For instance, 'Paired End' folder name on this path is not being replaced with spaces: ...