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

learn more… | top users | synonyms

4
votes
1answer
4k 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 ...
3
votes
1answer
36 views

How to find files/directories with specific ACL

How to I do something like find . -acl u:jim:rx find . -acl u:*:r find . -noacl u:jim:r etc. I know that the find command does not support this but, you have the idea. Are there any scripts, even ...
-4
votes
1answer
36 views

How to tell xargs to unpack tar into certain directory [on hold]

I wrote my first script which goes: find /media/temp/test -type f -printf '%T@ %p\n*.tar.gz' | sort -n | tail -1 | cut -f2- -d" " | xargs tar -xvpf I would like to find latest modified file which ...
2
votes
2answers
62 views

How to find a specific file and move it to a specific directory?

How to find a specific file, and move it to the specific directory /var/tmp? For example I want to find the file 0914_Jul-2014.gz. Remark, the file 0914_Jul-2014.gz, is under ~300 subdirectories: ...
6
votes
4answers
4k views

Preserve directory structure when moving files using find

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
7
votes
6answers
41k 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 ...
3
votes
3answers
148 views

Using `find`, how can I get `rm` to print a fuller path name than it does when executed through `-execdir`?

Summary of Answers: while literature promotes "-execdir" as safer than "-exec", do not ignore the operational difference. The former is not a simple reimplementation of the latter. Also, when using ...
6
votes
4answers
8k 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 ...
0
votes
1answer
151 views

Trying to pass user generated variable to an external command

I have a bash script that is asking a user for input, then passes that variable to a find command. I've tried quoting/escaping the variable every way I know, but it keeps failing. read -p "Please ...
1
vote
1answer
27 views

In which directory is node running?

In trying to figure out how some application that listens on port 8088 is running, I see that it has PID 15020: $ netstat -ntulp Proto Recv-Q Send-Q Local Address Foreign Address ...
4
votes
2answers
107 views

Find and create empty files with the same name in another location

I want create empty files with the same name, but in another location. Is it possible? find some files use only filenames touch an empty file in another place Something like this: find . -type f ...
0
votes
1answer
59 views

bash: What is the difference between these two script variants?

(Note: Both of these examples may require GNU or BSD find and may not work as-is with the POSIX "edition" of find). Both of the scriptlets below must be understood as excerpts from way more complex ...
9
votes
4answers
7k views

find -exec in bash script with variable expansion

I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir. ...
1
vote
1answer
27 views

Copy only files between two times [closed]

I'm trying to copy pictures taken between two times, from one directory to another. I’ve managed to list them using this command find /mnt -type f -name "*.jpg" -newermt "2014-12-14 01:00:00" ! ...
1
vote
1answer
20 views

How do I find/list all files on filesystem with a certain SELinux “fcontext”

I'm having trouble finding information on what command, presumably from setools, I should use to find all the files on my filesystem that are labeled by SELinux with a certain file-context (fcontext). ...
1
vote
1answer
45 views

Change file ownership recursively without errors

I am trying to write a script that fixes the ownership of all files owned by a specific user, after changing the user's UID. Currently, I run: chown -Rhc --from=${OLD_UID} ${NEW_UID} / chown -Rhc ...
2
votes
1answer
44 views

Find files older than x amount of time in specific directory with ignoring subdirectories

My setup is as following: folder structure dir |--correctfile1 |--correctfile2 |--correctfile3 |--subdir1 |--wrongfile1 |--wrongfile2 |--wrongfile3 |--subdir2 |--subdir3 I need to ...
9
votes
6answers
11k views

How to report number of files in all subdirectories?

I need to inspect all sub-directories and report how many files (without further recursion) they contain: directoryName1 numberOfFiles directoryName2 numberOfFiles
4
votes
2answers
228 views

How to quote arguments with xargs

Suppose that I want to delete all files in a folder that are greater than 1 MB. $ find . -size +1M | xargs -0 rm This will not delete files that have space in their names. So I want it to quote all ...
6
votes
3answers
282 views

find all end subdirectories in a tree

given the following structure: oz123@debian:~/ $ tree . . ├── a │ ├── a1 │ ├── a2 │ └── a3 ├── a1 │ ├── a11 │ ├── a12 │ └── a31 ├── b │ └── b1 │ ├── b11 │ │ └── b21 │ ...
0
votes
2answers
39 views

How to save stat of all files found in a search?

