find_usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
find_usage [2021/04/08 10:03] – raju | find_usage [2024/03/12 23:10] (current) – [find and sort] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== list files in chronological order ==== | ||
+ | |||
+ | < | ||
+ | <some find command> | xargs ls -ltr --time-style=" | ||
+ | </ | ||
+ | |||
+ | For example, the following command will list all yml files under the current directory in a chronological order | ||
+ | |||
+ | < | ||
+ | find . -iname ' | ||
+ | </ | ||
+ | |||
+ | Sample run | ||
+ | < | ||
+ | $ find . -iname ' | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 1212 20210128_1851 ./ | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 2486 20211109_0907 ./ | ||
+ | -rw-r--r-- 1 kkusuman 1049089 3130 20211231_1209 ./ | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | -rw-r--r-- 1 kkusuman 1049089 3153 20220609_1304 ./ | ||
+ | -rw-r--r-- 1 kkusuman 1049089 | ||
+ | </ | ||
+ | |||
+ | Ref:- https:// | ||
+ | |||
+ | tags | find and sort, chronological, | ||
+ | |||
+ | ==== find number of words in all files under a directory ==== | ||
+ | < | ||
+ | find . -type f -exec wc -w {} + | tail -n1 | ||
+ | </ | ||
+ | |||
+ | Ref:- https:// | ||
+ | |||
+ | ==== gunzip files on nfs and copy to hadoop ==== | ||
+ | < | ||
+ | files_to_copy=`find $dir -maxdepth 1 -iname ' | ||
+ | for i in $files_to_copy | ||
+ | do | ||
+ | unzipped_file=${tmp_nfs_dir}/ | ||
+ | gunzip $i -c > $unzipped_file | ||
+ | hadoop fs -put -f $unzipped_file $hdfs_dir | ||
+ | echo " | ||
+ | rm -f $unzipped_file | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | tags | process the output of find | ||
==== dummy ==== | ==== dummy ==== | ||
* [[grep on find results]] | * [[grep on find results]] | ||
Line 5: | 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.txt · Last modified: 2024/03/12 23:10 by raju