Tried doing a STRQSH and then a ls -? to find the parameters.  Not nearly
definitive as DOS help, eh?

On a Unix system (not the iSeries) you'd normally get help on any command by typing "man ls" (or whatever the command happens to be) the resulting help screen is MUCH more informative than the MS-DOS version.


<rant>
Try finding out what to pass to "NET SEND" on Windows if you're not already familiar with the parameters!!!


C:\WINDOWS>net send /?
The syntax of this command is:

NET SEND
{name | * | /DOMAIN[:name] | /USERS} message

Gee, thanks. And this is the only help I'm aware of for this command...
</rant>

Anyway, the iSeries doesn't have the Unix manual on-line. Instead, you have to go to the Information Center to get help on QShell commands.

Programming -> Shells and Utilities -> QShell -> Utilities -> L -> ls


What I want to do is pipe the listing of ls through whatever their version
of DEL is.  However I was wondering if there was some selection criteria
on the ls command that would say files that have a last modified date x
days old.

The Unix equivalent of "DEL" is "rm" (remove). But the PIPE sends data to it's standard input stream, and "rm" deletes files based on it's parameters, not it's standard input. Fortunately, there's a utility that converts standard input to a parameter list called "xargs". What it does is read the standard input and use it to create a command string. Whatever you specify as xargs' parameters will be added to the start of the command string.


So, the following command would try to run the QShell command line "foo bar":
echo "foo" | xargs bar


The 'ls' utility won't list files based on age, but the 'find' command will. For example, to delete files (but not directories) under the /home/scott directory that haven't been modified in 10 days, you could type:

  find /home/scott -type f -mtime +10 | xargs rm

For testing purposes, I'd recommend typing

  find /whatever -type f -mtime +10

to make sure it gives you the output that you're expecting. Then add the 'xargs rm' to the end when you're sure it's only going to delete the right stuff.

The other problem you may run into is the maximum length of a single command string. If there are a million files that need to be deleted, it won't all fit on a single command line generated by xargs.

If that happens, you can tell QShell to launch a separater "rm" for each command. It will take a LOT longer, but it'll work:

  find /home/scott -type f -mtime +10 -exec rm {} \;

the -exec switch tells it to execute a command. Everything after the -exec and before the semi-colon is considered a part of the command it executes. The braces "{}" will be replaced with each filename for each file that it wants to delete. The backslash is needed to escape the semi-colon so that it'll get passed to the find utility rather than being interpreted by Qshell itself.

But, like I said, using -exec is very inefficient on computer resources because it submits a separate job for each file that you want to delete, whereas the xargs version submits only one job that deletes them all.

Of course, if you really need the ability to delete an unlimited number of files, you could redirect the output of "find" to a physical file member, and have a CL program that reads that member and deletes each file with the RMVLNK command. That would also be more efficient than -exec...

Okay, I've said enough for now :)


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.