find_usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
find_usage [2024/01/03 21:58] – [find number of words in all files under a directory] raju | find_usage [2024/03/12 23:10] (current) – [find and sort] raju | ||
---|---|---|---|
Line 59: | Line 59: | ||
See: https:// | See: https:// | ||
+ | ==== copy all txt files in a directory to another ==== | ||
+ | |||
+ | < | ||
+ | find $SRC_DIR -maxdepth 1 -iname ' | ||
+ | </ | ||
+ | |||
+ | Note: The $DEST_DIR must exist. Otherwise it will throw an error. | ||
+ | |||
+ | The difference between this and '' | ||
+ | |||
+ | Sample run | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | $ mkdir -p x1/x2 x3 | ||
+ | $ touch x1/ | ||
+ | |||
+ | $tree | ||
+ | . | ||
+ | ├── x1 | ||
+ | │ ├── file1.pdf | ||
+ | │ ├── file1.txt | ||
+ | │ ├── file2.txt | ||
+ | │ └── x2 | ||
+ | │ | ||
+ | └── x3 | ||
+ | |||
+ | 3 directories, | ||
+ | |||
+ | $find x1 -maxdepth 1 -iname ' | ||
+ | `x1/ | ||
+ | `x1/ | ||
+ | |||
+ | $tree | ||
+ | . | ||
+ | ├── x1 | ||
+ | │ ├── file1.pdf | ||
+ | │ ├── file1.txt | ||
+ | │ ├── file2.txt | ||
+ | │ └── x2 | ||
+ | │ | ||
+ | └── x3 | ||
+ | ├── file1.txt | ||
+ | └── file2.txt | ||
+ | |||
+ | 3 directories, | ||
+ | </ | ||
+ | |||
+ | Without the -maxdepth option, all files underneath $SRC_DIR will be copied. The directory hierarchy is not preserved. For example, while files in x1 are copied to x3 so are the files in x1/x2 etc., | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | $ rm -rf x3 | ||
+ | $ mkdir x3 | ||
+ | $ find x1 -iname ' | ||
+ | `x1/ | ||
+ | `x1/ | ||
+ | `x1/ | ||
+ | |||
+ | $ tree | ||
+ | . | ||
+ | ├── x1 | ||
+ | │ ├── file1.pdf | ||
+ | │ ├── file1.txt | ||
+ | │ ├── file2.txt | ||
+ | │ └── x2 | ||
+ | │ | ||
+ | └── x3 | ||
+ | ├── file1.txt | ||
+ | ├── file2.txt | ||
+ | └── file3.txt | ||
+ | |||
+ | 3 directories, | ||
+ | </ |
find_usage.1704319081.txt.gz · Last modified: 2024/01/03 21:58 by raju