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

learn more… | top users | synonyms

2
votes
1answer
42 views

Is there a version of the 'find' command that saves its state?

If a find is searching a large disc, and is aborted for some reason, I'd like to be able to start it again, from where it left off. Is there a version of 'find' that does this? The problem is that, ...
0
votes
2answers
95 views

Bad Substitution when Renaming Files using find

I am trying to recursively rename image files using the find command. Currently, the command is written as follows: $ find . -name '*.jpg' -exec rename "${echo $(uuidgen) | cut -c1-8}.jpg" '{}' \; ...
3
votes
2answers
136 views

Find Files not an regex whitelist

I have a huge Folder with thousands of Files. Some Files have some Characters in it, which are not allowed. (UTF-8 signs) So I have a white list of allowed characters and a beginning of a bash-script ...
0
votes
1answer
150 views

Find files and recursively append text to them

I have been looking for an answer to this problem for a while: how can I use find append text to all hits? My original method was something like sudo find / -type f -name "*.py" -exec cat somecode.txt ...
2
votes
3answers
303 views

Can I use the find command to pass arguments to perl?

I have a perl script $ cat ~/script.pl sub main { my ($file) = @_; <STUFF> } } foreach (@ARGV) { main($_); } I want to execute ~/script.pl on every .txt file under the ...
0
votes
1answer
175 views

Find regex for timestamp in filename not working

I want find mail files in user maildir, without mailfilter, dovecot-index etc. All mail files have unix timestamp in its filenames, I think it is the easiest way. I used this regex: .*\/\d{10}\..*. ...
1
vote
1answer
98 views

How to recursively remove all but list of files?

How can I recursively remove everything in a directory EXCEPT a small list of files to preserve? For example, let's try to remove all files except ones named f2 and f5. # Create a testing ground ...
1
vote
2answers
46 views

path of folder within a folder in terminal

I have a number of files that are saved as Year -> Month -> Day -> bunch of .nc files I would like to generate a list of all of the directories that contain the nc files. I can list the ...
1
vote
1answer
80 views

Create file for every result of find command?

With this line of code I generate an output of every result. exec("find ics/ -mmin +3 -type f -name '*.pdx' -exec basename {} ';' > ./tmp/filename") How can I generate a file with dynamic file ...
1
vote
1answer
55 views

Zip subdirectories based on find, -exec

Here's what I would like to achieve: I have some directories, and subdirectories in them (which may have sub-subdirectories). In each subdirectory I want a zip file with contents of that particular ...
2
votes
1answer
72 views

Find and replace using parts of the found string in the replace string

Let foo be any string. I have to search a file for all occurrences of \LeftLabel{foo} and replace each occurrence with \LeftLabel{\textsf{foo}} but only if foo does not start with a $ ...
2
votes
1answer
41 views

who to get a count of “base subDir” without there subDirs?

All I am trying to do is get a count of direcrories on one leve of a tree. so Far I have this. find /media/data/temp1 -type d -exec basename {} \; which gives me this: temp1 Coldplay Greatest ...
1
vote
5answers
225 views

List (or move) only files with a certain number of lines?

Dealing with a whole bunch of two-line config files, I'd like a way to exclude any files that have a different number of lines. So, something like: mv * destdir only if file contains exactly two ...
0
votes
2answers
28 views

how to find the file size for softlinked files

I have a log of files that's on a NFS, and they are connected via softlinks on the local redhat server. When I try to run search for any files that was touched during last weekend and calculate ...
1
vote
1answer
2k views

Using regex quantifier with find [duplicate]

I've got a set of files in a directory, all of the format test[0-9][0-9].txt. If I run find . -regex ".*/(test)[0-9][0-9]\.txt" then all the files are shown, but if I run find . -regex ".*/(test)[...
0
votes
1answer
31 views

Struggling with find

I have the following scenario: My directory-tree looks like this: /export/home1/user1/profile.V2 /export/home1/user2/profile.V2 my find command should find all profile.V2 directories: find /...
1
vote
1answer
62 views

How do I combine '-size` and '-exec rm' in find?

