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

learn more… | top users | synonyms

8
votes
5answers
245 views

Why does find sometimes match its command line path argument?

On Linux, cd /tmp mkdir foo; cd foo Now, running find . -name 'foo' gives no output. Whereas running find /tmp/foo -name 'foo' Gives the output /tmp/foo which doesn't make sense to me. Can ...
1
vote
1answer
51 views

Add one line to all found files

My original working directory hierarchy: $ find . ./usr1 ./usr1/.vimrc ./usr2 ./usr2/.vimrc I want to add one line -- "set number" -- to all .vimrc files. So I ran this command: find -name ".vimrc"...
1
vote
2answers
61 views

Usage of prune not working in find command

I am trying to use prune as: find /opt/app/bss/sieb/fs_clone1/userpref -name "*" -type f -mtime -7 -prune This is still searching sub-directories.
0
votes
2answers
211 views

How to recursively change permissions on all directories inside current directory?

How can I change folder and file permissions for all files and folders recursively inside current directory? I am not sure, why, but my command fails with this output: chmod: missing operand after '...
0
votes
1answer
59 views

How to set up a pre-defined variable with multiple directory paths to use with the find command

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them. I can run the find command on one ...
-4
votes
1answer
35 views

find problems again? [closed]

How do i show pipe or socked files from a directory? echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find $directory -maxdepth 1 -type ...
1
vote
3answers
29 views

problem with find (shell script)

I want the files of a given directory and use the following script: echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find /-type f $...
4
votes
2answers
84 views

How to modify files on Unix to avoid file purging policy?

We have a policy on our cluster that any files not modified or accessed within 30 days will be deleted. I have a project running and I want to keep all files until I finish it, would it be possible to ...
1
vote
3answers
88 views

Find Directory if Number of files is over X

Am wondering if someone can advise on the best way to do this. In my Web Dir is around 100 folders; each folder is a clientID. Within each ClientID folder is a Sub-Set of folders. In each subset ...
1
vote
2answers
114 views

Listing line number of results in `find` and `ls` [duplicate]

Is it possible with either find or ls to see, in a list of results, if any given entry is the nth result, what n is? So, for example, pretend ls -l returns: total 0 -rw-rw---- 1 bigdog bigdog 0 Jan ...
0
votes
2answers
54 views

Why doesn't this find command work? Regex & Find variants for .mp3 .wav and .m4a files

2015.10.25 Move on and Be Blessed.wav dummy.m4a 2015.11.17 BS Full.wav.mp3 2015.11.17 BS MOL.wav.mp3 find . -name '*.mp3' -o -name '*.wav' -o -name '*....
5
votes
5answers
468 views

Rename files based on their parent directory using find/xargs command?

I have a directory structure like this: Project/ | +--Part1/ | | | +--audio.mp3 | +--Part2/ | | | +--audio.mp3 | +--Part3/ | | | +--audio.mp3 ... I want to ...
3
votes
2answers
150 views

Find all files modified around a known one

An installer which isn't really clean (Adobe Acrobat Reader DC) installed on my Unix (Mac OS X) a lot of files in different places. I have a reference file Application which I am pretty sure was ...
4
votes
2answers
57 views

Invert matching lines, NUL-separated

I’m writing something that deals with file matches, and I need an inversion operation. I have a list of files (e.g. from find . -type f -print0 | sort -z >lst), and a list of matches (e.g. from ...
1
vote
2answers
28 views

Find file type reverse

On my image folder i want only images,so i will find all video files "intruders" using this command(found somewhere on stackexchange) find folder/imageonly -type f -exec file -N -i -- {} + |sed -n '...
2
votes
3answers
40 views

Find files with group permissions more restrictive than owner permissions

This is an actual work-related problem. Users could previously "su - userx" and was able to execute a script with user:owner permissions as userx:groupz 760 or 540, or modify a file that's userx:...
3
votes
1answer
327 views

I want to list all the files in my Linux server which are older than Dec 31, 2014

I want to list all the Linux files in a directory and sub directories which are older than 31 Dec 2014. Please help me out for this.
1
vote
1answer
48 views

find: missing argument to « -ok » [closed]

A while ago, I ran chmod to change some file permissions to 777. A friend of mine told me to never chmod 777, so I decided to change the permissions again. So, first I looked for all the 777 files: ...
1
vote
1answer
56 views

find command match issue [duplicate]

I'm having some trouble while searching files with find command and the way it handles the search. Let's say I'm currently in the directory /tmp and the directory contains the files: backup-20151219....
1
vote
3answers
100 views

How to find empty directories in unix [duplicate]

I want to show all the empty directories under my home directory, using shell script, can you help me find the code? (without using find's -empty)
4
votes
1answer
360 views

Why GNU find -execdir command behave differently than BSD find?

On my OSX, I've installed GNU find next to default BSD find via: brew install findutils. As far as I understand, BSD find is following POSIX standards and GNU makes it optional (as per this post), ...
3
votes
1answer
428 views

Odd alias “find . -name '*\!{*}*' -ls” in Unix Power Tools

From Unix Power Tools 3rd Edition page 175: Article 9.27 shows a way to match directories in the middle of a path. Here's a simpler "find file" alias that can come in very handy: alias ff "...
3
votes
5answers
457 views

How to process special characters in in file name using find

I am to find all files that start with certail char , e.g find . -maxdepth 1 \( -name "^m*" -a ! -name "g$" \) -print but what if someone create file that has special characters in the name of that ...
1
vote
2answers
24 views

Find doesn't work with recursion?

I ran the command below and notice it will only did the mod on the first level(SubDir*) on the finding and not the subsequence (ChildSubDir*). I wanted to ask if it is possible to go recursion on the ...
0
votes
1answer
178 views

shell find -delete “directory not empty” [duplicate]

i try to delete backupfiles on my synology nas older than 30 days, the files are in a directory which is created durig downoad the backupfile from my webserver after download i want to check -mtime ...
3
votes
1answer
117 views

Finding empty directories recursively

How can I find every empty directory, let's say, on the /home/.../Desktop. Because I am on Solaris, I can't use the find . -empty -type d command. Is there any other way?
5
votes
2answers
2k views

Find files containing string in file name and different string within file?

I would like to (recursively) find all files with "ABC" in their file name, which also contain "XYZ" in the file. I tried: find . -name "*ABC*" | grep -R 'XYZ' but its not giving the correct output....
3
votes
4answers
72 views

Finding mount points with the find command?

Is there a way to recursively search a tree for mount points on Linux? I'm looking to do something like this: find /tree -type mountpoint | sort -r | xargs umount
1
vote
2answers
110 views

use find and grep to find lines that contain some string and don't contain other string from files

First, I try the following code find . -name "*.cfg" | xargs grep "good"|grep -v "^\#" In the current folder, I get the list with the file name's extension is "cfg". Then I want to search the ...
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
80 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
121 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
123 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
274 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
148 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
93 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
73 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
53 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
220 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
61 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
425 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
200 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
48 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
235 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 ...