@@ -5,6 +5,8 @@ Handy list of oft-used Linux commands that I will never remember. Not intended t
5
5
- [ Shell 101] ( #shell-101 )
6
6
- [ List directory contents with size] ( #list-directory-contents-with-size )
7
7
- [ Count number of items in directory] ( #count-number-of-items-in-directory )
8
+ - [ Find all files larger than a given size] ( #find-all-files-larger-than-a-given-size )
9
+ - [ Run command on every file] ( #run-command-on-every-file )
8
10
- [ Monitor GPU usage] ( #monitor-gpu-usage )
9
11
- [ File Permissions] ( #file-permissions )
10
12
- [ Symbolic Links] ( #symbolic-links )
@@ -24,6 +26,8 @@ Handy list of oft-used Linux commands that I will never remember. Not intended t
24
26
- [ Data Wrangling] ( #data-wrangling )
25
27
- [ grep] ( #grep )
26
28
- [ awk and sed] ( #awk-and-sed )
29
+ - [awk to print all columns from nth to last](#awk-to-print-all-columns-from-nth-to-last)
30
+ - [sed for removing and adding characters](#sed-for-removing-and-adding-characters)
27
31
- [ Machine Learning Toolchain] ( #machine-learning-toolchain )
28
32
- [ Install Tensorflow GPU] ( #install-tensorflow-gpu )
29
33
## Shell 101
@@ -40,6 +44,21 @@ du -sch * .[!.]* | sort -rh
40
44
ls < directory path> -1 | wc -l
41
45
```
42
46
47
+ ### Find all files larger than a given size
48
+
49
+ ``` bash
50
+ # find all files "-type f" in the current directory "."
51
+ # of size greater than 20MB and list the files using "ls -lh"
52
+ # print the file size "5ドル" and the whole file name "0,2ドル"
53
+ find . -type f -size +20000k -exec ls -lh {} \; | awk ' {print 5ドル ":"; 1ドル=2ドル=3ドル=4ドル=5ドル=6ドル=7ドル=8ドル=""; print substr(0,2ドル)}' | sed -r ' s .{9} '
54
+ ```
55
+
56
+ ### Run command on every file
57
+
58
+ ``` bash
59
+ for i in ./* txt; do echo " File $i " ; done
60
+ ```
61
+
43
62
### Monitor GPU usage
44
63
45
64
``` bash
@@ -133,6 +152,11 @@ rsync -avzPn ~/local/directory username@remote_host:/home/username/destination_d
133
152
# using ssh key
134
153
rsync -avzPn -e " ssh -i ~/ec2_keyfile.pem" user@remote:/home/folder /tmp/local_system/
135
154
155
+ # read file names from a list stored in another file - https://serverfault.com/a/212441
156
+ # works better when source directory is set to root "/" and file names are stored with absolute path
157
+ # source directory gets appended to the file paths inside the listfile
158
+ rsync -avzP /source/directory --files-from=/full/path/to/listfile /destination/directory
159
+
136
160
# with xargs for parallel execution - https://stackoverflow.com/a/25532027
137
161
# This will list all folders in ~/data, pipe them to xargs,
138
162
# which will read them one-by-one and and run 4 rsync processes at a time.
@@ -322,7 +346,37 @@ More `grep` funda [here](https://www.grymoire.com/Unix/Grep.html)
322
346
323
347
### awk and sed
324
348
325
- TODO: Refer [ here] ( https://missing.csail.mit.edu/2020/data-wrangling/ ) now
349
+ #### awk to print all columns from nth to last
350
+
351
+ ``` bash
352
+ # print 5th column, set columns 1 to 8 as empty, then print all columns
353
+ # https://stackoverflow.com/a/2961994
354
+ < command output with list of formatted strings> | awk ' {print 5ドル ":"; 1ドル=2ドル=3ドル=4ドル=5ドル=6ドル=7ドル=8ドル=""; print substr(0,2ドル)}'
355
+ ```
356
+
357
+ #### sed for removing and adding characters
358
+
359
+ ``` bash
360
+ # add in the beginning of every line in file - https://stackoverflow.com/q/2099471
361
+ sed -i -e ' s/^/\/home\/users\/anurag\//' file
362
+
363
+ # remove last character of every line in file
364
+ sed -i ' s/.$//' file
365
+
366
+ # add :8080 at the end of every line in portsfile
367
+ sed -i ' s/$/:8080/' portsfile
368
+
369
+ # REPLACE last character of each line in file with p3
370
+ sed -i ' s/.$/p3/' file
371
+
372
+ # remove last character of every line in file
373
+ sed -i ' s/.$//' file
374
+
375
+ # remove first two characters of every line in file
376
+ sed -r ' s .{2} ' file
377
+ ```
378
+
379
+ For more tips, refer [ here] ( https://missing.csail.mit.edu/2020/data-wrangling/ ) .
326
380
327
381
## Machine Learning Toolchain
328
382
0 commit comments