This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Force "ls" to show .exe extension


On 1/7/15, 8:07 AM, "Paul" <Paul.Domaskis@gmail.com> wrote:

>Buchbinder, Barry (NIH/NIAID) [E] <BBuchbinder <at> niaid.nih.gov> writes:
>>Paul sent the following at Tuesday, January 06, 2015 7:12 PM
>>> I'm wading through many files in two file trees. In particular, I'm
>>> looking at corresponding directories in the two trees where "diff
>>> -qr" revealed differences. I want the absolute truth of what the
>>> filename is with minimal distractions about how to achieve that.
>>> Then, I can focus on figuring how those files came about, and how
>>> the differences arose.
>> 
>> Not a Cygwin solution but the following should give real names.
>> 
>> cmd /c dir /b /a:
>> 
>> (The /a: makes sure that hidden files are listed.)
>
>That works great, Barry.  The following also works:
>
>   cmd /c dir /b /a: | dos2unix | xargs ls -ltd
>
>However, variation#1
>
>   type -pa pdfcrop | xargs cmd /c dir /b /a:
>
>doesn't work because dir expects DOS filenames (I suspect).
>
>Variation#2
>
>   type -pa pdfcrop | xargs cygpath -aw | xargs cmd /c dir /b /a:
>
>doesn't work because the backward slashes are interpretted by Escapes
>by bash.
>
>Variation#3 (on *one* line):
>
>   type -pa pdfcrop | xargs cygpath -aw -t mixed | xargs cmd /c dir /b
>   /a:
>
>doesn't work because
>
>   Parameter format not correct - "cygwin64"
>
>To find out what was going on, I stuck an "echo" in front of cmd,
>which yielded the following (on *one* line):
>
>   cmd /c dir /b /a: C:/cygwin64/home/User.Name/bin/pdfcrop
>   C:/cygwin64/usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl
>   C:/cygwin64/usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl
>
>I think the dir command is interpreting /cygwin64 as a command switch.

That is true.

To further add to the confusion this can cause (and a possible solution
after this):

$ ls -l
total 3
-rwxr-xr-x 1 rmcgowan None 45 Jan  6 15:12 abc.bat
-rwxr-xr-x 1 rmcgowan None 50 Jan  7 09:48 abc.exe # note this file size
-rwxr-xr-x 1 rmcgowan None 48 Jan  6 15:15 abc.sh
$ date > abc # NOTE file name...
$ l
total 3
-rwxr-xr-x 1 rmcgowan None 45 Jan  6 15:12 abc.bat
-rwxr-xr-x 1 rmcgowan None 30 Jan  7 09:48 abc.exe # And here.
-rwxr-xr-x 1 rmcgowan None 48 Jan  6 15:15 abc.sh


And trying to do a 'touch abc' changes the date associated with abc.exe
(it was Jan 6, is now Jan 7).

But 'mkdir abc' creates the directory abc.

And in an empty directory, 'touch abc' creates the empty file 'abc', and
'touch abc.exe' then creates 'abc.exe'.

And now, if you do a 'touch abc', the timestamp of the file 'abc' is
changed, and 'abc.exe' is left alone.

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


I hope this is helpful.

Bob


--
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]