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.
Here's a bash command to do that:
1 | ls -S foo/ | sort -k1,1n -k2,2r |
1 | ls -S foo/ | sort -k1,1n -k2,2r | awk '{print $NF}' |
1 | find foo/ -type f -printf '%s %f\n' | sort -k1,1n -k2,2r | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 4 5 6 7 | #!/bin/bash # List files sorted by size with additional sorting ls -S foo/ | sort -k1,1n -k2,2r | awk '{print $NF}' # Alternative approach using find # find foo/ -type f -printf '%s %f\n' | sort -k1,1n -k2,2r | awk '{print $2}' |
Running the following program:
1 2 3 4 5 6 7 | #!/bin/bash # List files sorted by size with additional sorting ls -S foo/ | sort -k1,1n -k2,2r | awk '{print $NF}' # Alternative approach using find # find foo/ -type f -printf '%s %f\n' | sort -k1,1n -k2,2r | awk '{print $2}' |
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 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.
Here's a bash command to achieve that:
1 | ls -S foo/ | sort -k1,1n -t$'\n' |
1 | ls -S foo/ | sort -k1,1n -t$'\n' | awk '{print $NF}' |
1 | find foo/ -type f -printf "%s %f\n" | sort -k1,1n | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 4 | #!/bin/bash # Script to list files in a directory sorted by size numerically ls -S foo/ | sort -k1,1n -t$'\n' |
Running the following program:
1 2 3 4 | #!/bin/bash # Script to list files in a directory sorted by size numerically ls -S foo/ | sort -k1,1n -t$'\n' |
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 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.
Here's a bash command to list files sorted by the least significant digit of their file size:
1 | ls -S foo/ | sort -k1,1n -k1.1,1n |
1 | ls -S foo/ | sort -n -k1.1,1 |
1 | ls foo/ | sort -n -k1.1,1 |
1 | find foo/ -type f -printf "%s %f\n" | sort -n -k1.1,1 | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/bin/bash # Directory to list files from DIR="foo/" echo "Method 1: ls with sort" ls -S "$DIR" | sort -k1,1n -k1.1,1n echo -e "\nMethod 2: Explicit ls with sort" ls -S "$DIR" | sort -n -k1.1,1 echo -e "\nMethod 3: Filenames only" ls "$DIR" | sort -n -k1.1,1 echo -e "\nMethod 4: Find with sort and awk" find "$DIR" -type f -printf "%s %f\n" | sort -n -k1.1,1 | awk '{print $2}' |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/bin/bash # Directory to list files from DIR="foo/" echo "Method 1: ls with sort" ls -S "$DIR" | sort -k1,1n -k1.1,1n echo -e "\nMethod 2: Explicit ls with sort" ls -S "$DIR" | sort -n -k1.1,1 echo -e "\nMethod 3: Filenames only" ls "$DIR" | sort -n -k1.1,1 echo -e "\nMethod 4: Find with sort and awk" find "$DIR" -type f -printf "%s %f\n" | sort -n -k1.1,1 | awk '{print $2}' |
Method 1: ls with sort
0
1
2
3
4
5
6
7
8
9
Method 2: Explicit ls with sort
0
1
2
3
4
5
6
7
8
9
Method 3: Filenames only
0
1
2
3
4
5
6
7
8
9
Method 4: Find with sort and awk
8
2
9
6
4
7
3
5
1
0
Resulting in output: Method 1: ls with sort 0 1 2 3 4 5 6 7 8 9 Method 2: Explicit ls with sort 0 1 2 3 4 5 6 7 8 9 Method 3: Filenames only 0 1 2 3 4 5 6 7 8 9 Method 4: Find with sort and awk 8 2 9 6 4 7 3 5 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.
Here's a Bash command to achieve that:
1 | ls -S foo/ | sort -k1,1n -k1.0,1.0 |
1 | ls -S foo/ | sort -k1,1n -k1.0,1.0 | awk '{print $NF}' |
1 | find foo/ -type f -printf "%s %f\n" | sort -k1,1n -k1.0,1.0 | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 4 5 6 | #!/bin/bash # Sort files in 'foo/' directory by size with least significant digit sorting # Usage: ./script.sh ls -S foo/ | sort -k1,1n -k1.0,1.0 | awk '{print $NF}' |
Running the following program:
1 2 3 4 5 6 | #!/bin/bash # Sort files in 'foo/' directory by size with least significant digit sorting # Usage: ./script.sh ls -S foo/ | sort -k1,1n -k1.0,1.0 | awk '{print $NF}' |
sort: character offset is zero: invalid field specification '1.0,1.0'
Resulting in output: sort: character offset is zero: invalid field specification '1.0,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.
Here's a bash command to achieve this:
1 | ls -S foo/ | sort -k1,1n -k1.7,1 |
1 | ls -S foo/ | sort -k1,1n -k1.7,1 | awk '{print $NF}' |
1 | find foo/ -type f -printf "%s %f\n" | sort -k1,1n -k1.7,1 | awk '{print $2}' |
I extracted the following code from that output:
1 2 3 4 | #!/bin/bash # Sort files in directory by size, with special sorting on least significant digit ls -S foo/ | sort -k1,1n -k1.7,1 |
Running the following program:
1 2 3 4 | #!/bin/bash # Sort files in directory by size, with special sorting on least significant digit ls -S foo/ | sort -k1,1n -k1.7,1 |
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 matches the regex 2.*0.*5.*7.*1.*6.*4.*3.*9.*8: False