[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Remove file resulting from ls|tail -1



On Vi, 19 iul 13, 21:15:35, Claudius Hubig wrote:
> Dear Oscar,
> 
> what a surprising name…
> 
> OECT T wrote:
> > I need to delete the file resulting from:  ls | tail -1
 
How do you know the last file in the output of 'ls' is the one you need? 
I'd rather use find with -delete for something like this.

> In Bash, $(command) is replaced with the output of "command". For
> example,
> 
> $ touch $(seq 1 4)
> 
> will create files 1, 2, 3 and 4. So you likely want something like
> 
> $ rm -i "$(ls | tail -1)"
> 
> where the "-i" is for interactive mode (rm will ask you) and the
> quotation marks are such that this is treated as a single argument
> rather than many different ones.
> 
> Note that you might also want to think of passing ls "-1" and and
> possibly sort before taking the tail.

-1 is implied when ls outputs to a pipe, but can't find that in the 
manpage right now. It also has lots of sort options, so there should be 
no need for another program to do that.

Kind regards,
Andrei
-- 
http://wiki.debian.org/FAQsFromDebianUser
Offtopic discussions among Debian users and developers:
http://lists.alioth.debian.org/mailman/listinfo/d-community-offtopic
http://nuvreauspam.ro/gpg-transition.txt

Attachment: signature.asc
Description: Digital signature


Reply to: