How can I make ls and xargs combined omit path

Posted by Steve McLeod on Server Fault See other posts from Server Fault or by Steve McLeod
Published on 2013-10-22T17:13:12Z Indexed on 2013/10/23 3:57 UTC
Read the original article Hit count: 485

Filed under:
|

I have a folder called lib. In that folder are some files. I want to obtain all the names of the files that end in .jar, and concatenate them into a line, separated by spaces. I don't want the path name at all.

I've tried this:

ls lib/*.jar | xargs

and the output is

lib/file1.jar lib/file2.jar

But what I'm trying to get is

file1.jar file2.jar

How can I do this?

I've also tried find but I get the same problem

find lib -name *.jar | xargs

© Server Fault or respective owner

Related posts about bash

Related posts about ls