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.
To list all files in the `foo/` directory and sort them based on the least significant digit of their size, you can use the following bash command:
1 | ls foo/ | xargs -I{} sh -c 'echo $(du -b "{}" | cut -f1) {}' | sort -n -k1.1 | cut -d' ' -f2 |
1 2 3 | lastfile file1 otherfile |
I extracted the following code from that output:
1 | ls foo/ | xargs -I{} sh -c 'echo $(du -b "{}" | cut -f1) {}' | sort -n -k1.1 | cut -d' ' -f2 |
Running the following program:
1 | ls foo/ | xargs -I{} sh -c 'echo $(du -b "{}" | cut -f1) {}' | sort -n -k1.1 | cut -d' ' -f2 |
0
1
2
3
4
5
6
7
8
9
du: cannot access '0': No such file or directory
du: cannot access '1': No such file or directory
du: cannot access '2': No such file or directory
du: cannot access '3': No such file or directory
du: cannot access '4': No such file or directory
du: cannot access '5': No such file or directory
du: cannot access '6': No such file or directory
du: cannot access '7': No such file or directory
du: cannot access '8': No such file or directory
du: cannot access '9': No such file or directory
Resulting in output: 0 1 2 3 4 5 6 7 8 9 du: cannot access '0': No such file or directory du: cannot access '1': No such file or directory du: cannot access '2': No such file or directory du: cannot access '3': No such file or directory du: cannot access '4': No such file or directory du: cannot access '5': No such file or directory du: cannot access '6': No such file or directory du: cannot access '7': No such file or directory du: cannot access '8': No such file or directory du: cannot access '9': No such file or directory
Testing if the previous output equals the string 2 0 5 7 1 6 4 3 9 8
: False
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.
To list all files in the `foo/` directory and sort them by the least significant digit of their size, you can use a combination of the `find` command, `stat` command, and the `sort` command with a custom sorting key. Here's the command to achieve this:
1 | find foo/ -type f -printf "%f\t%s\n" | sort -t $'\t' -k2.9 | cut -f1 |
1 2 3 | file1 otherfile lastfile |
I extracted the following code from that output:
1 2 3 | #!/bin/bash find foo/ -type f -printf "%f\t%s\n" | sort -t $'\t' -k2.9 | cut -f1 |
Running the following program:
1 2 3 | #!/bin/bash find foo/ -type f -printf "%f\t%s\n" | sort -t $'\t' -k2.9 | cut -f1 |
0
1
2
3
4
5
6
7
8
9
Resulting in output: 0 1 2 3 4 5 6 7 8 9
Testing if the previous output equals the string 2 0 5 7 1 6 4 3 9 8
: False
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.
To list all files in the `foo/` directory and sort them by the least significant digit of their size, you can use a combination of the `find` command, `stat` command, and `sort` command in Bash. Here's how you can achieve this:
1 | find foo/ -type f -printf "%f\t%s\n" | sort -t$'\t' -k2.${#},2 | cut -f1 |
1 2 3 | lastfile file1 otherfile |
I extracted the following code from that output:
1 2 3 | #!/bin/bash find foo/ -type f -printf "%f\t%s\n" | sort -t$'\t' -k2.${#},2 | cut -f1 |
Running the following program:
1 2 3 | #!/bin/bash find foo/ -type f -printf "%f\t%s\n" | sort -t$'\t' -k2.${#},2 | cut -f1 |
sort: character offset is zero: invalid field specification '2.0,2'
Resulting in output: sort: character offset is zero: invalid field specification '2.0,2'
Testing if the previous output equals the string 2 0 5 7 1 6 4 3 9 8
: False
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.
To list all files in the `foo/` directory and sort them by the least significant digit of their size, you can use the following command:
1 2 3 4 | ls foo/ | while read file; do size=$(stat -c%s "foo/$file") printf "%d\t%s\n" $((size % 10)) "$file" done | sort -n | cut -f2- |
1 2 3 | file1 (size: 2820 bytes) otherfile (size: 281771 bytes) lastfile (size: 2279 bytes) |
1 2 3 | file1 lastfile otherfile |
I extracted the following code from that output:
1 2 3 4 5 6 | #!/bin/bash ls foo/ | while read file; do size=$(stat -c%s "foo/$file") printf "%d\t%s\n" $((size % 10)) "$file" done | sort -n | cut -f2- |
Running the following program:
1 2 3 4 5 6 | #!/bin/bash ls foo/ | while read file; do size=$(stat -c%s "foo/$file") printf "%d\t%s\n" $((size % 10)) "$file" 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 equals the string 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.
To list all files in the `foo/` directory and sort them by the least significant digit of their size, you can use the following command in Bash:
1 2 3 4 | ls foo/ | while read -r file; do size=$(stat -c %s "foo/$file") printf "%d %s\n" $((size % 10)) "$file" done | sort -n | cut -d' ' -f2 |
1 2 3 | file1 lastfile otherfile |
I extracted the following code from that output:
1 2 3 4 5 6 | #!/bin/bash ls foo/ | while read -r file; do size=$(stat -c %s "foo/$file") printf "%d %s\n" $((size % 10)) "$file" done | sort -n | cut -d' ' -f2 |
Running the following program:
1 2 3 4 5 6 | #!/bin/bash ls foo/ | while read -r file; do size=$(stat -c %s "foo/$file") printf "%d %s\n" $((size % 10)) "$file" done | sort -n | 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 equals the string 2 0 5 7 1 6 4 3 9 8
: True