In UNIX you can direct the output of a command to either a file, or
another command. Huh? That's right.
So, lets start with some data we can play with:
mkdir -p ~/LL/lesson2 <- the
"~" is the same as "/home/<username>"
cd ~/LL/lesson2
cd lesson2
wget http://biff.freeshell.org/learnlinux/examples/lesson2.txt
<- downloads lesson2.txt to the current working directory
so, some basics:
1- cat lesson2.txt
reads lesson2.txt and prints each line to the screen
2- cat lesson2.txt > outfile
Reads each line of lesson2.txt and writes it into the file output
instead of to the screen
2- echo "this is a test"
>> output
The ">>" operator means append. If you look at the
bottom of the file output, you'll now see "this is a test"
3- echo "this is another
test" > output
You'll notice that you've replaced the contents of the output file with
just "this is another test". The ">" operator deletes
the file if one exists, and simply creates a new file.
So, lets learn the sort command:
cd ~/LL/lesson2
wget http://biff.freeshell.org/learnlinux/examples/list.txt
cat list.txt
Let me give you a few examples:
1- sort list.txt
puts list.txt order
2- sort < list.txt
redirects the input of list.txt to the sort command
(it looks the same as the above command)
3- sort <list.txt > outlist.txt
this directs the input of list.txt to the sort
command, and then directs the output to the outlist.txt file
4- sort < /etc/passwd
puts the /etc/passwd file in order
read: http://www.ee.surrey.ac.uk/Teaching/Unix/unix3.html
and
http://www.ee.surrey.ac.uk/Teaching/Unix/unix4.html
ASSINGMENT:
1- the
last command shows you who has been logged into the system, sort in order the
users that have logged in.
2- tell
me how to ignore case for the sort command
3- tell
me how to reverse the output of the sort command
4- show
me how you would list the files of the /etc/ directory in alphabetical order
5- show
me how you would list the files of the /etc/ directory in reverse alphabetical
order