Questions tagged [find]

This tag has multiple meanings. Please DO NOT use this tag if you're just trying to find something.

find is:

  1. a filesystem search tool on various flavors of *nix,
  2. a filesystem search tool on various flavors of DOS and Windows,
  3. the name of a jQuery method,
  4. the name of a family of methods in ActiveRecord,
  5. a function in the C++ standard library,
  6. a method of strings in Python,
  7. a method of Matcher Class in Java.
  8. a method in many different NoSQL's to find documents in a collection.
11183 questions
179
votes
5 answers

Command line: piping find results to rm

I'm trying to work out a command which deletes sql files older than 15 days. The find part is working but not the rm. rm -f | find -L /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups -type f \( -name '*.sql' \) -mtime +15 It kicks out a list of…
jerrygarciuh
  • 21,158
  • 26
  • 82
  • 139
178
votes
13 answers

Python ElementTree module: How to ignore the namespace of XML files to locate matching element when using the method "find", "findall"

I want to use the method of findall to locate some elements of the source xml file in the ElementTree module. However, the source xml file (test.xml) has namespaces. I truncate part of xml file as sample:
KevinLeng
  • 1,843
  • 2
  • 12
  • 7
171
votes
11 answers

Check if one list contains element from the other

I have two lists with different objects in them. List list1; List list2; I want to check if element from list1 exists in list2, based on specific attribute (Object1 and Object2 have (among others), one mutual attribute (with type…
Ned
  • 3,961
  • 8
  • 31
  • 49
170
votes
8 answers

How to strip leading "./" in unix "find"?

find . -type f -print prints out ./file1 ./file2 ./file3 Any way to make it print file1 file2 file3 ?
breadjesus
  • 1,979
  • 3
  • 13
  • 8
170
votes
4 answers

Ruby Array find_first object?

Am I missing something in the Array documentation? I have an array which contains up to one object satisfying a certain criterion. I'd like to efficiently find that object. The best idea I have from the docs is this: candidates = my_array.select…
Dan Halabe
168
votes
16 answers

Best way to handle list.index(might-not-exist) in python?

I have code which looks something like this: thing_index = thing_list.index(thing) otherfunction(thing_list, thing_index) ok so that's simplified but you get the idea. Now thing might not actually be in the list, in which case I want to pass -1 as…
Draemon
  • 33,955
  • 16
  • 77
  • 104
168
votes
3 answers

Delete files older than 10 days using shell script in Unix

I want to delete scripts in a folder from the current date back to 10 days. The scripts looks like: 2012.11.21.09_33_52.script 2012.11.21.09_33_56.script 2012.11.21.09_33_59.script The script will run in every 10 day with Crontab, that's why I need…
Steve88
  • 2,366
  • 3
  • 24
  • 43
165
votes
17 answers

How do I get the find command to print out the file size with the file name?

If I issue the find command as follows: find . -name *.ear It prints out: ./dir1/dir2/earFile1.ear ./dir1/dir2/earFile2.ear ./dir1/dir3/earFile1.ear I want to 'print' the name and the size to the command line: ./dir1/dir2/earFile1.ear 5000…
Brian
  • 13,412
  • 10
  • 56
  • 82
164
votes
6 answers

How to find the files that are created in the last hour in unix

How to find the files that are created in the last hour in unix
Ankur
  • 2,321
  • 3
  • 17
  • 7
162
votes
13 answers

How can I search for a multiline pattern in a file?

I needed to find all the files that contained a specific string pattern. The first solution that comes to mind is using find piped with xargs grep: find . -iname '*.py' | xargs grep -e 'YOUR_PATTERN' But if I need to find patterns that spans on…
Oli
  • 15,345
  • 8
  • 30
  • 36
160
votes
4 answers

Find all elements on a page whose element ID contains a certain text using jQuery

I'm trying to find all elements on a page whose element ID contains a certain text. I'll then need to filter the found elements based on whether they are hidden or not. Any help is greatly appreciated.
user48408
  • 3,234
  • 11
  • 39
  • 59
158
votes
6 answers

How to select where ID in Array Rails ActiveRecord without exception

When I have array of ids, like ids = [2,3,5] and I perform Comment.find(ids) everything works fine. But when there is id that doesn't exist, I get an exception. This occurs generaly when I get list of IDs that match some filter and than I do…
Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327
156
votes
8 answers

How can I store the "find" command results as an array in Bash

I am trying to save the result from find as arrays. Here is my code: #!/bin/bash echo "input : " read input echo "searching file with this pattern '${input}' under present directory" array=`find . -name ${input}` len=${#array[*]} echo "found :…
Juneyoung Oh
  • 7,318
  • 16
  • 73
  • 121
145
votes
8 answers

How can I find a specific element in a List?

My application uses a list like this: List list = new List(); Using the Add method, another instance of MyClass is added to the list. MyClass provides, among others, the following methods: public void SetId(String Id); public…
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
145
votes
8 answers

PowerShell Script to Find and Replace for all Files with a Specific Extension

I have several configuration files nested like such: C:\Projects\Project_1\project1.config C:\Projects\Project_2\project2.config In my configuration I need to do a string replace like such: will become:
Brandon
  • 10,744
  • 18
  • 64
  • 97