By default when I use the command ls on my folder, I have the result sorted by name. What if I want to change that behavior system wide for created_at ?
Edit the file ~/.bashrc
in your favorite text editor and add the following line at the bottom:
alias ls='ls -tU'
Save and close the file.
The next time you open a terminal, ls
will give the list in sorted order of time.
But if you need to make it take effect immediately, you can:
source ~/.bashrc
I will brutally chop your question in two:
How to sort by creation time:
There may not be an answer to that. This post https://unix.stackexchange.com/questions/20460/how-do-i-do-a-ls-and-then-sort-the-results-by-date-created seems to suggest that the creation date is NOT stored in many Unix systems, but I'm not sure about linux. Also, ls in MacOS IS able to sort by creation date. If you have a mac, do ls -tU
How to change a command's default behavior:
Suppose that you have found a way to make ls sort by creation date (for example, on MacOS, I do so by typing in ls -tU
), then you could use the alias command. Simply do alias ls='ls -tU'
and in the future all ls commands would be replaced by ls -tu
. This solution persists until your close your terminal window, but you can always add it to a startup script (for example, .bashrc
) to apply it every time you pull up your command shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With