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

learn more… | top users | synonyms

5
votes
1answer
95 views

find -maxdepth 0 not returning me any output

I am trying to understand how to use find -maxdepth 0 option. I have the below directory structure. --> file1 --> parent --> child1 --> file1 ...
5
votes
3answers
217 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
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?
5
votes
3answers
240 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
620 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
2k 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
3answers
3k views

find files which have a higher permission than xxx

I want to find all files which have a higher permission than e.g. 640. Perhaps this would work with a find and exec command. But my knowledge isn't sufficient for such a task.
5
votes
1answer
63 views

find directories not containing a file

How can I use the find command to locate directories that do NOT contain a particular file? E.g., if I have bunch of directories that should be under revision control, can I search and find the ones ...
5
votes
1answer
487 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
866 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
830 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
2answers
494 views

Finding all large files in the root filesystem

I have a linux server, which currently has below space usage: /dev/sda3 20G 15G 4.2G 78% / /dev/sda6 68G 42G 23G 65% /u01 /dev/sda2 30G 7.4G 21G ...
5
votes
1answer
52 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
4answers
3k views

Preserve directory structure when moving files using find

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
5
votes
2answers
976 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 ...
5
votes
1answer
206 views

Execute multiple bash commands on the output of find

I want to execute some commands using the find -exec option, but I'm not sure what' wrong with this code. Currently, it's only processing the first find result, then getting stuck. I'm using bash in ...
5
votes
1answer
201 views

How can I synchronize all PDFs from one directory with Dropbox?

I want to synchronize all the PDFs from one directory (my Zotero library) to Dropbox. Finally, I want to have a list of all the PDFs, not the directory names. I successfully synchronized all my PDFs ...
4
votes
6answers
2k views

Get a list of directory names with find

I know I can do this to get a list of directory names: find . -type d -maxdepth 1 The output looks like this: . ./foo ./bar I prefer the listing without ./. Is there a way to get find to output ...
4
votes
3answers
373 views

Using find command to find folder ignoring case

I would like to know if a particular folder is present or not. I used the following command find /mnt/md0/ -maxdepth 1 -name 'dcn'||'DCN' I want to know if folder name is DCN or dcn . How would I ...
4
votes
2answers
402 views

`find` with multiple `-name` and `-exec` executes only the last matches of `-name`

When I'm using find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt" it finds all the types of file. But when I add -exec at the end: find . -type f -name "*.htm*" -o -name "*.js*" -o ...
4
votes
1answer
3k views

Why is my find not recursive?

I am running the following command, but it is not performed recursively: find . -name *.java I know there are java files further down in the current directory but it is performing the find on the ...
4
votes
2answers
669 views

How to I scan using find for all files that do have execute bit set?

I want to write a permission fix script that uses find to fix permissions on files. Mainly what I need is a find command that is able to list all files with execute bit set, regardless of the other ...
4
votes
6answers
1k views

ls with find :: report total size

I am trying to get the total size of files satisfying a find, e.g.: ls $(find -maxdepth 2 -type f) However, this kind of invocation of ls does not produce the total size as well.
4
votes
1answer
4k views

delete files matching pattern

I need to recursively remove all files in all subdirs where the filename contains a number followed by an 'x' followed by a number, at least two times. Example: I'd want to remove these files: ...
4
votes
2answers
1k views

How to search for files by size and extension ?

I want to delete all empty files with a particular extension from a directory and all its subdirectories.
4
votes
4answers
230 views

Locating files and displaying their owner

I have to search for a specific file type on a storage unit and also want to know their owners. With locate '*.txt' >> result.txt I find all files I'm looking for but I'm missing the owner this ...
4
votes
4answers
144 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
4
votes
2answers
608 views

Append line to many files

I want to add some text to over 200,000 files I am trying this find . -name *.txt -print | xargs -I % echo "hello world" >> % But nothing is happening. When i run find . -name *.txt it work ...
4
votes
2answers
222 views

Why 2 linux machine behave differently with command of the same syntax?

