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

learn more… | top users | synonyms

0
votes
1answer
98 views

How can I pass in a parameter to sed?

To be more precise - how can I pass in a parameter to a program that then calls sed - how can I 'pass' that parameter along? I have a file 'source_code.sc'. I have a sed script "find_expect": #n ...
2
votes
2answers
103 views

Use xargs to move files from within a directory

I am searching for some folders in my current directory. What I want to do is, move all the files within those directories to another directory. I am using the following command: find -maxdepth 1 ...
1
vote
1answer
96 views

Copying wallpaper images into a single folder

In my ubuntu 12.04 set-up, there are lots of wallpaper images in the directory /usr/share/wallpapers. For example, one might be usr/share/wallpapers/Leafs_Labyrinth/contents/images/1600x1200.jpg ...
1
vote
2answers
130 views

Count entries for each directory in tree

Say I have the following tree: root: d foo d bar /foo: d A - tmp.txt /bar: d B - tmp2.txt /foo/A: - tmp3.txt /bar/B: d = directory and - = file I need to answer the following question: which ...
2
votes
1answer
41 views

Linux shell - unexpected error

I'm new to the linux & command world. I have two directories, one called pasta (which contains 3 files) and another one called pasta2 (with nothing inside). I'm trying to move all 3 files from ...
2
votes
2answers
65 views

What is the “initialization time” in the find command?

When I try to refer find command's man page , I come across -mmin n The value of n can be one of the following: n Evaluates as True if the file modification time ...
0
votes
3answers
120 views

thoroughly find all links (hard and symlinks, and any combination thereof) leading to a file/dir

I read "most" of the proposed questions, but I believe they all miss the complexity of the right answer. I want, only using "basic" commands (for maximum portability) (i.e., something that would work ...
2
votes
2answers
71 views

Trouble getting regex to work with find

I'm having a lot of trouble getting find to work with regex flags. Im using egrep on its own to find a date pattern in a file, like this: egrep '[0-9]{4}-[0-9]{2}-[0-9]{2}' which will return dates ...
3
votes
3answers
113 views

Find directories without music files

My ~/Music/ directory is actually full of "empty" directories I want to clean. I say "empty" because this directories actually contain files, some contain old cover image files or Thumbs.db files. I ...
1
vote
1answer
75 views

Find a particular nesting of directory names, e.g. …/project/dir1/dir2

I'm having some issues dealing with the find command; I don't know the syntax for it very well and I need to use it in a script to find a specific directory structure that could be located anywhere. ...
4
votes
2answers
98 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 ...
3
votes
2answers
174 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 ...
1
vote
2answers
249 views

Need to copy files to existing directory and remove files already there with the same name but different extension

EDIT: Total rewrite of question for clarity. I have a directory tree (new) with a bunch of files of with an extension of .new. I have an identical tree (old) where many of the files have names ...
4
votes
1answer
82 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 ...
2
votes
2answers
69 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 ...
4
votes
3answers
110 views

What is the difference between [.]* and '.*' for command 'find -name'?

My goal is to find all files or directories in a filesystem that start with a dot (.), for example .gnupg. So I came up with the command: find -name '.*' Checking on the Internet, I saw some hints ...
2
votes
2answers
65 views

Rationale find command display . directory

I am wondering what the reason or rationale is for the find command to list the current directory ( . ) at some times but not others. When I use ".", I see the current directory in the outer ...
4
votes
5answers
879 views

Faster way to delete large number of files

I have a directory where lots of cached files are getting generated very quickly. Since these are very small files, it is consuming all my inodes very quickly. Currently I am running the following ...
1
vote
2answers
124 views

mv complains about standard input in a pipeline that filters file name with grep

I'm trying to move several .avi files that have spaces in from a CD to my home folder. I've already know how to get rid of the spaces: find /media/mathscd/ | grep -L -r "*.avi" | for file in *; do ...
3
votes
2answers
1k views

find files not matching list of filename patterns

I find myself needing to find and identify extraneous files (out of about 900K files on a 2T drive). There are lots of files that I want to keep, and I have filename patterns for these known good ...
4
votes
2answers
675 views

recursive search for a pattern, then for each match print out the specific SEQUENCE: line number, file name, and no file contents

What I am after is almost exactly the same as can be found here, but I want the format "line number, separator, filename, newline" in the results, thus displaying the line number at the beginning of ...
2
votes
4answers
143 views

Recursively apply a command to modify all files in a directory

I have a command that reads a file, and outputs a modified version on stdout: ./convert /path/to/file How can I recursively apply this command to all files in a directory, and overwrite the ...
4
votes
3answers
245 views

Search mp3 collection for songs with a certain song length

How would I search a directory of mp3 files for songs between a certain length. Ex: findmp3 -min=03:00 -max=03:15 /music/mp3/ebm/ Would return all mp3 files in the emb/ directory having a song ...
1
vote
2answers
111 views

How to find certain files and move them to a new directory in the same command?

So I was looking around and all I have found is how to do this only if the directory is already made, which is this: find source -name '*.z' -exec cp {} destination \; But how can I make a new ...
2
votes
5answers
149 views

Delete all files in directories except those whose path are listed in a file

Given the following files: data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
0
votes
1answer
64 views

find /var/log/ -type f -name *.log doesn't return list of log files

Instead, it returns the following error: find: paths must precede expression: file1.log Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] ...
2
votes
1answer
188 views

