I want a simple list of files in a directory that is not my current directory. I run
ls /other/directory/*.txt and get:
How can I get the second list?
migrated from stackoverflow.com Nov 12 '10 at 0:47
This question came from our site for professional and enthusiast programmers.
Is there some reason why you can not use
I notice you've changed the question now - my solution won't work with your new example of
2) ls doesn't print the full path anyway:
Edit The question has changed. Per Paul's comment below I am updating my answer. You can do it like this:
That's a minus 1, not l, although l works too. Explanation: ls -l/-1 writes out the file names with the stuff you don't want. Each line is piped through sed, which here is doing a substitution, as specified by the s/. A substitution takes the form:
We are substituting everything from the beginning of the line
The expression in `` gets expanded to the files, then each of them is passed to basename. Caveat: Does not work with files containing white spaces!