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 files in the `foo/` directory, sorted by the least significant digit of their size, and display only the filenames, you can use a combination of `ls`, `awk`, and `sort`. Here's a bash command that accomplishes this:
1 | ls -l foo/ | awk '{print $5 % 10 " " $NF}' | sort -n | cut -d' ' -f2 |
1 2 3 | file1 otherfile lastfile |
I extracted the following code from that output:
1 2 3 | #!/bin/bash ls -l foo/ | awk '{print $5 % 10 " " $NF}' | sort -n | cut -d' ' -f2 |
Running the following program:
1 2 3 | #!/bin/bash ls -l foo/ | awk '{print $5 % 10 " " $NF}' | sort -n | cut -d' ' -f2 |
2
40
0
5
7
1
6
4
3
9
8
Resulting in output: 2 40 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.
To list files in a directory sorted by the least significant digit of their size in bash, you can use a combination of `ls`, `awk`, and `sort`. Here's a command that accomplishes this:
1 | ls -l foo/ | awk '{print $5 % 10, $NF}' | sort -n | cut -d' ' -f2 |
1 2 3 | file1 otherfile lastfile |
I extracted the following code from that output:
1 2 3 | #!/bin/bash ls -l foo/ | awk '{print $5 % 10, $NF}' | sort -n | cut -d' ' -f2 |
Running the following program:
1 2 3 | #!/bin/bash ls -l foo/ | awk '{print $5 % 10, $NF}' | sort -n | cut -d' ' -f2 |
2
40
0
5
7
1
6
4
3
9
8
Resulting in output: 2 40 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.
To list files in the `foo/` directory, sorted by the least significant digit of their size, and display only the file names, you can use a combination of `ls`, `stat`, and `sort` commands in bash. Here's how you can do it:
1 2 3 4 5 6 | ls -1 foo/ | sort -n -k1.1,1.1 <( for file in foo/*; do size=$(stat -f %z "$file") echo "${size: -1} $(basename "$file")" done ) | cut -d' ' -f2- |
1 2 3 | file1 otherfile lastfile |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 | #!/bin/bash ls -1 foo/ | sort -n -k1.1,1.1 <( for file in foo/*; do size=$(stat -f %z "$file") echo "${size: -1} $(basename "$file")" done ) | cut -d' ' -f2- |
Running the following program:
1 2 3 4 5 6 7 8 | #!/bin/bash ls -1 foo/ | sort -n -k1.1,1.1 <( for file in foo/*; do size=$(stat -f %z "$file") echo "${size: -1} $(basename "$file")" done ) | cut -d' ' -f2- |
0
1
2
3
4
5
6
7
8
9
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
stat: cannot read file system information for '%z': No such file or directory
Resulting in output: 0 1 2 3 4 5 6 7 8 9 stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory stat: cannot read file system information for '%z': No such file or directory
Testing if the previous output matches the regex 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 files in the `foo/` directory, sorted by the least significant digit of their size, and display only the file names, you can use a combination of `find`, `stat`, `sort`, and `awk` commands in bash. Here's a one-liner that accomplishes this:
1 | find foo/ -type f -printf "%s %f\n" | sort -k1.${#1} | awk '{print $2}' |
1 | find foo/ -type f -printf "%s %f\n" | sort -k1.${#1},$((${#1}+1)) | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 | #!/bin/bash find foo/ -type f -printf "%s %f\n" | sort -k1.${#1} | awk '{print $2}' |
Running the following program:
1 2 3 | #!/bin/bash find foo/ -type f -printf "%s %f\n" | sort -k1.${#1} | awk '{print $2}' |
sort: character offset is zero: invalid field specification '1.0'
Resulting in output: sort: character offset is zero: invalid field specification '1.0'
Testing if the previous output matches the regex 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 files in the `foo/` directory, sorted by the least significant digit of their size, and display only the file names, you can use a combination of `ls`, `stat`, `sort`, and `awk` commands in bash. Here's a one-liner that accomplishes this:
1 | ls -1 foo/ | xargs -I {} bash -c 'stat -f "%z %N" "foo/{}"' | sort -n -k1.${#1} | awk '{print $2}' |
1 2 3 | file1 otherfile lastfile |
I extracted the following code from that output:
1 2 3 | #!/bin/bash ls -1 foo/ | xargs -I {} bash -c 'stat -f "%z %N" "foo/{}"' | sort -n -k1.${#1} | awk '{print $2}' |
Running the following program:
1 2 3 | #!/bin/bash ls -1 foo/ | xargs -I {} bash -c 'stat -f "%z %N" "foo/{}"' | sort -n -k1.${#1} | awk '{print $2}' |
sort: character offset is zero: invalid field specification '1.0'
stat: cannot read file system information for '%z %N': No such file or directory
xargs: bash: terminated by signal 13
Resulting in output: sort: character offset is zero: invalid field specification '1.0' stat: cannot read file system information for '%z %N': No such file or directory xargs: bash: terminated by signal 13
Testing if the previous output matches the regex 2.*0.*5.*7.*1.*6.*4.*3.*9.*8
: False