Questions tagged [find]

search for files in a directory hierarchy

Find is used to look files in a directory hierarchy. You can refer to its manpage here.

Examples:

Look for all files on a server owned by user siegfried:

 find / -user siegfried

Find all files ending in php en remove them:

 find / *.php -exec rm '{}' \;
307 questions
100
votes
8 answers

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 anything?
yael
  • 1,199
  • 4
  • 13
  • 13
62
votes
9 answers

Linux: using find to locate files older than

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 do this, only to compare against another files…
DrStalker
  • 6,676
  • 24
  • 76
  • 106
59
votes
5 answers

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 {} \; The above might run a script or tool over every…
PP.
  • 3,246
  • 6
  • 26
  • 31
54
votes
5 answers

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: Found /media/1Tb/videos/102, executing rm -rf…
Alex
  • 1,768
  • 4
  • 30
  • 51
51
votes
3 answers

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-folders, what is the default order in which…
Nasko
  • 513
  • 1
  • 4
  • 4
44
votes
8 answers

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 deployment script cat/loops copying the files…
Mikey1980
  • 711
  • 1
  • 8
  • 12
38
votes
6 answers

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 up with is: find /sourcedirectory -mtime 365…
cr0c
  • 1,116
  • 3
  • 15
  • 32
33
votes
3 answers

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 -i *.php However, it doesn't find hidden files,…
Tom
  • 4,157
  • 11
  • 41
  • 52
32
votes
3 answers

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 grep -l "rumpus" Occasionally, find will return a…
abeger
  • 461
  • 1
  • 4
  • 6
32
votes
8 answers

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 solution.
Registered User
  • 1,453
  • 5
  • 18
  • 37
29
votes
8 answers

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 indicator would be very helpfull, like a bar or at…
Vlad Balmos
  • 395
  • 1
  • 3
  • 6
23
votes
3 answers

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, but I'd expect some extra key for du for that…
Alexander
  • 724
  • 2
  • 11
  • 19
20
votes
2 answers

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 of the packages currently installed on the Debian…
Karol
  • 323
  • 2
  • 9
18
votes
5 answers

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 directories themselves, but not any of the…
Jason Down
  • 303
  • 1
  • 6
  • 11
16
votes
4 answers

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 . -name vmware-*.log | xargs rm However, when I run the…
Dan Monego
  • 285
  • 1
  • 2
  • 7
1
2 3
20 21