mirror of
https://github.com/xmengnet/the-art-of-command-line.git
synced 2024-12-24 03:56:28 +08:00
Improve find
commands
It's more straightforward to use quotes around the pattern arguments rather than escaping the asterisks with backslashes. Also, find (the GNU version, at least) requires the path to come before the expression.
This commit is contained in:
parent
7237274c0e
commit
31b01f1ba4
1 changed files with 3 additions and 3 deletions
|
@ -59,7 +59,7 @@ Scope:
|
|||
|
||||
- Use `xargs` (or `parallel`). It's very powerful. Note you can control how many items execute per line (`-L`) as well as parallelism (`-P`). If you're not sure if it'll do the right thing, use `xargs echo` first. Also, `-I{}` is handy. Examples:
|
||||
```
|
||||
find . -name \*.py | xargs grep some_function
|
||||
find . -name '*.py' | xargs grep some_function
|
||||
cat hosts | xargs -I{} ssh root@{} hostname
|
||||
```
|
||||
|
||||
|
@ -123,7 +123,7 @@ Scope:
|
|||
|
||||
## Processing files and data
|
||||
|
||||
- To locate a file by name in the current directory, `find -iname *something* .` (or similar). To find a file anywhere by name, use `locate something` (but bear in mind `updatedb` my not have indexed recently created files).
|
||||
- To locate a file by name in the current directory, `find . -iname '*something*'` (or similar). To find a file anywhere by name, use `locate something` (but bear in mind `updatedb` my not have indexed recently created files).
|
||||
|
||||
- For general searching through source or data files (more advanced than `grep -r`), use [`ag`](https://github.com/ggreer/the_silver_searcher).
|
||||
|
||||
|
@ -240,7 +240,7 @@ A few examples of piecing together commands:
|
|||
|
||||
- Use `xargs` or `parallel` whenever you can. Note you can control how many items execute per line (`-L`) as well as parallelism (`-P`). If you're not sure if it'll do the right thing, use xargs echo first. Also, `-I{}` is handy. Examples:
|
||||
```
|
||||
find . -name \*.py | xargs grep some_function
|
||||
find . -name '*.py' | xargs grep some_function
|
||||
cat hosts | xargs -I{} ssh root@{} hostname
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue