I want to list and sort by time, all the files matching a certain pattern and then get only the first 20:
ls -laths *.txt | head -20
This works well, for example if I create two files:
touch 1.txt
touch 2.txt
The result of the above command is:
$ ls -laths *.txt | head -20
1,5K -rw-rw---- 1 user user 0 20. Apr 09:49 2.txt
1,5K -rw-rw---- 1 user user 0 20. Apr 09:49 1.txt
This works well if I do it on the terminal. But when trying to save it as an alias (where the input $1 is the pattern I want), like this:
alias lis20='function _(){ ls -laths "${1}" | head -20; }; _'
Then when I use the alias, I get:
$ lis20 *.txt
1,5K -rw-rw---- 1 user user 0 20. Apr 09:49 1.txt
It means it only lists the first file. I have tried several expansions of the variable inside, as in this question, but without any success.
I am using zsh, but it would be nice to have a solution that works for both bash and zsh.