In the table on our linux commands page, the following bash command was used to illustrate a rather complicated alias command:
$ alias createdToday=' TODAY=` date | cut -c5-10 ` ; LIST=` \ls -lc | grep "${TODAY}" | cut -f2 -d: | cut -f2 -d" " `; for file in ${LIST} ; do echo ${file} ; done ; unset TODAY LIST '
This example is complicated and a careful description of what is happening here seems like a good way to explain why and how some of the concepts described in our brief linux tutorial can be strung together to accomplish something useful.
The command is a single long line of text that effectively creates a user-defined command called createdToday. This new command lists all files in the current area that were created or modified today. It does this by combining some standard commands that the bash shell understands and a mixture of command separator symbols (;), command substitution symbols (the pairs of `'s) and several pipes (the | symbols, which make the output of one command become input to the next).
If this command had been written for the tcsh shell, it would only appear marginally different.
It is much easier to see what this command is doing and how it works if it is broken down into more easily read "logical units" using colors
$ alias createdToday=' TODAY=` date | cut -c5-10 ` ; LIST=` \ls -lc | grep "${TODAY}" | cut -f2 -d: | cut -f2 -d" " `; for file in ${LIST} ; do echo ${file} ; done ; unset TODAY LIST '
or (better yet) using separate lines for the different units:
$ alias createdToday=' TODAY=` date | cut -c5-10 ` ;
LIST=` \ls -lc | grep "${TODAY}" | cut -f2 -d: | cut -f2 -d" " ` ;
for file in ${LIST} ;
do echo ${file} ;
done ;
unset TODAY LIST
NOTE: While you could cut and paste the single line command into a linux terminal window and create the correct command, if you try the same thing with this set of comnmands broken into separate lines, it will fail completely. You could, however, ignore the bits containing " alias createdToday=" and the semi-colons (the ;'s), and instead cut and paste each separate line into a terminal window. This sequence of commands would list the files created today, which is what the createdToday command is designed to do. The alias command simply combines all these steps into a new, user-created command.