Operating System - HP-UX
1822430 Members
3141 Online
109642 Solutions
New Discussion юеВ

starnge behaviour of ls command

 
SOLVED
Go to solution
Percy Glaves
Occasional Advisor

starnge behaviour of ls command

Dear Sirs,

I've a rather big directory in which if I do a command like, ls or ls -al, everything will work fine, I'll get my listing. BUt if I do something like
# ls df* or ls *.lis will give no listing and get only a
/usr/bin/ls : Arg list too long message

There are plenty of file called df01.lis in that directory, so I expected something to come out!


Any idea on what could be wrong?

Thanks very much,

Percy Glaves
4 REPLIES 4
TwoProc
Honored Contributor
Solution

Re: starnge behaviour of ls command

There are too many files of type "*.lis" or "df*" to list for the ls command.

Do this instead:

cd /yourdatadirectory
find . -name "df*" -o -name "*.lis" | xargs -i ls -al {} > /tmp/dirlisting.out

Oh, and btw, if possible it's time to clean some files from that directory!

:-)

We are the people our parents warned us about --Jimmy Buffett
HGN
Honored Contributor

Re: starnge behaviour of ls command

James R. Ferguson
Acclaimed Contributor

Re: starnge behaviour of ls command

Hi Percy:

This is quite expected.

The shell is expanding all filenames that match the characters before the asterisk ("*") and *then* passing (or trying to pass) that argument list to the 'ls' command. Thus, you do:

# ls w*

(for example)

...but the shell really expands this to look like:

# ls what whence where whether why ...

...or whatever files exist in the directory in which you are running.

This can lead to an argument-list-too-long error. There is nothing wrong other than you must divide and conquer by reducing the length of the list. In this case, that could be as simple as adding a few more characters to match before the asterisk.

Regards!

...JRF...
Percy Glaves
Occasional Advisor

Re: starnge behaviour of ls command

Yes, the problem was a big amount of files with almost same names. with the help of xargs went ok.

Thanks very much