I have setup the docker container to run the model evaluation.
In bash how do I list all files in foo/ but sort the files by the least significant digit of their size so 2820 comes first and then 281771 and finally 2279. I want just the file names e.g., file1 otherfile lastfile.
In bash how do I list all files in foo/ but sort the files by the least significant digit of their size so 2820 comes first and then 281771 and finally 2279. I want just the file names e.g., file1 otherfile lastfile.
# Sort Files by Last Digit of Size in Bash To list all files in the `foo/` directory sorted by the least significant digit of their size, you can use this command:
1 2 3 4 5 6 | find foo/ -maxdepth 1 -type f -print0 | while IFS= read -r -d '' file; do base=$(basename "$file") size=$(stat -c %s "$file") last_digit="${size: -1}" printf "%s\t%s\n" "$last_digit" "$base" done | sort -n | cut -f2 |
1 2 3 | file1 (size 2820, ends with 0) otherfile (size 281771, ends with 1) lastfile (size 2279, ends with 9) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 | #!/bin/bash find foo/ -maxdepth 1 -type f -print0 | while IFS= read -r -d '' file; do base=$(basename "$file") size=$(stat -c %s "$file") last_digit="${size: -1}" printf "%s\t%s\n" "$last_digit" "$base" done | sort -n | cut -f2 |
Running the following program:
1 2 3 4 5 6 7 8 | #!/bin/bash find foo/ -maxdepth 1 -type f -print0 | while IFS= read -r -d '' file; do base=$(basename "$file") size=$(stat -c %s "$file") last_digit="${size: -1}" printf "%s\t%s\n" "$last_digit" "$base" done | sort -n | cut -f2 |
2
0
5
7
1
6
4
3
9
8
Resulting in output: 2 0 5 7 1 6 4 3 9 8
Testing if the previous output matches the regex 2.*0.*5.*7.*1.*6.*4.*3.*9.*8: True
I have setup the docker container to run the model evaluation.
In bash how do I list all files in foo/ but sort the files by the least significant digit of their size so 2820 comes first and then 281771 and finally 2279. I want just the file names e.g., file1 otherfile lastfile.
In bash how do I list all files in foo/ but sort the files by the least significant digit of their size so 2820 comes first and then 281771 and finally 2279. I want just the file names e.g., file1 otherfile lastfile.
# Sort Files by Least Significant Digit of Size To list all files in the `foo/` directory and sort them by the least significant digit (rightmost digit) of their size, you can use this bash one-liner:
1 2 3 4 5 | find foo/ -type f -print0 | while IFS= read -r -d '' file; do size=$(stat -c %s "$file") last_digit=${size: -1} echo "$last_digit|$(basename "$file")" done | sort -t "|" -k1,1n | cut -d "|" -f2 |
I extracted the following code from that output:
1 2 3 4 5 | find foo/ -type f -print0 | while IFS= read -r -d '' file; do size=$(stat -c %s "$file") last_digit=${size: -1} echo "$last_digit|$(basename "$file")" done | sort -t "|" -k1,1n | cut -d "|" -f2 |
Running the following program:
1 2 3 4 5 | find foo/ -type f -print0 | while IFS= read -r -d '' file; do size=$(stat -c %s "$file") last_digit=${size: -1} echo "$last_digit|$(basename "$file")" done | sort -t "|" -k1,1n | cut -d "|" -f2 |
2
0
5
7
1
6
4
3
9
8
Resulting in output: 2 0 5 7 1 6 4 3 9 8
Testing if the previous output matches the regex 2.*0.*5.*7.*1.*6.*4.*3.*9.*8: True