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

learn more… | top users | synonyms

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
45 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
767 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
190 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
195 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
1k 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
354 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
3answers
1k views

Delete files and directories by their names. No such file or directory

I need to delete all compiled data: directories called build, directories called obj, *.so files. I wrote a command find \( -name build -o -name obj -o -name *.so \) -exec rm -rf {} \; that ...
4
votes
2answers
280 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
844 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
6answers
933 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
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
224 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
131 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
3answers
7k 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
3answers
584 views

Recursively Remove SVN files

I'm still learning the bash shell. I want to recursively find and remove svn files within the child directories of a given folder. I made the mistake of checking out instead of just cloning. So i'm ...
4
votes
2answers
394 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
2answers
537 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
216 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
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
4answers
1k 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
110 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
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
2k 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
899 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
4k 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
429 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
217 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
3answers
1k 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
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
583 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
135 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 . ...
4
votes
2answers
75 views

Why does 'find -delete ' delete all files in a directory recursively

So the following behaviour of unix find just cost me dearly: > touch foo > touch bar > ls bar foo > find . -name '*oo' -delete > ls bar > touch baz > ls bar baz > find . ...
4
votes
2answers
206 views

Find file names that don't contain a specified string

I'd like to execute the opposite of: find . -name "*2013*" Find all the files in the current directory that don't contain the string "2013" in their names. How can I do that?
4
votes
2answers
269 views

Sort files by modification time

I've seen many questions and answers here using a construction along the lines of list_dir=`ls -t /path/to/dir/` for i in $list_dir; do or ls -t | while read i; do Now, I know that you shouldn't ...
4
votes
4answers
3k views

find command in cygwin giving parameter format not correct

I am using cygwin in my windows machine. I am trying to do a find and it is giving parameter format not correct. Why is that? $ ls bootstrap.jar catalina-tasks.xml catalina.bat catalina.sh ...
4
votes
1answer
3k views

find & sed (search and replace)

I'm using the following command on my mac: $find . -name “*.java” -exec sed -i ’s/foo/bar/g’ {} \; and it seems to have no effect. I have two files in the directory that end in .java, which both ...
4
votes
2answers
1k views

Using files that have spaces in their name in pipes

I have folder named play which contains a file damn file (with space). When I use find and pipe the output to tar: find play/ -name 'damn*' | tar cf archive.tar -T - It works perfectly. Why does ...
4
votes
4answers
518 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 ...
4
votes
2answers
672 views

find arcana: can't get pipe to work in -exec line

How do I pipe the results of a find through a sed to xform the stream, and then use that transformed stream as one of two arguments to a script? IE: find turns up file1.tiff (among others) sed ...
4
votes
1answer
129 views

Find directories and files with permissions other than 775 / 664

I am moving a website from one server to another and Git does not store metadata such as file permissions. I need to find the directories and files that are not 775 / 664 respectively. Right now, I'm ...
4
votes
1answer
124 views

why does find command use {} for a placeholder variable?

I'm curious as to why find uses {} as the syntax for variable substitution (e.g., as in find . -name "*~" -exec rm {} \;). It's a rather unusual syntax, and I don't know any other programs or ...
4
votes
2answers
985 views

remove duplicate files

On my Mac OS X 10.6.7, iTunes duplicated every single file in my music library. Now I have 3,840 files instead of 1,920. The problem is that iTunes didn't simply duplicate the whole folder, but each ...
4
votes
3answers
2k views

Use a shell variable to execute a comand

I have a unix command in a variable, it looks like this: cmd="find /path/to/webpage -type f | grep -v .svn | xargs grep $@" `$cmd` find: paths must precede expression Usage: find [-H] [-L] [-P] ...
4
votes
1answer
164 views

Why does find's -exec only executes on one result?

Here's what I checked: find mydir -maxdepth 2 -name .project -or -name .classpath gives output: mydir/.project mydir/.classpath Meanwhile find mydir -maxdepth 2 -name .project -or -name ...
4
votes
1answer
1k views

Deleting files by age

Is there a command to delete all the files in a directory that haven't been modified in N days? I need to clean up some old logs.
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 ...
4
votes
2answers
787 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. ...