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, 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 a one-liner that accomplishes this:
1 | ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
1 | ls -1A foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
I extracted the following code from that output:
1 2 3 | #!/bin/bash ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
Running the following program:
1 2 3 | #!/bin/bash ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
sort: character offset is zero: invalid field specification '1.0'
stat: cannot statx '0': 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 statx '0': 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
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 a one-liner that accomplishes this:
1 | ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1 -n -t '' | cut -d' ' -f2- |
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 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1 -n -t '' | cut -d' ' -f2- |
Running the following program:
1 2 3 | #!/bin/bash ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s {})" "{}"' | sort -k1 -n -t '' | cut -d' ' -f2- |
sort: empty tab
stat: cannot statx '0': No such file or directory
xargs: bash: terminated by signal 13
Resulting in output: sort: empty tab stat: cannot statx '0': 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
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 accomplish this in bash, you can use a combination of `ls`, `awk`, and `sort`. Here's a command that will do what you're asking:
1 | ls -l foo/ | awk '{print $5 " " $9}' | sort -k1.${#1} -n | awk '{print $2}' |
1 | ls -la foo/ | awk 'NR>1 {print $5 " " $9}' | sort -k1.${#1} -n | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 | #!/bin/bash ls -l foo/ | awk '{print $5 " " $9}' | sort -k1.${#1} -n | awk '{print $2}' |
Running the following program:
1 2 3 | #!/bin/bash ls -l foo/ | awk '{print $5 " " $9}' | sort -k1.${#1} -n | 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`, and `sort` commands in bash. Here's a one-liner that accomplishes this:
1 | ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s foo/{})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
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 'printf "%s %s\n" "$(stat -c %s foo/{})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
Running the following program:
1 2 3 | #!/bin/bash ls -1 foo/ | xargs -I {} bash -c 'printf "%s %s\n" "$(stat -c %s foo/{})" "{}"' | sort -k1.${#1} | cut -d' ' -f2- |
sort: character offset is zero: invalid field specification '1.0'
xargs: bash: terminated by signal 13
Resulting in output: sort: character offset is zero: invalid field specification '1.0' 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
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 the `ls` command combined with `sort` and some text processing. Here's a command that should do what you're asking:
1 | ls -l foo/ | tail -n +2 | awk '{print $5 " " $9}' | sed 's/^[0-9]*\([0-9]\) /\1 /' | sort -n | cut -d' ' -f2 |
1 | ls -la foo/ | tail -n +4 | awk '{print $5 " " $9}' | sed 's/^[0-9]*\([0-9]\) /\1 /' | sort -n | cut -d' ' -f2 |
I extracted the following code from that output:
1 2 3 | #!/bin/bash ls -l foo/ | tail -n +2 | awk '{print $5 " " $9}' | sed 's/^[0-9]*\([0-9]\) /\1 /' | sort -n | cut -d' ' -f2 |
Running the following program:
1 2 3 | #!/bin/bash ls -l foo/ | tail -n +2 | awk '{print $5 " " $9}' | sed 's/^[0-9]*\([0-9]\) /\1 /' | 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 matches the regex 2.*0.*5.*7.*1.*6.*4.*3.*9.*8
: True