I am using 2 machine , which is both Red Hat Enterprise Linux AS release 3 (Taroon Update 2) ( I check it in /etc/*-release ). I checked they are using the same default shell by ps -p $$, which is ...
4
votes
3answers
8k 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?
4
votes
2answers
435 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
3answers
4k 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: ...
4
votes
3answers
126 views

Finding files on a Unix server and sorting by size

I have a web server where I have run out of space and it's causing issues with the WordPress sites I am running on them. I know that I have a lot of large .png files (the fact that it's PNG is a ...
4
votes
4answers
2k views

What is the most efficient way to move a large number of files that reside in a single directory?

CentOS 5.x I apologize if this is a repeat question. I've seen a lot of similar questions (regarding deleting files) but not exactly the same scenario. I have a directory containing hundreds of ...
4
votes
4answers
2k views

Remove numbers from filenames

I've a problem modifying the files' names in my Music/ directory. I have a list of names like these: $ ls 01 American Idiot.mp3 01 Articolo 31 - Domani Smetto.mp3 01 Bohemian rapsody.mp3 01 Eye of ...
4
votes
2answers
115 views

Linux splitting array into separate variables

I've been programming on MVS for years and recently have been using Linux so my Linux skills are not that great yet but I understand development concepts well. What I'm trying to do is to read a ...
4
votes
3answers
1k views

How to find first match in multiple files

Is there a way for the find command to search for the first match or occurrence of a string or pattern within each of multiple files? I've been using the usual syntax: find dir -iname '*.ext' -exec ...
4
votes
3answers
2k views

bash - can I do : find … -exec this && that?

Is there a way to logically combine two shell commands that are invoked with find - exec? For instance to print out all the .csv files that contain the string foo together with its occurrence I would ...
4
votes
5answers
3k views

How do I perform an action on all files with a specific extension in subfolders in an elegant way?

My current best bet is: for i in $(find . -name *.jpg); do echo $i; done Problem: does not handle spaces in filenames. Note: I would also love a graphical way of doing this, such as the "tree" ...
4
votes
2answers
4k views

issue with find -exec cp

Consider this example (newbie alert): touch test0 touch timestamp touch test1 sudo find /var/www/import -iname 'test*' -newer timestamp -exec cp {} new \; It actually copies file test1, but it ...
4
votes
2answers
985 views

Is there a way to find files containing only non-printing characters?

I've got a program that's behaving badly and has created a number of files with only a few non-printing characters. If I were to cat the files, I see nothing (since they are non-printing chars). ...
4
votes
2answers
5k 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 */ ...
4
votes
1answer
761 views

How search for a file beginning with either a or z and ending with a or z?

I attempted find -name 'a*' 'z*' '*a' '*z' but it gave me the error code find: paths must precede expression: z* I know how to find files starting with a though z, or ending with a-z, but not ...
4
votes
1answer
222 views

What is the '+' in find command for? [duplicate]

I have some times come across the use of trailing + while using unix commands like find. Example from SO post - find -exec touch -t 201007162310.00 \+ Please help me understand the use of this.
4
votes
4answers
8k views

Move all files with a certain extension from multiple subdirectories into one directory

Suppose I have a bunch of zip files in several directories: Fol1/Fol2 Fol3 Fol4/Fol5 And I want to move them all to a common base folder. How would I do this?
4
votes
3answers
2k views

Why piping find and grep returns nothing?

I'm trying to have grep search inside specified files that are returned by find: find . -type d -name 'mydir*' -exec find '{}' -name '*.java' \; | grep 'MyClass' This doesn't work. Meanwhile, ...
4
votes
2answers
640 views

Why does this awk command not play as well with find as sed does?

I am very much a newbie at Unix/Linux command line stuff, and mostly get to where I'm going by copying, pasting, and modifying code I find on the internet. Just mentioning that in hopes people will ...
4
votes
1answer
136 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 ...
4
votes
3answers
4k views

Pass xargs argument as a string to another command with '>'?

Suppose I have a bunch of files in /tmp/. I do find . -type f | xargs -iFILES And I want to do a md5sum in each file, outputting to a file with the same name, but with .md5 extension. find . ...