LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-26-2008, 12:44 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
error on ls -lt


Hi all,

I am getting a error , while i run the command inside a directory.

ls -lt /A/B/C/D/filetolist*

-bash: /bin/ls: Argument list too long...

I want to know the reason for this and an alternate solution to it. Since this output, will be used for a script, I want the desired output of "ls -lt"

Suggest some ways to go with

Thanks
 
Old 05-26-2008, 01:12 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
It means that when the shell expands the wildcard '*' you end up with too many files that match ie too many args for ls to handle.
What you can do is just a straight ls of the dir (which will just read the info from the dir file) and grep out the ones you want

Code:
for file in `ls A/B/C/D |grep ^filetolist`
do
    ls -lt $file
done
Do you really need the info from the -lt switches?
 
Old 05-26-2008, 01:53 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Chris,

Thanks for the response.

Do you really need the info from the -lt switches?

Really needed. The script am using is listing the latest files from a number of directories. I failed to got the output(mailed to me, by the sctipt) for 2 directories , for the past couple of days .Then i found, the standard error in the mail from cron.

line 27: /bin/ls: Argument list too long (for the 2lines , denoting the 2 failed directories.)

I need to change the entire script , if i go on the way you shown....

Is there any other way to solve this...


Thanks Again
 
Old 05-26-2008, 02:26 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
The script am using is listing the latest files from a number of directories.
You can try to use find. For example if you want to find the files whose modification time is less than 5 days, you can do
Code:
find /A/B/C/D/ -mtime -5 -exec ls -l {} \;
using -exec you can execute the command ls -l over each of the files found. Or you can try the stat command to extract some more specific information (see man stat for details).
 
Old 05-26-2008, 02:50 AM   #5
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Thanks Colucix.,,


I can go with the "find " . The command you gave
find /A/B/C/D/ -mtime -5 -exec ls -l {} \;
is listing all files in that directory. But all the details I needed are there. Can you give me a "find" option to list the files created , within the last 5 days(along with ls -l , as above).

Thanks
 
Old 05-26-2008, 04:16 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I think it gives problems with recursion. Try either
Code:
find /A/B/C/D -mindepth 1 -mtime -5 -exec ls -l {} \;
or
Code:
find /A/B/C/D -type f -mtime -5 -exec ls -l {} \;
ZAMO, just a little advice: use the code tags for posting command lines: they are more readable and preserve multiple spaces, tabs and indentation. To embed a text inside code tags, go in advanced mode, select the text you want to embed and press the "#" button. Or put the code tags by typing them directly. Like this

[CO DE]do i = 1,n
write(*,*) array(n)
done[/CO DE]

strip out the blank space between O and D (I put it to show you what code tags are) and the trick is done
Code:
do i = 1,n
    write(*,*) array(n)
done
 
Old 05-26-2008, 04:57 AM   #7
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by colucix View Post
To embed a text inside code tags, go in advanced mode, select the text you want to embed and press the "#" button. Or put the code tags by typing them directly. Like this

[CO DE]do i = 1,n
write(*,*) array(n)
done[/CO DE]

strip out the blank space between O and D (I put it to show you what code tags are) and the trick is done
Code:
do i = 1,n
    write(*,*) array(n)
done
@colucix: A slightly off-topic remark, but to illustrate how to format stuff in the forum, you can use [noparse][/noparse] tags, which will not interpret the information between those tags. This allows you to write [code][/code] and it will not insert a code block.
 
Old 05-26-2008, 05:09 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Good to know! Thank you, pwc101!
 
Old 05-26-2008, 09:38 AM   #9
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Thanks Again Colucix...

Yes ,am able to go with "find" . But i have an issue in this .

I have to list files with different names in a same directory too..

For you to understand my need.. Please have a look this link. Ignore the unanswered last post from me.

Code:
http://www.linuxquestions.org/questions/linux-general-1/bash-scripting-help-needed-640810/
Instead of working with

Code:
ls -t abc/123/ABC/456/freshfile* |head -2|tail -1|awk -F\/ '{print $NF}'

Code:
find abc/123/ABC/456  -type f -mtime -5 -exec ls -lt {} \; |tail -1 |awk -F\/ '{print $NF}'
Any Idea to get my desired output.

Sorry .,, If i confuse you a Lot
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Putty fatal error: Network error: connection refused (ubunty server 6.06.1) gerardnijboer Ubuntu 2 03-18-2010 03:46 PM
Conmpile error wen compile php:configure: error: libpng.(a|so) not found tanveer Linux - Software 5 02-03-2009 06:13 AM
Suse CUPS error: cups(File)DoRequest error:client-error-bad-request smdonelan Linux - Hardware 6 04-17-2007 06:46 PM
updating new installation of 9.3 ERROR...ERROR...ERROR Morbid SUSE / openSUSE 3 08-15-2005 11:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration