User Tools

Site Tools


opus:fall2012:dsherbur:unixpart2

Keyword 2 Phase 1

alias

Definition

Definition (in your own words) of the chosen keyword.

Alias: semantics applied to the command shell. An alias is a string substituted for another string. If, for example, you always need to use the -l option to ls, you would be typing ls -l and potentially wasting 3 keystrokes. With the help of alias, we can make a more terse command that accomplishes what you want without typing more than is absolutely necessary.

lab46:~$ alias lsl='ls -l'
lab46:~$ lsl
total 72

Alias can also take pipes, which means you can write very lengthy incantations, and instead of typing the whole thing out or trolling through your history to use it again, you can make an alias and make your life a touch easier.

lab46:~$ alias lsl='ls -l | wc -l'
lab46:~$ lsl
30

Aliasing can be used to customize your commands, as well as to play some cruel pranks. If someone walks away from an open terminal, you could alias one command to something completely different, like alias vim='cd /; cat *', or alias cd='cat /dev/random'.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

Keyword 2 Phase 2: I/O Redirection

Definition

There is no clear definition for I/O redirection but both of these in the UNIX universe in particular are actually two components of our interface that we use at every given moment while actively using the terminal or even this browser. The Input is coming from your computer's keyboard or terminal keyboard while the Output is what you see on the monitor typically, such as in the Lab46 Terminal, the text you see is the output. In the middle of both input and output is actually where all the processing happens, this is key to the redirection as it has an effect to where the output will be directed. There are two kinds of I/O redirection, them being represented by the less than and greater than symbols ><. The less than < symbol is what does input redirection, commonly useful for when a program doesn't read files but reads from standard input, for example, you can have file1 send its contents to a mail of some sort like jackrabbit@rabies.org and the command would look something like this: mail jackrabbit@rabies.org < file1

The greater than > symbol does the “opposite” and is used in a different scenario. Say you wanted all the output you receive from issueing an ls -l command to be put into file2. Just do ls > file2 and all that output will be within the file.

Some other important concepts about I/O redirection is usage of the pipe | and the semicolon ;. The pipe and semi are used when you want to use more than one command at one time, but the difference between the two is crucial to a successful incantation. The pipe will redirect output from the initial command into the next command while the semicolon will not redirect any output into the next command, it will just perform it as if you were doing it singularly. A situation where the semicolon is crucial is if you have a cat command following your initial casting.

Now when you use the output redirect, one thing to keep in mind is that if you send another piece of output into file2 with a single >, it will overwrite the file with that new output and the old output from ls -l will no longer be there.

References

  • O'Reilly Learning The UNIX Operating System

Demonstration

Demonstration of the indicated keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

In my first experiment, I tried to make an incantation that combs the entire filesystem for a search parameter. Its kind of primitive, and most of the output is error text. We can redirect that error text to clean that up a bit (wedge).

opus/fall2012/dsherbur/unixpart2.txt · Last modified: 2012/10/31 17:24 by dsherbur