When I use this, it works: find /home -name "error_log" -exec rm -rf {} \; But when I try to add a file size limit, it won't remove any files: find /home -size +5000000b -name "error_log" -exec rm ...
0
votes
1answer
523 views

How to add subject line when sending email output of find using ssmtp

I got a script running (as cronjob) that will list the files in a folder before doing a Rsync job and emailing me the list. How can I add a subject line. find /path/to/folder/ -type f -size +1M -name ...
1
vote
1answer
236 views

How do you assign {} to a variable in find --exec

I'm going to ask and answer this as I couldn't find the answer anywhere. I was trying to write a script that looped through each xml file in a directory and run make NAME= where NM was the filename ...
1
vote
1answer
49 views

copying and working on OSX .app files (folders) in linux

tldr; I want to run a script over an external hard drive and tar.gz every folder that ends with .app into their own archive. That is, I don't want them all in one tar.gz file, I want to create one ...
2
votes
5answers
252 views

How can I list the names of directories that contain file names matching a regex?

Given a directory X that contains several subdirectories and files, I would like to list the names of the immediate child directories of X that (directly or indirectly) contain file names matching the ...
0
votes
1answer
48 views

quoting problem when piping find output into xargs [duplicate]

I have a directory with the following subdirectories, i.e. If I run $ tree -L 1 . ├── 2007-06-20_to_2008-10-01 ├── 2008-07-21_to_2008_08_12-Nokia 2mp ├── 2009-11-01_to_2011-01-10 - All iphone Pics ├──...
1
vote
2answers
285 views

How does 'find -exec' pass file names with spaces?

If I have a directory containing some files whose names have spaces, e.g. $ ls -1 dir1 file 1 file 2 file 3 I can successfully copy all of them to another directory like this: $ find dir1 -...
2
votes
1answer
153 views

How to copy recursively all files not older than 1 day?

How to copy recursively all files not older than 1 day? I first tried find . -amin -1440 | xargs cp /dest But it doesn't work because the items given to xargs should be positionned before the /...
2
votes
3answers
380 views

How to iterate through files and delete those older than x days but NOT in use

So, I've been able to figure out bits of this myself but am having trouble piecing them together. I have a task I need to automate - I have folders filled with gigabytes of obsolete files, and I want ...
3
votes
5answers
610 views

Search files for a string and if found check if a file with paired name exists in the same directory

I have many different files with the same ending .ft1 that may or may not contain one specific word special. For the files that contain this word, I want to check whether another file with a different ...
0
votes
1answer
89 views

Cron to find exec cp and redirect output with time / date per line?

I try to setup a cron task to run a set of basic shell commands. I need to look to any files created on the last day, then copy to another folder and generate a log stating, line by line, the date ...
0
votes
2answers
44 views

Only print filepath,without filename [duplicate]

The find command find /MOS -name "001.txt" The print /MOS/XNF/N01/001.txt My questions Which option could only print the filepath,without the filename ? The print /MOS/XNF/N01/
1
vote
2answers
39 views

Rsync two “filepath” found by find commands [closed]

Original file /001day/backup/001m/name_test_v1.txt Destination file /001date/003m/name_test_v12.txt Method 1 rsync -av --progress /001day/backup/001m/ /001date/003m/ Method 2 ...
0
votes
1answer
21 views

Cleaning script with find and anacron

I want to automatically delete old files in ~/Downloads. with exception of ones that have '!' in their name. My current version is as follows: find /home/user/Downloads/ -mtime +90 ! -path '*!*' -...
1
vote
2answers
122 views

Find works fine in command line, but won't work in script