I had a cron which removes all files with a specific pattern from temp. find /tmp/* -type f -iname magick-* -exec rm {} \; Now, I want to log the stat of all files before deleting them for future ...
2
votes
3answers
143 views

find, xargs and mv: renaming files with double-quotes, expansion and bash precedence issue

Ok, I'm simply trying to strip out double-quotes in my filenames. Here's the command I came up with (bash). $ find . -iname "*\"*" -print0 | xargs -0 -I {} mv {} {} | tr -d \" The problem is the ...
0
votes
3answers
37 views

Cannot prompt user using rm bultin prompt option -i with xargs and find

I am using xargs and rm with find in order to remove files that follow a specific pattern defined by find as follows. touch file find . -name file | xargs rm Everything works fine with the above ...
2
votes
2answers
48 views

Deleting files older than a month [duplicate]

Need to delete all sub-directories which are a month old. But last day of the month data should be ignored for previous three months. The data representation is as follows: bkp_01102014 ...
1
vote
1answer
504 views

find and exec: why does this command not work?

I don't get why echo prints empty line (latest cygwin version): ~/tmp >find mydor/ -name "*php" mydor/es/c/packags.php mydor/etns/inx.php mydor/pacepors.php mydor/XAE.php ~/tmp >find mydor/ ...
5
votes
4answers
4k views

Recursively rename files and directories

I'm using this command to rename files: for fname in *; do mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ') done But it only renames in the current directory. Let's say I have many ...
2
votes
4answers
72 views

Find files that end with number

Im trying to make some backup script as the log files get bigger and bigger. What i have is coping the current file, (for example secure file in /var/log/) and remove the content from that file. But ...
3
votes
6answers
95 views

How to show distinct directories on find?

I want to find all directories containing, for example, files named *.txt. but the output must not contain duplicates. How to do it?
0
votes
3answers
62 views

How to find a file in Unix using find command?

I have been trying to search for a file which contains a specific pattern. The pattern is itself in a variable tmpfl echo $tmpfl --> ack_2* Now to find for the file in the current working ...
2
votes
1answer
40 views

find command sometimes results in non-matching files being zipped

I'm trying to make a zip file of all the files in a specific directory which were modified in the last x minutes. Here's my command: find "/path/to/dir" -mmin -30 -not -name ".*" -exec zip -r ...
2
votes
1answer
38 views

Find Command: File Path vs -name Argument

I'm currently building a script to handle some files in a directory. In the first example, I use the find command and pass a directory in as the argument. In the second I instead use the -name switch ...
0
votes
2answers
49 views

linux + find command with rm -rf

why the following command removed the tmp directory under /var and how to avoid this? find /var/tmp -type d -ctime -1 -exec rm -rf {} \; pwd /var/tmp [root@linux /var/tmp]# find /var/tmp -type ...
1
vote
3answers
46 views

Remove old directories according to directory's name?

In my bash script I create a directory each month for backups as follows: DAY=$(date -d "$D" '+%d') MONTH=$(date -d "$D" '+%m') YEAR=$(date -d "$D" '+%Y') mkdir -p /var/app/backup/$DAY$MONTH$YEAR ...
2
votes
2answers
42 views

find and delete gives false status

I tried to execute delete as per many previous discussions occurred find & delete however my attempts lead to different experience. find . -type d -name "koko" -exec rm -rf {} \; deletes the ...
0
votes
1answer
42 views

How to find files which have been modified in the last 50 days? [duplicate]

How can I find all the files which have been modified 50 days before? I'm trying this: find -maxdepth 1 -mtime -50 is it the right command to find files that have been modified in the last 50 ...
1
vote
2answers
29 views

Find command with -ctime +0 for testing

The following command will delete directories and sub directories that are older then 100 days: find /var/tmp -type d -ctime +100 -exec rm -rf {} \; But actually I want to perform the test to ...
2
votes
4answers
229 views

Copy files and directory tree for filesize in specified range

Hi I would like to make a small script copying files from different directories example /pp/01 /pp/02/ etc... to another destination with the same directory design. But only those files within the ...
1
vote
2answers
32 views

How to limit the number of search results per directory

How to limit the number of search results per folder, for example: With this command: grep --include=*.php -Ril '<?' '/var/www/' I get the following: /var/www/test.php /var/www/test1.php ...
2
votes
3answers
55 views

Find files that have a confirmed duplicate in same directory recursively

Say I have the following directory structure: root |-- dirA |-- file.jpg |-- file-001.jpg <-- dup |-- file2.jpg |-- file3.jpg |-- dirB |-- fileA.jpg |-- ...
2
votes
1answer
31 views

'Tar' the result of a 'find', preserving the directory structure

I want to tar all the *.txt file, that I get from the result of a find, that exist into a directory having a tree like this: Directory_name dir1 file1.pdf file1.txt dir2 file2.pdf ...
3
votes
1answer
380 views

Omitting extension with find?

I need to create thumbnails from multiple .png files and would like to do this using ImageMagicks convert utility. To recursively find all files that are not thumbnails themselves, I am using the ...
6
votes
4answers
304 views

what's the difference between using 'single quotes' or not in find command

find ~/ -name *test.txt find ~/ -name '*test.txt' Can anyone help me to construct an example where the first form fails but the second still works. And tell me the difference between them.Thanks!
0
votes
1answer
37 views

Issue finding lines using grep in UNIX [closed]

I am trying to use a .txt file with around 5000 patterns (spaced with a line) to search through another file of 18000 lines for any matches. So far I've tried every form of grep and awk I can find on ...
27
votes
3answers
8k views

How to stop the find command after first match?

Is there a way to force the find command to stop right after finding the first match?
1
vote
0answers
35 views

trash and restore script - issue restoring

#!/bin/bash echo "Are you sure you want to move this file to the Recycle Bin?" "(Yes/No)" read ans case "$ans" in Yes) echo "$(readlink -f $1)" >> "$HOME/TrashLog" && mv "$1" ...
0
votes
1answer
65 views

What does newermt mean in find command?

I know I can use this option to find file between particular modified times. But I'm curious about what does this mean? I used man find | grep newermt trying to find something. But I got no direct ...
5
votes
6answers
5k 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
1k views

Delete n minutes old file in solaris

Can some one please tell me how to delete n minutes old files in Solaris? My find does not -mmin option.
1
vote
2answers
102 views

Sort files according to their extensions

I have made a script that will sort files according to their extension and place them in the proper folder. For example, place abc.jpg in the directory jpg. #!/bin/bash #this script sorts files ...
-1
votes
3answers
44 views

How to print the base file name using find in Unix?

I have been trying to print out the base file names using find in Unix. To simply print out the file names the command I have been using is this find . -type f -name \*.out -print It prints out ...