Sort file array list in bash by date and bypass argument limit
0
votes
2
answers
457
views
So, I have a file array list in a bash shell, and I want to sort all the files in the array by the date modified, starting with the oldest being the first one in the array. However, I don't want to sort and modify the original array, and instead want to have the sorted result be in a different array. I saw this thread in which I tried the following command, although I modified it since the array was a variable and not a file.
new_array=( $(ls -t $(printf '%s\n' "${array_list[@]}")) )
However, the array is so big that ls reports the argument list is "too long"
Is there another way I can sort the main array by the modified date, starting with the oldest file at the beginning, and save the results to a different array?
Asked by Eduardo Perez
(161 rep)
Feb 20, 2023, 06:13 PM
Last activity: Mar 13, 2023, 06:37 AM
Last activity: Mar 13, 2023, 06:37 AM