ls -1tr | tail -1 doesn't work in cygwin

1

I have a weird situation here... two out of three of my servers refuse to give any output to the command ls -1tr | tail -1

There are definitely files in the directory but it gives no output what so ever (returns nothing and goes back to the prompt)... simply typing ls or ls -c works but not ls -1tr | tail -1

x2 Server 2003

x1 Server 2008

Only one of the Server 2003 gives the correct response to the command.

I have put the /bin directory in the windows environmental path field so I don't think that is the problem.

Any suggestions?

emtunc

Posted 2011-03-13T17:41:10.450

Reputation: 613

Does the more formal ls -1tr | tail -n 1 work? – p.vitzliputzli – 2011-03-13T18:03:11.000

Answers

3

The tail -[number] syntax is no longer valid by POSIX.1-2008. Maybe you are using different versions of the coreutils and that is why you are experiencing different results. The correct syntax is ls -1tr | tail -n 1.

p.vitzliputzli

Posted 2011-03-13T17:41:10.450

Reputation: 587

Your "corrected" syntax is uncorrected. – Paused until further notice. – 2011-03-13T19:58:13.390

When I try that on the two servers that did not work before, I now get the message:

"TAIL: can't open 1" – emtunc – 2011-03-13T20:13:43.377

1Besides from trying to upgrade your cygwin installations, you could try to use ls -1tr | tail --lines=1. – p.vitzliputzli – 2011-03-13T20:54:55.297

Updated the installation but still receiving the same message "TAIL: can't open 1"... @p.vitzliputzli when I tried that command, I got a "TAIL: lseeki64() failed 22" message - not sure what that means. – emtunc – 2011-03-14T10:56:44.947

1Errno 22 is probably EINVAL, i.e. invalid argument. It sounds like you have encountered a cygwin bug. Nevertheless, could you please post the coreutils/tail-version? tail --version – p.vitzliputzli – 2011-03-14T11:46:01.047

tail --version throws a "TAIL:lseeki64() failed 9" error - it looks like a completely messed up install to me (or a lot of missing components) - it may be worth installing to a completely different directory to see if I get the same issue - what do you think? – emtunc – 2011-03-14T13:52:13.663

1Yes, I would try that with the default installation. – p.vitzliputzli – 2011-03-14T14:00:21.413

@p.vitzliputzli - great, it works now with the commands above! One small problem though, when I run my batch script which has the following in it "C:\cygwin\bin\bash -c "script.sh" - it tries to use the old bash from the previous installation (the new installation is C:\cygwin and the old one was in C:\ssh) - are you aware of any config or why the bash.exe in the new installation dir is still using or pointing to the old one? Hope that makes sense! – emtunc – 2011-03-14T15:20:43.103

1Maybe you have to change the PATH-var in Windows to your new cygwin installation. – p.vitzliputzli – 2011-03-14T15:34:49.383

p.vitzliputzli@ Already tried that... hmm strange – emtunc – 2011-03-14T15:51:57.057

1Apparently, there are some keys in the registry. Could you search for "cygwin" with regedit? – p.vitzliputzli – 2011-03-14T17:43:31.150

@p.vitzliputzli I did that but got the same issue - I looked at it again today (after some rest :D) and managed to see the problem - I was just using the "-c" switch instead of "--login -c -c" - thanks for all your help! :-) – emtunc – 2011-03-15T15:40:55.720