sort
commandsort
simply sorts the contents of a file or stream
and displays the sorted data to the terminal. There are several
options to sort which will modify the way which data is sorted
by the command.
The basic syntax is shown below:
>> sort filename.txt
The "-n" option causes the command to sort the data as
numbers instead of alphabetically.
>> sort -n filename.txt
The "-r" option causes the command to reverse the
order of the sorted data.
>> sort -r filename.txt
grep
commandgrep
is used to filter data from a file and then
display the resulting data to the terminal.
The basic syntax is shown below:
>> grep string filename.txt
In the example above grep
will search the file
"filename.txt" and return any lines which have the
text "string" in them.
The "-v" option inverts the search:
>>grep -v string filename.txt
In this example grep
will search the file
"filename.txt" and return any lines which do
NOT have the text "string" in them.
Normally grep
is case sensitive. This means that a
search for the text "string" will not match
"STRING" nor will it match "StRiNG". The
"-i" option causes grep
to ignore any
case differences in its search.
>> grep -i string filename.txt
alias
commandalias
creates or changes an 'alias' for a command; it is typically used to create a shortcut to a more complex command, often with the same name as the aliased command. For example, rather than enter the command ls -F
one could create an alias command (also called ls
in this example) that includes the option -F
. In that case, entering the command ls
woudl actually invoke the command ls -F
.
The basic syntax for the bash
shell is shown below:
>> alias myname='name -flags'
In the C shell, do not use the '=' sign, just a space.
In the example above myname
will invoke the command name
with the option -flags
. The apostrophes are used if there is a whitespace in the aliased command.
The alias
command with no arguments lists all aliases that are set:
>>alias
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias myname='name -flags'
alias vi='vim'
The unalias
command will remove the alias:
>> unalias myname
|
||||
>> >> echo Something > file.out >> cat file.out Something >> |
|
||||
>> >> df > /mnt/homes/tuckerm/df.out >> cat ~/df.out Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda3 4806572 4231116 331268 93% / /dev/hda6 8277240 6879728 977014 88% /software /dev/hdb1 118160964 37351852 74806428 34% /data /dev/hda2 4883604 3502264 1381340 72% /mnt/other /dev/hda1 19606554 16422 18594104 1% /data/misc omega:/var/data/ldm 172297760 107148368 51365568 68% /mnt/data omega:/var/data/arch 48082320 43248592 987136 98% /mnt/arch omega:/var/data/metadmin 172297760 107148368 51365568 68% /mnt/metadmin omega:/export/homes 20644848 9267136 9726128 49% /mnt/homes /data/temp/slackware-9.0-install.iso 678688 678688 0 100% /mnt/loop //alpha/mht06220 84371456 76660736 7710720 91% /mnt/z-drives/mark >> |
|
||||
>> >> who -H >> who.out >> cat who.out USER LINE LOGIN-TIME FROM mark :0 Feb 9 12:30 tuckerm pts/5 Feb 11 18:50 >> |
who
command will be added on to
the end of the existing file "file.out". If the file
did not exist,
it would be created by the redirection.
cat
utility.
|
||||
>> >> cat df.out who.out > new.out >> cat new.out Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda3 4806572 4231116 331268 93% / /dev/hda6 8277240 6879728 977014 88% /software /dev/hdb1 118160964 37351852 74806428 34% /data /dev/hda2 4883604 3502264 1381340 72% /mnt/other /dev/hda1 19606554 16422 18594104 1% /data/misc omega:/var/data/ldm 172297760 107148368 51365568 68% /mnt/data omega:/var/data/arch 48082320 43248592 987136 98% /mnt/arch omega:/var/data/metadmin 172297760 107148368 51365568 68% /mnt/metadmin omega:/export/homes 20644848 9267136 9726128 49% /mnt/homes /data/temp/slackware-9.0-install.iso 678688 678688 0 100% /mnt/loop //alpha/mht06220 84371456 76660736 7710720 91% /mnt/z-drives/mark USER LINE LOGIN-TIME FROM mark :0 Feb 9 12:30 tuckerm pts/5 Feb 11 18:50 >> |
|
||||
>> >> cat < new.out Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda3 4806572 4231116 331268 93% / /dev/hda6 8277240 6879728 977014 88% /software /dev/hdb1 118160964 37351852 74806428 34% /data /dev/hda2 4883604 3502264 1381340 72% /mnt/other /dev/hda1 19606554 16422 18594104 1% /data/misc omega:/var/data/ldm 172297760 107148368 51365568 68% /mnt/data omega:/var/data/arch 48082320 43248592 987136 98% /mnt/arch omega:/var/data/metadmin 172297760 107148368 51365568 68% /mnt/metadmin omega:/export/homes 20644848 9267136 9726128 49% /mnt/homes /data/temp/slackware-9.0-install.iso 678688 678688 0 100% /mnt/loop //alpha/mht06220 84371456 76660736 7710720 91% /mnt/z-drives/mark USER LINE LOGIN-TIME FROM mark :0 Feb 9 12:30 tuckerm pts/5 Feb 11 18:50 >> |
cat
command. cat
then does its
operations to display the contents of the redirected data to the
screen.
|
||||
>> >> cat < new.out > new2.out >> |
|
||||
>> >> ls -l |less >> |
ls
command and
will feed it to the less
command. less
will treat this data as if it were read from a file.
Example:
|
||||
>> >> last | grep tuckerm >> |
last
command and will only display out any lines
which contain the text "tuckerm"
Another example:
|
||||
>> >> last | grep tuckerm | head -5 >> |
last
command and will only display out any lines
which contain the text "tuckerm". Piping the data into
head
with the "-5" option will cause only
the first five lines of the output to be displayed.
Combining pipes and redirection:
|
||||
>> >> last | grep tuckerm | head -5 > logins.list >> |
last
command and will only display out any lines
which contain the text "tuckerm". Piping the data into
head
with the "-5" option will limit the
output to only the first five lines. The final
output in this command will not go to the screen but will be
redirected to the file names "logins.list".