This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Force "ls" to show .exe extension
- From: Paul <Paul dot Domaskis at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Thu, 8 Jan 2015 15:38:30 +0000 (UTC)
- Subject: Re: Force "ls" to show .exe extension
- Authentication-results: sourceware.org; auth=none
- References: <loom dot 20150106T203355-631 at post dot gmane dot org> <1941710256 dot 20150107013212 at yandex dot ru> <loom dot 20150107T010713-891 at post dot gmane dot org> <6CF2FC1279D0844C9357664DC5A08BA20FA979B4 at msgb09 dot nih dot gov> <loom dot 20150107T164855-744 at post dot gmane dot org> <D0D2B422 dot 8725%bob_mcgowan at symantec dot com>
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