Force "ls" to show .exe extension

Paul Paul.Domaskis@gmail.com
Thu Jan 8 15:40:00 GMT 2015


Bob McGowan <Bob_McGowan <at> symantec.com> writes:
| Back to Paul's problem, getting a list of the actual filenames, as
| they actually exist in the filesystem, can be handled by 'find', I
| think.  At least it worked in my simple test setup, above.
| 
| $ find . -name abc
| ./abc
| $ find . -name 'abc*'
| ./abc
| ./abc.bat
| ./abc.exe
| ./abc.sh
| 
| Since find prints each file name on a line by itself, filenames with
| spaces just "work":
| 
| $ touch 'pdq xyz'
| $ find .
| .
| ./abc
| ./abc.bat
| ./abc.exe
| ./abc.sh
| ./pdq xyz
| 
| To process the above output, use a 'while' loop with the 'read'
| command and quote the shell variable in the loop body to preserve
| the single filename with spaces:
| 
| $ find . |
| > while read filenames
| > do
| >  file "$filenames"
| > done
| .: directory
| ./abc: empty
| ./abc.bat: empty
| ./abc.exe: empty
| ./abc.sh: empty
| ./pdq xyz: empty
| 
| The above is for illustration only.  It is not efficient, since
| 'file' is run 6 times, when it could have run once with multiple
| file names, but then the quoting wouild be more difficult.  You
| would replace it with 'ls -l' to get individual file metadata,
| though again it would be inefficient.
| 
| Using 'xargs' would improve this, assuming the right parameters are
| used.  This will work with 'xargs' and 'cpio', I'm not sure which
| other commands might support literal NULL termination of strings
| (note the 0 (zero) in each command's args).
| 
| find . -print0 | xargs -0 file
| .: directory
| ./abc: empty
| ./abc.bat: empty
| ./abc.exe: empty
| ./abc.sh: empty
| ./pdq xyz: empty

It certainly is educational.  For the original problem, though, I'd
like to keep it simple enough to fit into one line.  It has to accept
output from "type" and must allow for "ls -l" and/or "ls -ltd" (or the
like):

   $ls -d `type -pa pdfcrop | sed -e 's/.*/&*/'`

      /bin/pdfcrop@  /home/User.Name/bin/pdfcrop.exe*
      /usr/bin/pdfcrop@

   $ls -ld `type -pa pdfcrop | sed -e 's/.*/&*/'`

      lrwxrwxrwx 1 User.Name Domain Users 48 Nov 10 16:35 /bin/pdfcrop
      -> /usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl*

      -rwx------+ 1 User.Name Domain Users 33792 Jun 21 2013
      /home/User.Name/bin/pdfcrop.exe*

      lrwxrwxrwx 1 User.Name Domain Users 48 Nov 10 16:35
      /usr/bin/pdfcrop ->
      /usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl*

I don't like using the back ticks myself because of its atrocious
readability, but I'm not religious about it.

P.S. Gotta luv the gmane captcha words.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list