I am trying to write a script on a Debian Jessie host. I am having an issue with trying to run the following command (with a twist) in a script: find ~/* -path ~/FileSniper* \ -prune -o \ -type f \( ...
1
vote
1answer
36 views

Search for file in folder1 and execute a script if that file isn't in folder2

folder1 contains only .flv files. folder2 contains only .mp4 files. All .flv files in folder1 SHOULD have a corresponding file ending in .mp4 in folder2 : /folder1/123.flv and /folder2/123.mp4. I ...
3
votes
3answers
94 views

Filter a list of files based on file attributes

With find you can search by file attributes like -type, -executable etc. How to achieve something similar, but from an existing list of files? e.g. the output of dpkg -L <package_name>. A pipe ...
3
votes
2answers
89 views

Why `find` likes `stat` or `fstat` so much?

I'm trying to make /usr/bin/find to show something meaningful without doing any sort of stat, with no useful results so far. If I forcefully inhibit stat, find stops descending into subdirectories at ...
2
votes
1answer
59 views

How to reuse file pattern in .gitignore in bash/zsh?

Here is the content of the .gitignore cron.yaml build target webview *.pyc *.sublime-workspace .idea *.rej .coverage app/tools/temp_*.py app/tools/*/temp_*.py I am currently iteraring files in a ...
0
votes
1answer
46 views

Delete Empty Folders - recursive [duplicate]

I would like to clean up some folders. So I want to delete all folders which are empty or only contain other folders... First I tried find . -type d -delete but this lists the subfolders after ...
1
vote
1answer
31 views

Extract entries from a file ranging from one date to another

There is a file which has entries with the first and second field as date and time in the following manner : 2015/10/14 00:33:37. The file has 100,000+ lines and is constantly updated. Entries in the ...
3
votes
4answers
108 views

Moving a list of files by matching them to a destination index

Say I have two text files src.txt and dest.txt, where src.txt contains a list of filenames (some of which include spaces) in /src/dir/ and dest.txt contains, in random order, a list of the complete ...
3
votes
2answers
94 views

How can I list all files, but only in directories that have no subdirectories?

I have a directory tree that I want to search recursively for all files of a certain type (for example all .jpg's), but I only want to list these files if they are at the bottom of a directory tree. ...
0
votes
1answer
32 views

Shorthand alternative to find

Is there any alternative out there for find similar to ag and ack? I'm really tired of having to type: find some/app -iname "some_file*" I much rather just type: find "some_file*" And have it ...
2
votes
2answers
87 views

Faster search than find

Is there a way to find things faster than find . I am/was doing :- $sudo find / -perm +4000 But it takes ages to find the required info. and I know that most of the files which would that specific ...
1
vote
1answer
20 views

How do I write a script to automatically compile and install all Moksha modules?

I have this repository cloned on my Sabayon machine, what I would like to do is write a script that will change into each directory of this repo (just the top-level directories, not directories inside ...
2
votes
4answers
172 views

Find latest files

How do I find out the most recently accessed file in a given directory? I can use the find command to list out all files modified/accessed in last n minutes. But here in my case, I'm not sure when ...
2
votes
1answer
153 views

Bash script unable to move files

I'm trying to write a "janitor" script that will run as a cron job in one specific directory. It is supposed to create an archive folder with the date of creation in the name, and then find and move ...
1
vote
0answers
56 views

Chaining grep commands [duplicate]

I'd like to find all xml files containing 'foo', but not containing 'bar'. The command I've put together looks like this: find -iname "*.xml" -print0 | xargs -0 grep -FlisZ "foo" | xargs -0 grep -...
4
votes
3answers
221 views

Linux find-command skips a directory

I have certain network share folders mounted in the /media directory. I want to make sure that when I do something like sudo find / -name foo it should always skip the /media directory. I don't want ...
1
vote
2answers
76 views

Internal expansion with the find command and wildcard character [duplicate]

I'm still learning the command line and I am having some trouble fully understanding the use of the wildcard within the find command. I'm working in the directory user/temp and use the find command ...
7
votes
4answers
303 views

Execute a command where a file is found

How do I execute a command where a file is found? Consider I've an directory named testdir that contains the following: $ ls -R testdir/ testdir/: dir1 dir2 dir3 dir4 dir5 testdir/dir1: doc1.pdf ...
1
vote
1answer
263 views

Find files older than a given file - a few hours

I'm using the following to find all files that are older than a reference file... find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt ... which works as expected. However, I want to ...
1
vote
1answer
19 views

What changes are made to ./.dns?

My server hosted at Hostgator was recently hit by malware and hence to monitor the file system I use find -mmin -xx command at regular intervals. But everytime I run the find command, I see the first ...