Hot answers tagged

11

GNU find has an optimization which can be applied to find . but not to find . -type f: if it knows that none of the remaining entries in a directory are directories, then it doesn't bother to determine the file type (with the stat system call) unless one of the search criteria requires it. Calling stat can take measurable time since the information is ...


7

You can do it with just find and awk: find . -type f -name '*.php' -size +1000c -exec awk ' FNR > 1 {nextfile} length >= 1000 {print FILENAME}' {} + The awk script skips to next file after the first line of every file. It prints the filename of the current file if the current line is >= 1000 characters long.


4

I am not sure what your intention is (you didn't make that clear), but if it's to chmod to 700 all the files that match the pattern, then, except for your typo (;\ instead of \;), your command seems to work as intended. However: when it finds a file containing that string grep -q gives me 0 so another exec executes but should not. Yes, it should do. 0 ...


2

If you want something more general than matching a specific character, you would have to use regular expressions. Since the question is not tagged "linux", the proper answer would use POSIX: find . | grep '[*~]' If you want to make it Linux-specific, you can use the GNU find option -regex (also supported by FreeBSD). If the pathname has an embedded ...


2

Use the -prune option to skip that directory find ~/.jenkins/jobs/subco -path ~/.jenkins/jobs/subco/myapp -prune -o -name '*.jar' -exec rm -r {} +


2

You can try this one using find and grep : find . -type f -name '*.php' -exec grep '.\{1000\}' {} +


1

This might be not efficient but I hope it could help you find -mindepth 3 -maxdepth 3 -type f -mtime -30 | xargs -n 1 dirname | xargs -n 1 dirname | uniq # (or sort -u, I assume find's output is already sorted)


1

I would use find on each directory in turn, and pipe it to grep -q . to check if there are any results, and print the directory name conditionally upon whether or not there were any results: for d in */; do find "$d" -type f -mtime -30 | grep -q . && printf %s\\n "$d"; done


1

Try: ( cd ~/.jenkins/jobs/subco find . -path ./myapp -prune -o -type f -name '*.jar' -print0 | ... ) Adding -type f to restrict the condition, since when you want to match JAR files only. And also, you used -print0, it's likely that your find supports -delete, so you can use: ( cd ~/.jenkins/jobs/subco find . -path ./myapp -prune -o -type f -name ...


1

1 For your first step, in your command example, you do not need the * because that is not filtering any file. What you do need is to filter .git, as this: $ find . ! -name ".git" -type f That will reject (!) any file named .git. That removes the need of grep -v ".git". The sed could not be avoided, as it is editing the internals of a file, not something ...


1

Implementations of find vary, but they should all handle character classes in wildcards (POSIX.2, section 3.13): find . -name '*[~*]*' If newline is among your "special" characters, you may need to work out how to get your shell to pass it to find. In Bash, you can use find . -name $'*[\t \n]*' to show files containing whitespace, for example. A ...


1

You have misunderstood how hard links work. There is no original. All files are simply hardlinks to an inode. Therefore, hardlinks don't actually link to files, they link to inodes. To illustrate, consider this file: $ touch file $ ls -li file 3282140 -rw-r--r-- 1 terdon terdon 0 May 3 16:27 file As you can see above, file points to the inode 3282140. ...


1

-name takes wildcard patterns, not regexps and matches on the file name, not its full path. Use -regex (or -iregex) for regexp matching but beware it matches against the full path. Here, you could do: LC_ALL=C find -E . -iregex '.*s[0-9]{1,2}\.?e[0-9]{1,2}[^/]*\.mkv' Here, we're replacing the second .* with [^/]*, that is a sequence of non-/ characters to ...


1

Why don't you try this one : find . -user trolkura ! -perm -u+rw This means: look for files starting in present directory, owned by trolkura, where the permissions for group and other can be anything (- in front of permission string) and the users permissions are only: rw



Only top voted, non community-wiki answers of a minimum length are eligible