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

learn more… | top users | synonyms

0
votes
2answers
20 views

what does `find pattern dir` do?

When I search for some files under a dir, I run find dir -name pattern But I find that the following will return all the files under dir, regardless what pattern is: find pattern dir is it just ...
1
vote
3answers
88 views

How to enter foo-* folder without actually using wildcard or shell expansions?

Short story I'm looking for the command to enter first found foo-something directory like: cd foo-* but without using wildcard (or other special shell characters). Long story As part of the ...
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 ...
1
vote
1answer
34 views

How can I run a script recursively in a directory

I am using the following code to decode JPEG-compressed DICOMs. find ./* -maxdepth 0 -name '*.dcm' -printf 'dcmdjpeg %p %p \n' | sh I run this code inside any folder containing those files. The ...
1
vote
1answer
34 views

find files with extended attributes [duplicate]

Can I use find to find all files which have extended attributes set? Let's say, I want to find all files with +i, immutable attribute in /foo and its subfolders. I could not find any, mention of ...
0
votes
1answer
79 views

Extract values from filename and add it into a text file

I have a gridded model data (separated by different depth) saved in text files. The structure is like this: Format of every column in a row in the text file: x_coordinate y_coordinate density ...
1
vote
3answers
53 views

Why does find -inum iterate through the whole filesystem tree?

It surprises me to see find iterate/walk through the complete filesystem when I do a simple find -inum 12345 Without background info it seems to me that there should be much easier ways for to tell ...
8
votes
6answers
431 views

When does the empty string denote the current directory?

In a script I use find to collect some files in the current directory, as in $ find . -name "*.h" ./foo.h Now I'd like it to just output foo.h, without the ./ prefix. I thought that the empty ...
1
vote
1answer
53 views

shell for loop with find with filenames containing spaces [duplicate]

Consider a directory with typical Microsoft Windows filenames: New Document.txt Foo.doc Foo - Copy.doc I'd like to do something on each file such as: for sendfile in $(find ${POLLDIR} -type f ...
0
votes
3answers
19 views

Setting global browsable permissions for subdirectories (r-x) but making files inaccessible to everyone but the owner and group members

I typically have a directory where I want all users to be able to browse through but having files be unreadable and unexecutable. I see some related questions that do not exactly match what I want: ...
5
votes
1answer
202 views

combining find with other commands: when to use -exec and when to use pipe? [duplicate]

I've learned to use the find command by itself to find files and directories however when it comes to doing something with the files/folders I'm confused. Given the following command: find . -type f ...
0
votes
1answer
40 views

find files in folder newer than

I searched through man find but it doesn't give me the answer to a simple task: I want to list all files inside a folder that were modified during the last 5 hours. I tried find ~/.purple/logs ...
1
vote
2answers
45 views

Moving files older than one year to parent archive directory

I want to move the photos of my collection into an "/home/Bruno/Archiv/Bilder" directory, which is parent to the "/home/Bruno/Bilder" Directory. I started of with: find -ctime +365 -exec echo mv ...
0
votes
4answers
62 views

grep for files and open the resultant matches

I'm trying to open all files based on some return values from grep in the command line. I know that I can use the -l option to only return filenames, but I would like to combine this somehow with ...
1
vote
1answer
30 views

Find files belonging to a group

Actually I want to find all the files and folders that are under the same group, for example I have this : [test] user1/sam a.txt user9/sam b.txt user4/sam I'm looking for a command ...
1
vote
2answers
54 views

Find and for loop

Trying to do a mass convert from M4A to OGG in a large music collection, I have: #!/bin/sh for i in `find /home/family/Music -name *.m4a -print0` #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac ...
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 ...
4
votes
1answer
77 views

Problem combining -or and -exec with find command

I'm finding that when I use find's -or operator in combination with -exec, I don't get the result I expect. When searching for .cpp and .h files, the command works as expected if I don't use -exec: ...
1
vote
1answer
24 views

my permission command doesn't work properly

find . a* -exec chmod o+r {} \; find . *d -exec chmod o+x {} \; I want to give o+r to all files that start with "a" and o+x to all files that end with "d", but these lines seem to affect all files ...
1
vote
1answer
36 views

Replace cp function by rsync [duplicate]

I'm trying to replace my cp function by an rsync function My cp function is the following find /home/odroid/USBHD/Movies/ -iname "*.mkv" -mtime '-1' -exec cp -n {} /home/odroid/NASVD/Movies \; do ...
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 ...
1
vote
2answers
53 views

run grep cmd recursively and print path name and result

I have a log file that exists in multiple directories one for each client. I am trying to run the following: find . -iname "20140926.log" -exec cat {} \; | grep 123456 | grep 'food="100"' | wc -l ...
1
vote
2answers
27 views

Why does find complain of an invalid expression?

I have shell script like this to copy from backup file to weekly directory: #!/bin/sh find . type f \( -iname "SS1*.tar" -o -iname "SS2*.tar" -o -iname "SS3*.tar" -o -iname "SS4*.tar"\) -exec cp {} ...
0
votes
2answers
66 views

How do I delete directory and file, if .picasa.ini is the only file in the directory?

I want to start from a root directory and recurse through the tree. I want to delete the directory and file if there is only one file in the directory called .picasa.ini It seems like the "find" ...
1
vote
2answers
65 views

Concatenate file contents AND names

I've been writing for many months. The files I create are dated files named like 2011-06-13.markdown with daily content. I've decided I want to have all the writing in one file instead but I'd like ...
2
votes
2answers
46 views

List of subdirectories that contains a particular file name

I am wondering if i can do this in a single shell command. I am in home directory and want to find a list of subdirectories that contains a particular file. The file name and the depth is always ...
1
vote
2answers
39 views

List folders that contain more than X images

Is there a way to return a list of all folders on a given disk containing more than X images ? The search should be recursive but X should not. Example for X=100 : Folder A |_ folder A1 ...
1
vote
2answers
64 views

finding latest date and date modified file and using sed

I have a series of files that contain a date and I need to get the file which has the latest date, and the latest date modification and pipe it to sed. I have tried various approaches and I cannot ...
0
votes
3answers
138 views

bash find using variable

I have an issue I don't understand. It is simple and it should work, but it doesn't. =EDITED exactly what I can see from terminal= I have a list of filenames: [molni@archlinux picasa_album]$ cat LIST ...
2
votes
1answer
42 views

how to execute a shell built-in if find found certain files

In general, if we want to execute a command if find identifies files corresponding to certain specs, we can use -exec. But in my case I want to exit the shell/script if find found a match and -exec ...
4
votes
5answers
290 views

Clone directory tree structure and copy files to the corresponding directories modified after a specific date

I have a folder with more than 30 sub directories and I want to get the list of the files which was modified after a specified date(say sep 8 which is the real case) and to be copied with the same ...
3
votes
1answer
40 views

List File Space Ownership By User

I have a 4TB NFS file system that is being served from a NetApp filer. The NetApp's quota tools tell me that a certain user is using X amount of disk space in that qtree, but it isn't in "their" ...
9
votes
1answer
319 views

Is it possible to use `find -exec sh -c` safely?

I'm trying to use find to echo 0 into some files, but apparently this only works with sh -c: find /proc/sys/net/ipv6 -name accept_ra -exec sh -c 'echo 0 > {}' \; But using sh -c with find -exec ...
2
votes
2answers
49 views

Reference a path name in `find` output results

What I would like to do is to be able to reference a find path name result as a parameter to another command without laboriously typing the full path name. Example: $ find -name testfile path1 ...
-2
votes
1answer
51 views

Delete empty directories without find

I want to delete empty directories without using find command like the following: Instead of find . -empty -type d -delete use if [ "$(ls -d *)" ]; then echo "Not Empty" else echo "Delete" fi ...
1
vote
1answer
41 views

Find files in multiple directories taken from list in a file?

FreeBSD 9.2 RELEASE p2 I have a file dirs.txt. In this file is a new line separated directory list like so: /etc /home /home/goods/ I need to first find in all directory's files which have names ...
2
votes
1answer
43 views

how to find and then delete files older than specific days in unix including files in subdirectores not touching folder structure

I have got one folder for log with 7 folders in it. Those seven folders too have subfolders in them and those subfolders have subfolders too. I want to delete all the files older than 15 days in all ...
5
votes
4answers
240 views

How can I cat the contents of files found using find into a single file?

I managed to shoot myself where it hurts (really bad) by reformatting a partition that held valuable data. Of course it was not intentional, but it happened. However, I managed to use testdisk and ...
0
votes
2answers
49 views

Remove by date in Shell Script

I have a shell script that creates a backup of a database. I would like to keep the last 7 days for files. What is the syntax I need to remove files in a directory by date or can I keep the newest 7 ...
1
vote
2answers
54 views

Find doesn't want to find *.sh in certain level [duplicate]

I have a problem with find. It doesn't find *.sh files if I am in certain directory level. It does, however, find *.sql files. /path$ cd do_not_upload/updates/1.1.1/ ...
3
votes
3answers
284 views

How to integrate mv command after find command?

Given a scenario I was searching for file name which contain AAA withing it on a path using following command: find path_A -name "*AAA*" Given the output shows from the above command, I want to ...
6
votes
3answers
708 views

Meaning of @0 in a shell script

I was looking at the script /etc/init.d/sudo in my Ubuntu 14.04 Linux system. While reading the script, I found this statement : find /var/lib/sudo -exec touch -d @0 '{}' \; What is the meaning of ...
0
votes
2answers
51 views

Find an archive and extract it in the directory where it is located

I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory ...
1
vote
1answer
90 views

make `find` return with a non-zero exit code if error occured

Why am I seeing the following: $ find -not -exec bash -c 'foo' \; -quit bash: foo: command not found $ echo $? 0 This is a reduced version of the actual script I am using which I post at the end ...
0
votes
1answer
33 views

Improve execution time for recursive md5sum check?

This recursive md5sum check for 40000 items of 11.8 GB takes 2 minutes: ret=$(find "${target}"/ -name ".md5sum" -size +0 | while read aFile; do cd "${aFile%/*}"; md5sum -c ".md5sum"; done | grep -v ...
1
vote
1answer
50 views

ls and find command excluding a certain directory

I want to do this: ls -altrhS 'find / -type d \( ! -name tmp -prune \) -size +10000k 2> /dev/null -print' | egrep -v 'ibd|MYD|MYI' So I want to list, in that format, files of a specific size ...
2
votes
3answers
109 views

find: Why is the -a operator not commutative in combination with -print?

Supposing we're using find in current directory with audio files (e. g. MP3) and (important!) also non-mp3 files (e. g. JPEG) present in current directory or somewhere below it. Additionally to that, ...
1
vote
1answer
62 views

Apply recursive chmod to files or folders only

I'd like to apply chmods to files and folders in one line, Basically: chmod 700 ./* -R # but only apply to folders chmod 600 ./* -R # but only apply to files Of course I searched google and read ...
6
votes
2answers
248 views

When will `find . -exec COMMAND {} +` execute COMMAND multiple times?

If I do find . -exec echo {} + it prints all paths in one line, i.e. command echo is only executed once. But according to man find, -exec command {} + ... the number of invocations of the ...
4
votes
2answers
40 views

mv with rsync functionality

I'm trying to merge two directory trees that have many common elements but also each have elements that are only present in one of the two trees. The main issue I am having is that when mv encounters ...