Re: How to find directories that only contain a certain type of files (e.g., .txt)?

2023-09-15 Thread Peng Yu
On Tue, Sep 12, 2023 at 6:13 PM raf wrote: > > On Tue, Sep 12, 2023 at 06:39:32PM +0200, Andreas Metzler > wrote: > > > On 2023-09-12 Peng Yu wrote: > > > Hi, > > > > > How to find directories that only contain a certain type of files (e.g., > &g

How to find directories that only contain a certain type of files (e.g., .txt)?

2023-09-12 Thread Peng Yu
Hi, How to find directories that only contain a certain type of files (e.g., .txt)? One idea that I have is to just search for all files' paths. Then use a post-processing script to analyze which directories only contain files of a certain type (e.g., .txt extension). Does anybody have a better

Re: best way to find and delete (may contains directories)

2021-03-28 Thread Peng Yu
On Sun, Mar 28, 2021 at 4:31 AM Bernhard Voelker wrote: > > On 3/27/21 10:16 PM, James Youngman wrote: > > Personally, I would probably use -delete to avoid the overhead of -exec > > entirely (the explicit -depth is essentially only there for documentation): > > > > find . -depth \( -path '*0/*'

best way to find and delete (may contains directories)

2021-03-26 Thread Peng Yu
Hi, If just find is used, the following error will be printed. There are many ways to solve this problem. $ mkdir -p {x..z}/0/ $ touch {x..z}/0/1.txt $ find -name 0 -delete find: cannot delete ‘./z/0’: Directory not empty find: cannot delete ‘./x/0’: Directory not empty find: cannot delete ‘./y/0

How to suppress "terminated by signal 13"?

2021-01-14 Thread Peng Yu
Hi, I want to suppress the message "xargs: ls: terminated by signal 13". $ find . -type f | xargs ls -altr | head ... xargs: ls: terminated by signal 13 I could use this. But I don't want to miss other error messages. Is there an option of xargs to just suppress this message? Thanks. $ find . -

How to just print the first n entries found?

2020-07-05 Thread Peng Yu
Hi, I don't find `find` has an option to limit the entries to print only to the first n entries. Is there such an option available? Thanks. -- Regards, Peng

Re: How to search for file with size >= a given size?

2020-05-10 Thread Peng Yu
It seems that +1 includes 1 block. Is it so? If it is the case, then it is not consistent with +1c which does not include 1c? Thanks. On 5/10/20, Andreas Metzler wrote: > On 2020-05-10 Peng Yu wrote: >> Hi, > >> I only see find's --size support + and - which means >

How to search for file with size >= a given size?

2020-05-10 Thread Peng Yu
Hi, I only see find's --size support + and - which means > or <. Is there a way to search for >= or <=? Thanks. -- Regards, Peng

Re: recursive find in current and parent etc until an item is found

2020-04-12 Thread Peng Yu
OK. So this will make sure `/d1/d2/d3` will not be searched multiple times? Or it is still searched when `/d1/d2`, `/d1` or `/` is searched? On 4/12/20, Bernhard Voelker wrote: > On 2020-04-11 12:19, Peng Yu wrote: >> Recursive also means subdirectories, sub subdirectories, etc. >

Re: recursive find in current and parent etc until an item is found

2020-04-11 Thread Peng Yu
Recursive also means subdirectories, sub subdirectories, etc. On Sat, Apr 11, 2020 at 4:17 AM Bernhard Voelker wrote: > On 2020-04-10 19:29, Peng Yu wrote: > > On 4/10/20, Bernhard Voelker wrote: > >> ---8<---8<---8<---8<---8<---8<---8<---8<---8<

Re: recursive find in current and parent etc until an item is found

2020-04-10 Thread Peng Yu
Thanks. I will need to search the parent directory recursively. Does this code only search whether a file is in a parent their parents, etc., but not recursively for a given ancestor? On 4/10/20, Bernhard Voelker wrote: > On 2020-04-10 16:09, Peng Yu wrote: >> Hi, >> >> I

recursive find in current and parent etc until an item is found

2020-04-10 Thread Peng Yu
Hi, I'd like to look for a file by its name in the current directory. If not found, go the the parent and look for it again. If not go up one level again and look for it, ... until it is found (or until a given level is reached). If the file is not found, return an error. The resulted path should

Re: specify a multiple of m arguments in xargs

2020-03-08 Thread Peng Yu
I don't think the `xargs -n 4` in the middle is robust. For example, when the input contains spaces, it won't work as expected. Is there a way to make it robust? $ printf '%s\n' {a..d} | xargs -n 4 a b c d $ printf '%s\n' 'a b' 'c d' 'e f' 'g h' | xargs -n 4 a b c d e f g h On 3/8/20, James Y

Re: specify a multiple of m arguments in xargs

2020-03-06 Thread Peng Yu
Instead of manually specify -n that is a multiple of m which could overflow, maybe xargs should have an additional argument to allow -n be the maximum allowable multiple of m? > $ seq 100 | xargs -n $(( 5 * 2000 )) printf '%s\t%s\t%s\t%s\t%s\n' > /tmp/1.txt > $ < /tmp/1.txt awk -e '!($1 &&

Re: specify a multiple of m arguments in xargs

2020-03-06 Thread Peng Yu
No. I have a program that expects m*n arguments instead of just m (n is an interger). Using `xargs -n m` would make calling the program too many times. On 2/21/20, Bernhard Voelker wrote: > On 2020-02-20 20:46, Peng Yu wrote: >> Hi, >> >> xargs by default does not put a mu

specify a multiple of m arguments in xargs

2020-02-20 Thread Peng Yu
Hi, xargs by default does not put a multiple of m arguments (m is an integer greater than 1) to the command line. But is there a way that I can make sure only a multiple of m arguments are put the command line. For example, for something like the following command, I'd like to make sure everytime

Ensure consistent order of find output

2020-01-26 Thread Peng Yu
Hi, I'd like to make sure the `find -printf '%P\n'` output of a directory (i.e., only relative paths are printed) be consistent among different runs as long as the file paths in the directory are the same. I can pass the `find` output to `sort`. Is it the best way to do so? Thanks. -- Regards,

Is there a way to let find return non-zero when nothing is found?

2019-11-11 Thread Peng Yu
Hi, Sometimes, I'd like to know whether there is nothing found. Is there a way to let find return none-zero when nothing is found? Thanks. -- Regards, Peng

Re: The quickest way to not to descend into sub-directories once a file is found?

2019-10-02 Thread Peng Yu
wrote: > On 2019-09-27 17:26, Peng Yu wrote: > > On 2019-09-27 09:49, Stephane Chazelas wrote: > >> Here, you could do: > >> > >> find . -type d -exec test -e '{}/file.txt' \; -prune -printf > '%p/file.txt\n' > >> > >>

Re: The quickest way to not to descend into sub-directories once a file is found?

2019-09-27 Thread Peng Yu
But wouldn't a scripting language be less efficient than C implementation? I am not sure the time saved by traverse fewer files using pruning will be greater than the time wasted in using a scripting language. I'd like to know this beforehand before I create a custom implementation in a scripting

The quickest way to not to descend into sub-directories once a file is found?

2019-09-26 Thread Peng Yu
Hi, I'd like to find files named `file.txt` recursively. But the directory structure has a property that if any directory has a file `file.txt`, any of its subdirectories will not have file.txt anymore. Therefore, the quickest way to `find` is to stop descending into subdirectories if their ances

Re: How to get the default value of --max-args?

2019-09-21 Thread Peng Yu
> That also depends on a few other factors like .e.g. "env headroom', see > https://git.sv.gnu.org/cgit/findutils.git/tree/xargs/xargs.c#n427 > from line 427 until line 510. > > I don't have Mac OS X, so I can't step through what's the limiting factor > in your case. > > What's your actual concer

Re: How to get the default value of --max-args?

2018-11-08 Thread Peng Yu
On Thu, Nov 8, 2018 at 4:50 AM Bernhard Voelker wrote: > > On 11/8/18 6:50 AM, Peng Yu wrote: > > Hi, > > > > It seems that the default value for --max-args is system dependent. Is > > there a way to find out its default value? Thanks. > > Actually the li

How to get the default value of --max-args?

2018-11-07 Thread Peng Yu
Hi, It seems that the default value for --max-args is system dependent. Is there a way to find out its default value? Thanks. -- Regards, Peng

Re: Why is `find -name '*.txt'` much slower than '*.txt' on glusterfs?

2018-01-27 Thread Peng Yu
> > > glusterfs doesn't provide D_TYPE information: > > getdents(4, {{d_ino=10054722685526780333, ..., d_type=DT_UNKNOWN} ... > > Nevertheless, it is strange that find calls newfstatat() also > in the case of "-maxdepth 1" - it shouldn't need to. Should this be considered as a performance bug of

Re: Why is `find -name '*.txt'` much slower than '*.txt' on glusterfs?

2018-01-27 Thread Peng Yu
> Is your find binary built with D_TYPE support? > > $ find --version > find (GNU findutils) 4.6.0 > Copyright (C) 2015 Free Software Foundation, Inc. > ... > Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION > FTS(FTS_CWDFD) CBO(level=2) > ^^ $ find

Re: Why is `find -name '*.txt'` much slower than '*.txt' on glusterfs?

2018-01-24 Thread Peng Yu
1 getppid 0.000.00 0 1 getpgrp -- --- --- - - 100.000.012473 144757 total On Wed, Jan 24, 2018 at 1:39 AM, Bernhard Voelker wrote: > On 01/24/2018 01:44 AM, Peng Y

Why is `find -name '*.txt'` much slower than '*.txt' on glusterfs?

2018-01-20 Thread Peng Yu
Hi, There are ~7000 .txt files in a directory on glusterfs. Here are the run time of the following two commands. Does anybody know why the find command is much slower than *.txt? Is there a way to change the API that `find` uses to search files so that it can be more friendly to glusterfs? $ time

Re: Why xargs still call the command when there is no input?

2015-06-02 Thread Peng Yu
On Tue, Jun 2, 2015 at 5:50 PM, Morgan Weetman wrote: > > Hi Peng, > > if you read the man page the behaviour is defined (note the "one or more > times"): > > - > xargs reads items > from the standard input, delimited by blanks (which can be protected > with double or singl

Why xargs still call the command when there is no input?

2015-06-02 Thread Peng Yu
The following command will call ls. But since there is no input, shouldn't xargs quit without doing anything? Thanks. xargs -0 ls

Re: How to search for symlinks pointing to directories?

2015-04-18 Thread Peng Yu
On Sat, Apr 18, 2015 at 11:13 AM, Eric Blake wrote: > On 04/18/2015 10:02 AM, Peng Yu wrote: >> Hi, >> >> I don't see there is a way to search for symlinks pointing to >> directories natively in find. >> >> This can be done by using -exec and test. Bu

How to search for symlinks pointing to directories?

2015-04-18 Thread Peng Yu
Hi, I don't see there is a way to search for symlinks pointing to directories natively in find. This can be done by using -exec and test. But I want to avoid using -exec. Is there a way to such a search natively in find? Thanks. -type c File is of type c: b

Re: Faster way to prune directory?

2015-04-16 Thread Peng Yu
On Thu, Apr 16, 2015 at 1:26 AM, Bernhard Voelker wrote: > On 04/16/2015 06:04 AM, Peng Yu wrote: >> Hi, The following code shows that -prune when used with -exec can be >> very slow. Is there somehow a way to speed this up? >> >> ~$ cat main.sh >> #!/usr/bin/

Faster way to prune directory?

2015-04-15 Thread Peng Yu
Hi, The following code shows that -prune when used with -exec can be very slow. Is there somehow a way to speed this up? ~$ cat main.sh #!/usr/bin/env bash tmpdir=$(mktemp -d) function mkalotdir { local n=$1 local i local j local k for i in $(seq -w "$n") do for j in $(seq -w "$n") do fo

Allow `find` to use exported function for -exec*?

2015-04-15 Thread Peng Yu
Hi, It seems that it might be convenient to allow `find` to use exported functions from shell for -exec*? Can this feature be added in the future? -- Regards, Peng

Re: -exec test (use which to only find test once)

2015-03-25 Thread Peng Yu
For my case, it is about 10% time difference. On Wednesday, March 25, 2015, Bernhard Voelker wrote: > On 03/25/2015 11:39 PM, Peng Yu wrote: > > I find that "-exec test ..." can be slower than "-exec $(which test) > > ...". Is possible that `find` internally u

-exec test (use which to only find test once)

2015-03-25 Thread Peng Yu
Hi, I find that "-exec test ..." can be slower than "-exec $(which test) ...". Is possible that `find` internally use "which", so that users don't need to explicitly call it? Thanks. -- Regards, Peng

How test for directory with single quote (') in the name (with find)?

2015-03-04 Thread Peng Yu
Hi, The following code shows that if a directory has single quote in the name, it does not work. Does anybody know what the correct way is to use -exec to test when there is single quote in the command? Thanks. /tmp/tryfind$ find . -type f ./'/.export /tmp/tryfind$ find . -type d -exec sh -c "tes

Re: faster version of find (for -exec)?

2014-07-19 Thread Peng Yu
The point is not to call an external program. For example, if there is a `find` tool made in python, so that I can specify a python expression to the tool (to replace the function from the external program), then everything will be run within one process, which avoid the spawning of new processes.

faster version of find (for -exec)?

2014-07-18 Thread Peng Yu
Hi, I'm wondering if there is a faster version of `find` (may be in other languages, such as python or perl). `-exec` of `find` calls for an external command, which is slow. If `find` can be implemented in, say, python, then I can use a native python expression for `-exec`. This should dramatica

Re: Trim directory to search?

2013-08-02 Thread Peng Yu
> find . \( -type d -exec test -e {}/.ignore \; -prune \) -o > > will do something like what you want. But, again, it's not > efficient, since it performs one fork/exec per subdirectory. A more I think that given the current wide availability of multicore, if 'find' can take make a multi

Trim directory to search?

2013-06-02 Thread Peng Yu
Hi, I don't want to let find search directories with a file .ignore (i.e., anything in the directory (including the subdirectories) is ignored). Is there an efficient way to customize find in this way? (I can think of an simple way---recursively call "find" with maxdepth 1 and not go into director

mnemonic for %* of -printf

2013-05-15 Thread Peng Yu
Hi, I find that things like '%H' of -printf is very hard to remember. Is there an easy way to remember '%*'? -- Regards, Peng

How to let -path match only relative path?

2012-08-05 Thread Peng Yu
Hi, /tmp/main$ find . -path '*/tmp*' /tmp/main$ find /tmp/main -path '*/tmp*' /tmp/main The above commands show that -path match the whole path (/tmp/main) rather than the relative path ('.'). Is there a way to always use the relative path so that both of the above commands returns nothing? --

How to find all the files that satisfy one set of conditions in directories that satisfies another set of conditions in one 'find' command?

2012-06-25 Thread Peng Yu
Hi, I want find all the files that satisfy one set of conditions in directories that satisfies another set of conditions in one 'find' command. As an example, I want to search for executables in directories that has a file named ".export". As of now, I use the follow commands (to demonstrate idea

How to exclude directories (and their subdirs) that contain a certain file?

2012-04-14 Thread Peng Yu
Hi, I'm wondering if there is an easy way to ignore all directories (and their subdirectories) that contain a certain file. For example, I have directories blah/a/ blah/a/b. I have blah/a/.ignore, so blah/a and everything in it are ignored. -- Regards, Peng

Re: How to find by birth time?

2011-11-20 Thread Peng Yu
> Yes.  It's explained in the Texinfo documentation for find. I see the word 'birth' appears in the following two places. -newerXY reference Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (an

How to find by birth time?

2011-11-20 Thread Peng Yu
Hi, stat can give birth time. Is there an option search by birth time in find? (I find -ctime -atime -mtime but not -btime in find.) -- Regards, Peng

How to only return the 1 match then quit?

2011-11-19 Thread Peng Yu
Hi, I'm not able to find an argument so that find will only return the first match then quit. Could you please let me know if there is such an option? -- Regards, Peng

Re: Is updatedb a bash script or a binary executable?

2011-11-08 Thread Peng Yu
On Tue, Nov 8, 2011 at 12:07 PM, Andreas Metzler wrote: > On 2011-11-08 Peng Yu wrote: >> I see that updatedb is a bash script after I compiled the source. But >> updatedb in ubuntu is a binary. I'm wondering where the binary >> updatedb in ubuntu comes from? > &g

Is updatedb a bash script or a binary executable?

2011-11-08 Thread Peng Yu
Hi, I see that updatedb is a bash script after I compiled the source. But updatedb in ubuntu is a binary. I'm wondering where the binary updatedb in ubuntu comes from? -- Regards, Peng

Re: limiting the directory to locate and search by file type

2011-11-08 Thread Peng Yu
On Tue, Nov 8, 2011 at 3:40 AM, James Youngman wrote: > On Tue, Nov 8, 2011 at 12:11 AM, Peng Yu wrote: >> On Mon, Nov 7, 2011 at 5:47 PM, James Youngman wrote: >>> You can achieve this by using locate --regex. >> >> Suppose I want to restrict the search to /tm

Re: limiting the directory to locate and search by file type

2011-11-07 Thread Peng Yu
On Mon, Nov 7, 2011 at 5:47 PM, James Youngman wrote: > On Mon, Nov 7, 2011 at 10:02 PM, Peng Yu wrote: >> Hi, >> >> For 'find', I can specify which directory (directories) to perform the >> search. It seems that there is no such an option for 'lo

limiting the directory to locate and search by file type

2011-11-07 Thread Peng Yu
Hi, For 'find', I can specify which directory (directories) to perform the search. It seems that there is no such an option for 'locate' to restrict the search to certain directory rather than everything in the database (specified by -d). Also 'find' offer the option -type, which allows me to sea

How to only find the first hit then return?

2011-08-25 Thread Peng Yu
Hi, By default, find will look for all the matches. Is there a way to let find only get the first match and then return? -- Regards, Peng

Re: Speed up find

2011-08-05 Thread Peng Yu
On Fri, Aug 5, 2011 at 4:46 PM, James Youngman wrote: > On Fri, Aug 5, 2011 at 10:44 PM, Peng Yu wrote: >> Hi, >> >> I'm wondering if there is a way to speed up find by create some kind >> of indexing. When the directory structure is large, find becomes slow.

Speed up find

2011-08-05 Thread Peng Yu
Hi, I'm wondering if there is a way to speed up find by create some kind of indexing. When the directory structure is large, find becomes slow. -- Regards, Peng

How to specify mulitple source directories in updatedb?

2011-02-13 Thread Peng Yu
Hi, The manpage of updatedb only shows the case when one source directory is used. But I have multiple directories need to be indexed. Is there a way to do so in updatedb? updatedb -l 0 -o db_file -U source_directory -- Regards, Peng

find starting from leaf rather than root

2010-06-13 Thread Peng Yu
I know that 'find' start from a dir then recursively check subdirectories. But I have an application, in which I need to check the start directory first then check the parent directory (I want to control whether to go to sibling directories) then the grandparent directory (I want to control whethe

How to find all the directories that don't have any file in it?

2010-06-11 Thread Peng Yu
Hello, I want to find all the directories that do not have any file in them (there can be directories in them). Could you show me how to do it? -- Regards, Peng

How to find directories or symbolic links that point to directories?

2010-05-03 Thread Peng Yu
I know -type d is for directory. But how to find directory as well as symbolic links that point to directories? -- Regards, Peng

How to locate a directory?

2010-04-25 Thread Peng Yu
I'm wondering if there is a way to locate directory. For example, file a.txt b.txt c.txt are in the directory 'a_dir'. When I locate 'a_dir', all the three file shows up. I just want to show 'a_dir' rather the three files. Is there a way to do so? a_dir/a.txt a_dir/b.txt a_dir/c.txt -- Regards,

How to search for broken symbolic links?

2010-02-15 Thread Peng Yu
I don't find which option to use to search for broken symbolic links. Could somebody let me know if there is such an option?

Re: How to search for files that have fewer than n lines?

2010-01-01 Thread Peng Yu
On Thu, Dec 31, 2009 at 9:23 PM, James Youngman wrote: > On Thu, Dec 31, 2009 at 10:05 PM, Peng Yu wrote: >> I know I can used wc -l to get the number of lines in a file. Could >> somebody let me know how to search for files that have fewer than n >> lines? (n is a nu

How to search for files that have fewer than n lines?

2009-12-31 Thread Peng Yu
I know I can used wc -l to get the number of lines in a file. Could somebody let me know how to search for files that have fewer than n lines? (n is a number)

Re: How to conditionally search?

2009-11-28 Thread Peng Yu
On Sat, Nov 28, 2009 at 4:12 AM, James Youngman wrote: > On Sat, Nov 28, 2009 at 12:09 AM, Peng Yu wrote: >> On Fri, Nov 27, 2009 at 2:54 PM, Eric Blake wrote: >>> find -name '*.py' -print -o -name '*.sh' \ >>>  -exec sh -c 'test ! -

Re: How to conditionally search?

2009-11-27 Thread Peng Yu
On Fri, Nov 27, 2009 at 2:54 PM, Eric Blake wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > According to Peng Yu on 11/27/2009 8:38 AM: >>> find . -name '*.sh' -o -name '*.py' >>> >>> ... do what you had in mind? >>

Re: How to conditionally search?

2009-11-27 Thread Peng Yu
On Fri, Nov 27, 2009 at 6:19 AM, James Youngman wrote: > On Wed, Nov 25, 2009 at 3:56 AM, Peng Yu wrote: >> I want to search for all '.py' files in a directory (recursively). >> However, if there is a '.sh' file in the same directory where a '.py'

How to conditionally search?

2009-11-26 Thread Peng Yu
I want to search for all '.py' files in a directory (recursively). However, if there is a '.sh' file in the same directory where a '.py' is in, the '.sh' file rather than the '.py' file will be returned. Would somebody let me know how to do so?