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

learn more… | top users | synonyms

1
vote
1answer
56 views

passing ls variable to grep when doing a file search only works inside directory

I am running a command that I use to find the most recent file in a folder then grep the contents for a matching pattern. Here is the command flow that shows the problem I am having. root@backup /]# ...
3
votes
2answers
96 views

find latest file created in folder and grep contents

I have a need to search a certain folder for the newest created file and grep the contents for a pattern. I have had ok success so far using this command: find /var/log/folder -type f -printf '%T+ %p\...
3
votes
4answers
94 views

'find -mtime -1 -print | xargs tar' archives all files from directory ignoring the -mtime -1 argument

I'm trying to create a backup script. I've managed to get this script working fine on a CentOS 6.7 machine and am now trying to get it working properly on Debian 7. I am running into a problem I can'...
1
vote
3answers
82 views

How can I recursively replace a string in file and directory names?

I have a git clone of etckeeper, and I'm trying to rename all files and directories with etckeeper in the name to usrkeeper. For example, ./foo-etckeeper-bar should be renamed to ./foo-usrkeeper-bar. ...
0
votes
0answers
39 views

How to create a symbolic link of all files in a directory using a shortened name obtained with using a piped cut on the filename

I have a directory full of libraries (*.so.0.*), and I want to use find to create a symbolic link to each file, named *.so.0. Here is a (non working) try: find $HOME/.local/lib64/ -name "lib*.so.0.*"...
1
vote
2answers
32 views

How to get all subfolder names consisting of uppercases only?

How to get the folders in a parent folder, the names of which are composed of A-Z, without lowercases, underscore, dot or any other things?
0
votes
0answers
43 views

find awk log print error

