linuxpipelinelsxargscd

Entering into the last modified sub-directory in a directory in linux


I have a dir in which I keep adding new dirs from a script. I want to enter that new sub-dir directly rather that always manually doing eza --sort=modified then copy pasting that name then cd into that folder. I am using eza and zoxide in fish shell

I tried doing this:

eza --sort=modified | tail -n 1 | xargs z

But it just gave an error xargs: z: No such file or directory. I did a bit of digging and now understand that pipe runs xargs in a subprocess, and xargs runs zoxide in a subprocess and changes in a subprocess do not get propagated to the parent process. I then tried:

z "(eza --sort=modified | tail -n 1 )"

I still got zoxide: no match found


Solution

  • As mentioned by @David C. Rankin in the comments:

    z ( eza --sort=modified | tail -n 1) worked