The standard unix find command is powerful and flexible and is necessary because the unix ls command was originally designed for human readability.
In brash, the .ls command acts like a cross between the windows "dir /b" command and "the linux ls -l" command. Because of its interface, the complexity of unix's find command is not as necessary. Basically, .ls gives most of the features of find -- though not the ability to invoke commands on each file or test specific file attributes.
The basic logic of using find is to pipe the results to some program that uses the names, like this:
find[options]directories|use_the_results
In brash, the same thing would be done with .ls
.ls-Rdirectories|use_the_results
If it is not convenient to embed the logic of filtering the list of file names in use_the_results, then an intermediate loop can be used:
.ls-Rdirectories|whilereadfile
do
if [ testOperator file ]
then
echo "$file" # only print the needed file names
fi
done | use_the_results
Note that there are several testOperator that can be used to filter names:
By release 1.2.12, the .ls builtin command now has a couple of useful command line options to aid in implementing unix find-like operations:
--sep=string (which lets you define something other than space as a field separator)
--seconds (which causes the time to be printed in seconds since 1970)
These options allow you to more easily parse the fields in the .ls outpout -- particularly if you combine them with the .cut command.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The standard unix find command is powerful and flexible and is necessary because the unix ls command was originally designed for human readability.
In brash, the .ls command acts like a cross between the windows "dir /b" command and "the linux ls -l" command. Because of its interface, the complexity of unix's find command is not as necessary. Basically, .ls gives most of the features of find -- though not the ability to invoke commands on each file or test specific file attributes.
The basic logic of using find is to pipe the results to some program that uses the names, like this:
In brash, the same thing would be done with .ls
If it is not convenient to embed the logic of filtering the list of file names in use_the_results, then an intermediate loop can be used:
Note that there are several testOperator that can be used to filter names:
Additionally case statements can be used to interpret parts of the file name
See also the .stat command in brash which lets you get at more details of the file than the test operators provide.
Here's its -h output:
By release 1.2.12, the .ls builtin command now has a couple of useful command line options to aid in implementing unix find-like operations:
--sep=string (which lets you define something other than space as a field separator)
--seconds (which causes the time to be printed in seconds since 1970)
These options allow you to more easily parse the fields in the .ls outpout -- particularly if you combine them with the .cut command.