First off, I should say that I posted a similar query about pathnames (specifically how to remove them) on linuxquestions quite recently and it was helpfully answered. The following question is a little different....:
I am have trouble getting the ls command to work exactly how I want, for example, sometimes I want to list the contents of a directory into a text file by command:
ls directory > list.txt
(assume the only objects the directory contains are files with extension .dat eg file1.dat, file2.dat, ...)sometimes I want the relative path of the files prepended to them in my text file eg:
other times I want just the file name and not the path, eg.:
It feels like ls is unpredictable in this regard - sometimes it prepends the path and sometimes it doesn't and sometimes it adds both entries (with and without the path prepended into the text file)....How can better control the way ls works?