Questions tagged [find]
search for files in a directory hierarchy
315
questions
119
votes
8
answers
85k
views
Can I make `find` return non-0 when no matching files are found?
Even when /tmp has no file called something, searching for it with find will return 0:
$ find /tmp -name something
$ echo $?
0
How can I get a non-zero exit status when find does not find ...
70
votes
10
answers
165k
views
Linux: using find to locate files older than <date>
find has good support for finding files the more modified less than X days ago, but how can I use find to locate all files modified before a certain date?
I can't find anything in the find man page to ...
62
votes
5
answers
40k
views
A better unix find with parallel processing?
The unix find(1) utility is very useful allowing me to perform an action on many files that match certain specifications, e.g.
find /dump -type f -name '*.xml' -exec java -jar ProcessFile.jar {} \;
...
60
votes
5
answers
68k
views
Bash find command verbose output
Is there way to tell the bash find command to output what it is doing (verbose mode)?
For example for the command:
find /media/1Tb/videos -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \; to output:
...
57
votes
3
answers
61k
views
find command default sorting order
what is the default sorting order for entries returned by the linux find command?
For example, if I issue
find . -type f -name '*mp3'
and the output consists of multiple files across multiple sub-...
48
votes
8
answers
108k
views
Remove path from find command output
I have a bash script for deploying code from a beta environment to a production environment but currently I have to add the list of files to a txt file manaully and sometime I miss some. Basically my ...
42
votes
6
answers
213k
views
Move files to another directory which are older than a date
I am looking for a solution to move files that are year older from today. My log partition is getting full, but I can not remove them. They are needed for a long long time. Anyway one solution I came ...
40
votes
3
answers
111k
views
How to view hidden files using Linux `find` command
On a Linux server, I need to find all files with a certain file extension in the current directory and all sub-directories.
Previously, I have always used the following command:
find . -type f | grep -...
32
votes
8
answers
102k
views
how to find out mac addresses of all machines on network
Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy ...
32
votes
8
answers
22k
views
Linux find command - show progress
I was wondering if there's any way to display some kind of progress info when searching for files in linux using find. I often find myself searching for files on a big disk and some kind of progress ...
32
votes
3
answers
26k
views
How can I handle spaces in file names when using xargs on find results?
One of my common practices is to perform greps on all files of a certain type, e.g., find all the HTML files that have the word "rumpus" in them. To do it, I use
find /path/to -name "*.html" | xargs ...
25
votes
3
answers
24k
views
FreeBSD: How to know real file size on zfs with compression on?
I'm using zfs on my FreeBSD 9.0 x64 and pretty happy with it, but I find it hard to count directory real, not compressed, size.
Surely I can walk over the directory and count every file size with ls,...
23
votes
5
answers
79k
views
How to rsync files / folders from a specific date forward?
I would like to rsync folders from a specific date and forward.
for example. I want to rsync my folders that were created from 3 days ago (and of course 2 days ago, one day ago etc.).
I know I need to ...
22
votes
2
answers
5k
views
How to find files in a Debian system not installed or created by dpkg?
I've installed some things manually in the past and would like to weed out all related files. So, I need a way to automatically find all the files (in /usr, for example) that are not included in any ...
19
votes
5
answers
33k
views
How do I find (or exclude) all directories and sub-directories matching a certain pattern (in Linux)?
I'm trying to use the Linux find command to find all directories and sub-directories that do not have .svn (Subversion hidden folders) in their path. I can only get it to exclude the actual .svn ...
17
votes
3
answers
13k
views
Get all extensions and their respective file count in a directory
Getting all extensions for a directory: easy. Getting file counts for a particular extension: easy.
But getting all file extensions and their respective file counts is alluding me.
eg.
+ dir
+ abc....
17
votes
8
answers
55k
views
How do I find all files and directories writable by a specific user?
Under Linux, how can I find all the files and directories that are writable (or, actually, not writable) by a particular user?
Edit: To clarify, I meant under a particular subdir, not systemwide. ...
16
votes
4
answers
13k
views
How to use find command to delete files matching a pattern?
I'm trying to write a bash command that will delete all files matching a specific pattern - in this case, it's all of the old vmware log files that have built up.
I've tried this command:
find . -...
16
votes
6
answers
55k
views
How can I use netsh to find a rule using a pattern
I'm wondering whether anyone in Microsoft has ever come to a situation where they can't remember a rule's name!
The netsh advfirewall firewall show rule only accepts 1 name and no pattern matching ...
16
votes
1
answer
19k
views
How do I find circular symbolic links?
I'm working on a HP-UX system and I want to find if there are any circular symbolic links.
So far I'm using the command:
ls -lrt `find ./ -follow -type l`
But it's only doing ls -lrt on current ...
15
votes
2
answers
13k
views
find files NOT belonging to group
How do I find files not belonging to particular group?
find /home -group NOT test
14
votes
7
answers
66k
views
How to Find a file in FreeBSD
I'm trying to locate all copies of example.filename on my FreeBSD server. What's the best / easiest / most efficient way to do this?
14
votes
3
answers
22k
views
how to find files with incorrect permissions on unix?
I'm looking for a way to search a directory or directories and list all the files that have the wrong permissions for a public directory.
14
votes
1
answer
472
views
Linux find command is misbehaving
Searching for system-resolved service following the recent vulnerability disclosure, I came to see a very strange behavior from find command.
root@localhost:/# find . -name "*systemd-resolved*"
./...
13
votes
9
answers
8k
views
How do I master the UNIX find command?
I think I am fairly advanced in my use of find but EVERY time I use it I cannot for the life of me remember the method to close the -exec option. I spend a good deal of time reading every time I use ...
11
votes
3
answers
7k
views
Unix magic, delete all .pyc files from a tree of directories?
Is there a quick way of deleting all the .pyc files from a tree of directories?
11
votes
5
answers
27k
views
What is the correct find -exec syntax
I wanted to delete files that were greater than 2MB within a specific folder. So I ran:
find . -size +2M
And I got a list of two files
./a/b/c/file1
./a/f/g/file2
So I then run:
find . -...
11
votes
4
answers
26k
views
Why does FIND on Windows 7 give an "Access Denied" error? [closed]
I have an administrator account on a Windows 7 x64 machine. It is not THE administrator account, the account is simply a member of the administrators group.
The install is default. When the user ...
11
votes
3
answers
20k
views
finding a file which was modified in last 10 minutes
I am running this command to find out the files which were modified in last 10 minutes
find / -fstype local -mtime -10m
but it is giving following error each time
find: missing argument to `-...
10
votes
3
answers
3k
views
Securely use find with sudo
On a Linux server, I need to remove root privileges from a group of users. But those users have legitimate reasons to be able to use the "find" utility to search for files based on file names, ...
10
votes
3
answers
253
views
Find's -true option: what for?
GNU find (and others?) has a -true test along with the normal -name, -mode, -user and so on. From the man page:
-true Always true.
Every time I see the man page I notice this and wonder when it'd ...
9
votes
5
answers
15k
views
How to find all filenames with given extension
I need to find all .pem files on my system. Would the following do this?
sudo find / -type f -name *.pem
If not, how would I write a find command to find every file of the sort?
9
votes
4
answers
8k
views
find only files in directory with permissions not set to 644 on linux
This is my first question although I've been lurking for a while.
Question:
I would like to use find to get only the files in a directory with permissions not set to 644 (or another permission value)....
9
votes
2
answers
4k
views
Linux & SVN: How to remove all versioned files but KEEP directory structure, ignore .svn dirs?
I want to remove all the versioned files from my repository, but KEEP the versioned directory structure. Obviously I want to leave all the .svn directories untouched.
In other words, I want to ...
8
votes
7
answers
5k
views
Linux Colorize Find?
Is it possible to 'colorize' the output from find?
I have a find that searches /home on all of my servers, and exec 'rm' certain files. As these are mixed in with my other find results, among ...
8
votes
5
answers
13k
views
How to remove directory on NFS fileystem with an enormous number of files
A poorly tested program created a directory on an NFS share with an enormous number of files, which I need to remove.
ls -ald /home/foo
drwxrwxr-x 2 503 503 317582336 Jul 29 11:38 /home/foo
The ...
8
votes
1
answer
19k
views
Find, and sort results by date created
How can I sort the results of find? I want to sort by date created asc?
find /docs -type f | sort
Sorts by filename not date created. Thanks.
7
votes
4
answers
27k
views
Why does "find -mtime" not work as expected on files with different timezones?
I have some files on a server with the date several months ago, but they are invisible to find -mtime 7 search.
When I list them with ls -l, they look perfectly normal:
-rw-r--r-- 1 root root ...
7
votes
3
answers
5k
views
Non-recursive find on linux
I am trying to find all directories that are directly inside the current directory and older than a specific age. The trick is, I only want to consider the age of the immediate descendants of the ...
7
votes
3
answers
964
views
Using `find` to delete
So, given three options...
find .... -delete
find .... | xargs rm ...
find .... -exec rm ...;
..or variations thereof, which option is preferable?
I'm guessing there is no hard and fast answer, ...
7
votes
4
answers
2k
views
Bash: execute command on results of FIND
I am trying to resize all files that are found using a FIND command (they are all files within a directory and its subdirectories). I tried many options but stumble across different errors each time. ...
7
votes
4
answers
16k
views
Locate, Find, Which - How do I launch an index/scan command for these utilities?
How do I re-scan my drive so my 'search utilities' are able to find a new file on my system?
I'm having a tough time googling HOW TOs for launching an index/scan command to any of this applications. ...
7
votes
2
answers
5k
views
Why does this regex not work on linux?
I can't say it works on Windows but from my understanding this regex is correct and how I would write it (except maybe the ^ at the beginning)
From http://www.velocityreviews.com/forums/showpost.php?...
7
votes
1
answer
729
views
File is too big for /dev/null
While testing a problem LUN for read errors, I encountered the following problem:
find /mnt/problem_lun/ -type f -print -exec dd if={} of=/dev/null bs=8k \;
...
/mnt/problem_lun/a_file
dd: writing `/...
7
votes
4
answers
14k
views
Find the location of libmysqlclient.so.X file in Linux environments
I'm putting together a script that has a requirement of knowing libmysqlclient.so.[15|16|18] .so file. It's usually located in /usr/lib/ , /usr/lib64/ or a mysql/ subdirectory of the aforementioned ...
7
votes
2
answers
5k
views
List directories not containing a file
I've seen similar questions to this, but nothing I can find related directly to files.
Is there any way to give me a list of directories which do not contain a specific file?
Example:
/dir1/good
/...
6
votes
6
answers
6k
views
Get Size of All Folders in Directory
I want to get the size of all directories within a specific directory. I was thinking something like
find . -type d -exec du -sh {} \;
But that returns all directories recursively. How can I limit ...
6
votes
3
answers
671
views
Difficult to Delete Files in Linux
There's a lot of stuff about this on the Internet, but most of the examples there are contrived. How does one delete files that are really stubborn? e.g.,
$ find ./ -inum 167794
./àKÈÿÿÿÿ@
$ find ....
6
votes
2
answers
12k
views
How to count all subfolders in an directory?
How can I count how many folders (including subfolders) I have under an specific folder?
6
votes
2
answers
33k
views
rsync only files created or modified after a date and time
The goal is to rsync (or using any other tools that give the desired result) only files that are created or modified after a date. It should work with filenames containing spaces (and/or other ...