Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: spaces in filenames should be a crime.
- X-seq: zsh-users 22616
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: spaces in filenames should be a crime.
- Date: Sun, 26 Mar 2017 21:18:05 +0000
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=Inti+Ji4hJBIaMry21vmPEsldoYgFyScgWmgmCm8U6o=; b=N1b0Y7/5 y7hj/XfE1YSeDtLoJUh9FY3LCDGcvv+uMEtkQ5S6zMc6woOrB9xmLwDIYWG6I7lt QJJPFDtbROchmDw1kEPg0yUE2IcwzOIAmXZP2RlwleaTAkjMJYFJIbWZP2F0/2G2 spsplvVcLONh1tJDrloALzeuFClyLTJR5FR0dlVo8pAR6csHRWGJ+JGNNzmwJtxD 6hLcBSOLct5VwPgESFHSExEBRH+XNLOM1q9YTVKoxdnyk/dbZM3zaMRFjCpnYLq1 gHwI6cEGywpOc7SQPrsYHaLT55SIvJnceRCWYELIbSjSlSji4DXb9a6AwXWbzLNC JHyBuDY8iIw3tQ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=Inti+Ji4hJBIaMry21vmPEsldoYgFyScgWmgmCm8U6o=; b=bsMMZngT JW0TUq/PUKRCcwGj/Y2/fe6rtyjpl4VY/I/VN34LUvtRuhPTYiR+ruK5IJw+nD+3 L63ka2ZIxshLh41Eqgl3HbLjHTYA03MizX65pMQdoVOtZXpisc8pjtlBHQe1SCNK 7yoexGtfaTBSDT9ZuoGiWifC22zpRdfrr1XFNwDZpm2fQSxM2x1LK0H9D2wxL7Cg B2sNK7dJtIXLRSvwHysUwhszMdb6zDTeIW5RY/LfF4Chd+j9KJzTfKRXUjjvmzT4 r8aLeLxKZnHL+Wvy0ha7/U1Kzy8qFFNpnPgQf/I+8+bxGLtVQKdxr4oSc+5j1ECo Gu/7ZhKP0rrlBw==
- In-reply-to: <0c1b9d89-edd0-a027-e2f1-d01c2d68fa4e@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <0c1b9d89-edd0-a027-e2f1-d01c2d68fa4e@eastlink.ca>
Ray Andrews wrote on Sun, Mar 26, 2017 at 13:22:24 -0700:
> Gentlemen:
>
> This function:
>
> mostrecent ()
> {
> ls -l ${(f)$( find . -type f -printf "%T@ %p\n" | sort -n | cut -d'
> ' -f 2- | tail -n 1 )}
> }
You could replace the whole function with:
mostrecent() { ls -l -- **/*(.om[1]) }
That glob qualifier restricts the match to files ('.'), sorts them by
modified date ('om'), and selects the first result ('[1]').
You can then use [1,3] to select several files.
> Testing it on this dummy directory tree:
>
> ├── [ 0] a
> ├── [4.0K] absolute junk
> │ └── [ 0] junk
> ├── [ 0] b
> └── [ 0] c
>
> If the most recent file is under 'absolute junk', the function works, but it
> requires the ' ${(f) ... ' treatment, otherwise it barfs at the space in the
> directory name. However, if I change things to ' tail -n 3 " it shows me:
>
> ls: cannot access './a ./absolute junk/junk ./c': No such file or directory
>
> So whereas the ' ${(f) ' treatment fixes the one problem, it creates the
> other, which is obviously that everything is one string. Can I have it both
> ways? Protected spaces in the directory name, and still have multiple items
> for the listing? I've done stuff like this before, but using arrays.
>
> Or can printf handle the situation by itself?
As Vadim said, putting the $() in double quotes makes this example work.
Another option here is to use find -print0 with ${(0)}. That only
matter if you need to DTRT when filenames contain NL characters.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author