I'm trying to find one year old directories named in yyyymmdd format and print it in the log file placed at different location. find ${LOG} -maxdepth 1 -type d -mtime +${DAY} -name '20[0-9][0-9][0-9][...
3
votes
3answers
315 views

Copy subfolders containing at least n files

I have a folder root_folder containing a lot of subfolders. Each of these subfolders contains a small number of files (between 1 and 20) and I want to copy all the subfolders containing at least 5 ...
1
vote
1answer
18 views

Format for iname in Find operation

When using find what is the correct format to say "Find files that end in .jpg OR .png"? Is it as simple as using the | operator/character? find -iname "*.jpg|*.png"
0
votes
1answer
25 views

Linux red hat + replace PATH or word on scripts

Under folder: /var/userTN/applo folder I have around ~100 shell scripts that include the following PATH: GLOBAL_PATH=/export/pop/PLW5 I want to replace the PATH on all the scripts under folder: ...
0
votes
1answer
22 views

How to display only .txt files with the name ScheduledJobs in them

I have tried this: find ~/ops_scripts -type f -maxdepth 1 -name "ScheduledJobs*" but I'm not sure how to get only .txt files to display.
3
votes
1answer
47 views

Understanding the following find command

I am currently having a hard time understanding the following find command: find / -o -group `id -g` -perm \  -g=w -perm -u=s -o -perm -o=w\ -perm -u=s -o -perm -o=w \ -perm -g=s -ls  ...
1
vote
3answers
38 views

Script or command to list all top-level directories that contain sub-directories with modified files less than 30 days old

This is quite a unique one. I'm looking for a way to list all top-level directories in a folder that contain sub-directories with new or modified files less than 30 days old in them. We use a ...
0
votes
1answer
30 views

Recursive Directory search, Showing most recent file in folder

Can someone point out where am going wrong please. Am doing a directory search (Based on the folder structure and file type) The folder structure is the same for every customer. Just the customer ...
3
votes
2answers
278 views

How can I find files with a long first line?

currently I have a problem with a server. One user who is hosting a lot of sites got hacked and some of his php files were modified. Now I want to get a list of the infected files and also want to ...
1
vote
2answers
51 views

How to rename certain directories if the parent has a particular name?

I have to do some global renaming in an Eclipse plugin project, although the fact that the code is Java and it's an Eclipse plugin is irrelevant. Basically, the steps I need to perform are the ...
1
vote
2answers
62 views

How do I remove all files from wtihin a certain directory except for a child directory of that directory?

I’m using bash shell. I have this command to delete all JAR files within a particular directory find ~/.jenkins/jobs/subco/ -name '*.jar' -print0 | xargs -0 -r rm However, I want to modify the ...
0
votes
2answers
49 views

Finding special characters in name

How do I find files that have ~ * and other special characters in the name? e.g. find . -name "*\*" should match "any characters" and then *, but it matches nothing; how can I get the command to ...
1
vote
2answers
39 views

Finding files and directories with different umask

I have an umask as a 0002 using umask -S it returns u=rwx,g=rwx,o=rx. How do I find all files and directories that does not have rights set up according to mask? The directories goes 777 - mask and ...
1
vote
2answers
40 views

Regex in find - OS X

I cannot figure out what's wrong with my regex, it seems to be working with grep but now with find. I'm trying to find all the files which follow the common expression in TV shows e.g. S02E21. find -...
1
vote
1answer
43 views

Printing the file with number of hardlinks

I can print the number of hardlinks to files in directory by using find . type f -printf "%f %n\n" but this will also print the hardlink not only original files: Example: file1 is an original ...
0
votes
0answers
38 views

Fixing Signal 13 Error on find

I have a situation where I'm trying to install softwares into my system. I'm using a fakeroot approach to install them in a separate directory where I'm listing all the files, directories and links ...
1
vote
1answer
126 views

Evaluation of find ( -exec )

I'm searching for all files that contain one of a set of strings. If they do, I change their access rights. find . -type f -exec grep -q '#!/bin/bash\|#!/usr/bin/grep\|#!/usr/bin/awk' {} \; -exec ...
13
votes
1answer
192 views

Why does `find . -type f` take longer than `find .`?

It seems like find would have to check whether a given path corresponds to a file or directory anyway in order to recursively walk the contents of directories. Here's some motivation and what I've ...
3
votes
2answers
45 views

How can I do a breadth-first search using `find`?

The -depth primary to find causes it to perform a depth-first search. However, the default sequence is not a breadth-first search. The default sequence could be informally described as a "depth-...
2
votes
2answers
54 views

Delete directories that contain a certain file

I want to find all directories that contain a certain file and then delete those directories. With find . -name thatcertainfile -execdir pwd \; I get a list of all the directories I want to delete, ...
1
vote
2answers
39 views

Rename all the files with a specific extension in all the subdirectory [duplicate]

I have a lot of directories. Each one of these has a file with a specific extension .ext. I want to rename these files. Example: // Note: The names are random, can have spaces and special ...
4
votes
1answer
42 views

`find` return value: Is the find man page wrong?

The find man page says: -execdir command {} + always returns true, while -execdir command {} ; returns true only if command returns 0. and EXIT STATUS find ...
1
vote
4answers
64 views

Why is it find dir -name file and not find -n dir file?

I've searched around for this but I couldn't find anything on it. I've always wanted to know, why is it that most other built in bash commands have the format of command -flag arg1 arg2, i.e. cp -r ...
0
votes
2answers
30 views

Having trouble deleting specific directories within a specific parent directory

I’m using Amazon Linux, bash shell. I’m trying to write a statement that will delete all child directories named “target” within a specific master directory. I would like to write things such that ...
2
votes
1answer
46 views

How do I search find files and compress if greater than 500M

I need to find files greater than 500M and older than 1 day and I need to compress those files. Also I need to omit files with .gz extension. How can it be achieved?
1
vote
1answer
24 views

How do I get a count of files in a directory (recursively) but exclude directories with a certain name

This is very similar to this question, but I need to take it a bit further. I'm using a synology drive and there are tons of @eaDir directories which I want to ignore (and the files in those ...
1
vote
1answer
39 views

Is there a standard abbreviation for 'find . -name foo' or do I need a function for this?

I recently used find . -name some-file-name a lot and decided that it's time to abbreviate this with a function (fb stands for find below): function fb() { find . -name "$1" } This seems to work ...
0
votes
1answer
81 views

Find not working

The find command is not working as expected on my OSX with oh-my-zsh. A few examples: $ find . -name test find: .: Invalid argument $ find usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [...
3
votes
3answers
105 views

Using grep/sort/find to extract unique values

I have a bunch of text files that are named in YYYYMMDD.Txt format (so today would be 20160420.Txt). Each file is basically a log that contains a timestamp and and a unique ID, each value is ...
1
vote
1answer
43 views

Rewrite a find command that uses sed -i for AIX

I have a script that searches for a string and replaces it via the sed command. If that string contains special characters, the script will escape them (except for the slash because it's my current ...
2
votes
2answers
39 views

Instead of using ls, how does it make work with `find`?

I have this command: ls -Ra | grep -cve/ -e'^\.*$' and I would like to do exactly the same with find I tried this find . -name "^\.*$" -o -print | wc -l but the problem is, if I create new file ...
4
votes
3answers
388 views

What's the quickest way to find duplicated files? [duplicate]

I found this command used to find duplicated files but it was quite long and made me confused. For example, If i remove -printf "%s\n", nothing came out. Why was that? Besides, why they used xargs -I{}...
2
votes
2answers
15 views

How to ignore passed directory in find command directory search?

I'm trying to perform the same process on all subdirectories. This should exclude the current directory, but I'm still matching on that and I don't know why. # Make a dummy file tree to test with ...
0
votes
1answer
44 views

How to generate a text report in Linux?

I have a command I'm using to find all of the *.xml files on our server. I'm using: find -type f -exec grep -il "xml" {} \; This is great, but there are maybe a thousand files like this on the ...
0
votes
1answer
31 views

How could I quickly find a recursive symbolic link? [duplicate]

I am experiencing an issue with a indexing program running much longer than expected. I want to rule out the possibility of a recursive symbolic link. How could I find a symbolic link that is ...
5
votes
5answers
535 views

Is it possible to run ls or find and pipe it through stat?

Is there a way to run ls or find to get the list of files within a directory and then run stat to get all of the specific information (i.e. File Group, File Name, File Owner, File Size (displayed in K,...
0
votes
1answer
40 views

How do I count the number of files in all subdirectories and add the counts together

I am trying to count the number of file in each directory/subdirectory, add them together and get a total which I can then compare to another directory: #!/bin/bash echo "Checking directories for ...
1
vote
1answer
71 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ....
-1
votes
1answer
27 views

Operator precedence in a find command?

See below example: $ ls -1p appledir/ applefile orangedir/ orangefile $ find . -type f -name apple\* ./applefile $ find . -type f -name orange\* ./orangefile $ find . -type f -name apple\* -o -name ...
2
votes
2answers
87 views

find: delete folder and sub folders but add exception to two files

I am trying to use the find command to do the following: Delete a whole folder with files, folders and subfolders except for 2 files, here is an example of what I need: test/folder1/file1.txt test/...
1
vote
2answers
68 views

Read files from directory and organize them by extentsion into corresponding folders

I'm trying to create a bash function script that will allow me to create multiple directories with the names below. I'm also trying to organize files by extension into their corresponding folders (i.e....
1
vote
3answers
55 views

Is there a faster way to find specific files than using find?

I have to find in a folder the files not having certain permissions (755). The sub-directory has other sub-directories containing in total millions of files, and the find ./ -not -perm 755 command it ...
1
vote
1answer
48 views

Why does `find -size -1G` not find any files?

When I issue: find / \( -type f -size +10M \) -and \( -type f -size -1G \) I don't receive any results; however, when I type: find / \( -type f -size +10M \) -and \( -type f -size -1000M \) ...
1
vote
2answers
55 views

find all hard linked files between two directories

How do I find if any files among two or more directories are hard linked? In other words, do any files under two or more directories refer to the same file? Similar to How to find all hard links to ...