ksh:Get files created on specific date in directory [duplicate]

I want get the files that were created on specific date in a directory > ll total 36 -rw-rw-r-- 1 tak tak 212 Oct 08 07:06 name.log -rw-rw-r-- 1 tak tak 494 ...
6
votes
3answers
105 views

Excluding . and .. from results in find and ls

Is there any way to prevent find and ls -l from listing . and .. in their results? I never care about seeing this result in the output, and it prevents me from effectively piping their output to wc -l ...
4
votes
1answer
195 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 ...
1
vote
1answer
95 views

find does not work on symlinked path?

If I run this command find $HOME/MySymlinkedPath -name "run*.sh" nothing happens, and gives no error ('MySymlinkedPath' is a symlinked path to another hard drive other then my $HOME one). These also ...
2
votes
2answers
198 views

Optimized way to list and delete files

I need to list and delete .php, .xml files. For this I am using find command. To list : find . -type f -name \*.php -print0 To delete : find . -type f -name \*.php -print0 | xargs -0 rm -r As I run ...
6
votes
2answers
364 views

How does this find command using “find … -exec sh -c '…' sh {} +” work?

@StephaneChazelas posted the following solution to this Q&A: Having some trouble using “find -exec {} +”. $ find . -iname "*.extension" -exec sh -c ' exec <command> "$@" <additional ...
4
votes
2answers
107 views

Find and differences between -perm /6000 and -perm /u+s

I have been trying to find setuid executables using a `one liner'. The line I first tried was: find / -perm /u+s -type f Then I found a line which is similar but gives different results: find / ...
1
vote
1answer
117 views

Brace expression does not work in find regex

I have two folders, CA01 and CA02 under current folder, foo: foo -+ | +-CA01 | +-CA02 When I type find . -regex ".*CA[0-9]+" -exec echo {} + Or find . -regex ...
4
votes
5answers
4k views

Why does find -mtime +1 only return files older than 2 days?

CentOS 5.9 I'm struggling to wrap my mind around why the find interprets file modification times the way it does. Specifically, I don't understand why the -mtime +1 doesn't show files less than 48 ...
4
votes
3answers
226 views

How to find a file with specific permission of a specific user?

How do I get a list of all the files which permission is "read and write" for a specific user. For example, when I go on the desktop of my mac, then right click on file "A", then "get info", then on ...
2
votes
4answers
267 views

Zgrep stop after first match when arguments are passed from xargs

I'm using this command to find patterns in zip files (similar to the one) suggested here http://superuser.com/questions/144926/unix-grep-for-a-string-within-all-gzip-files-in-all-subdirectories find ...
2
votes
1answer
126 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 ...
0
votes
2answers
618 views

How can I find files and then use xargs to move them?

I want to find some files and then move them. I can find the file with: $ find /tmp/ -ctime -1 -name x* I tried to move them to my ~/play directory with: $ find /tmp/ -ctime -1 -name x* | xargs ...
3
votes
1answer
175 views

find multiple conditions with multiple execs

I'm trying to build a find command with multiple conditions that lead to multiple actions. It was suggested to me that I should use only one find command for efficiency. Here is what I have: ...
1
vote
3answers
473 views

How to delete directories based on `find` output?

I issue the following command to find the .svn directories: find . -name ".svn" That gives me the following results: ./toto/.svn ./toto/titi/.svn ./toto/tata/.svn How could I process all these ...
2
votes
2answers
63 views

open a file and copy the listed files to another folder

I have a file named file1.txtcontaining file names like below : filea.txt fileb.txt filec.txt I want to copy the files listed in file1.txt to another folder. What is the UNIX command to use? (the ...
6
votes
2answers
740 views

Find files that a user can not read?

I want to find files that a particular user will not be able to read. Assume the username is "user123" and they are in a group called "user123". I want to find files that, if they are owned by ...
2
votes
4answers
255 views

Scope of variables when calling function from find

In a bash script I define a function that is called from find. The problem is that the scope of variables does not extend to the function. How do I access variables from the function? Here is an ...
4
votes
3answers
1k views

Sorting files according to size recursively

how to scan a folder recursively and find the largest files in the folder, and sort them by size. I have tried using ls -R -S but it tends to list the directories as well I need to scan the folders ...
2
votes
2answers
92 views

Filtering the result of the find command, so that it returns only directories

Is it possible to get only the results from find that are directory paths? Using find with some option, or using grep or some other utility the results are piped into as a filter? I thought something ...
0
votes
1answer
79 views

Problem with small bash script

I often run find in my code projects when I make a change somewhere and I have to find where it impacts other pieces of code, so I thought about writing a very small script to make this easier, call ...
5
votes
1answer
312 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 | ...
3
votes
2answers
71 views

Exclude paths that make find complain about permissions

I need to generate a file list from a disk volume. Some of the directories (all hidden directories under the root directory) have strange permissions that causes find to complain. I try to exclude ...
1
vote
2answers
624 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 ...