I want a simple list of files in a directory that is not my current directory. I run ls /other/directory/*.txt and get:
/other/directory/file1.txt /other/directory/file2.txt
I want:
file1.txt file2.txt
How can I get the second list?
|
show 1 more comment
feedback
|
This question came from our site for professional and enthusiast programmers.
|
Is there some reason why you can not use
EDIT: I notice you've changed the question now - my solution won't work with your new example of
| |||
|
feedback
|
|
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 | |||||||||||||||||||||
feedback
|
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! | |||
|
feedback
|
*.txtmade a difference. I updated the question. – User1 Nov 11 '10 at 16:10