To avoid the problem of the "for" line getting to long use "while" not "for". We can then deal with any number of files.
If we redirect the error channel from "ls" we stop "ls" failing if there are no matching files. We now don't need to count the files or deal with the problem that the "find" actualy counts the files in the subdirectories too.
No need to use ls in for, because shell file generation can do it. Filegenaration is handled by shell, not by command (*, ?, ...). Maybe number of arguments is not problem for shell. If it's, then you need tmp-file.
This version try to use shell built-in commands = much faster as use external commands like awk, sed, ...
If I understood your needs, here is version N. Works with ksh, bash, posix-sh, ...
In this example maybe case is the most beautiful (my opinion).
I agree that the "case" construct is more readable.
There are many posts on this forum where the "for" construct breaks because the list causes the "for" statement to be too long ... or any filename contains spaces. Depends on local conditions.
I think that problem is not for, problem is ls.
I just tested with 62000 files in one directory. ls *.txt not work but
for f in *.txt
works fine.
If you use ksh (software download selections), then filegeneration limit is maybe some huge value, but 62000 files was okay.
for also works fine with filenames which have spaces and other special characters.
Why so many use
for f in $(ls *.txt) ?
for f in *.txt is enough, no need to use with ls
Maybe dos history ?
In sh-shells *, ?, ... are handled by shell, not by command, so you can use those marks with any commands like
print *.txt
You are right. Even with a modern shell it is quite easy to exceed the maximum size of a variable or the maximum length of a command line. The dodgy syntax includes:
I too wonder why so many are expanding "ls" on the command line.
Hi we are using AIX 5.3 64bit
I have near about 79000 log file having naming convention like "IFTMBCSun Aug 14 07:45:00 PAKST 2011".
This naming convention was created by a script error, now we need to rename these log file by removing extar spaces and (:) colon for that we wrote below script
... (4 Replies)
Hi,
I am getting the below error message When i am trying to delete the files from the directory.Could you please guide me?
rm *.aud
ksh: /usr/bin/rm: 0403-027 The parameter list is too long.
and
find /oracle/admin/testP/adump/*.aud -mtime +5 -exec rm {} \;
ksh: /usr/bin/find:... (3 Replies)
Hello All,
We have a batch job that clean old records. This run a script to back up file then delete. Unfortunately, this job been failing lately. This is the error we received.
"/usr/bin/compress: 0403-027 The parameter list is too long."
I am not sure if the job failed since its... (2 Replies)
Hi,
I'm trying to list specific files and redirecting to a file
ls aqp* > temp.lst
but getting "/usr/bin/ls: 0403-027 the parameter list is too long." error. I just have 236 files in the directory.
I tried "ls | grep 'aqp*' > temp.lst" too, but nothing was redirected.
+ grep aqp*
+... (4 Replies)
hi
when i ran the following command
rm *_F
i got this error
0403-027 The parameter list is too long.
It shd remove 5000(around) files
pls help me on this.
why its throwing this error
how to rectify this error (5 Replies)
I am using IBM AIX unix version 4.3.3.0.
In a directory there are many files with different patterns.
When I am trying to execute the command, ls -l with the file pattern, which have fewer files it gives the desired result. However when I am trying to execute the same command for file pattern,... (2 Replies)
when i run the command below in a directory which contains too
many files i got the error: ksh: /bin/grep: arg list too long
ls|grep AA*B*
how can i handle this problem? (5 Replies)
Hello,
I create a file touch 1201093003 fichcomp
and inside a repertory (which hava a lot of files) I want to list all files created before this file :
find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long
but i make a filter all... (1 Reply)
Hi there
I get this error message when I try to do a basic grep. Does anyone have any ideas what is wrong. Thanks
0403-027 The parameter list is too long. (1 Reply)