16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Introduction to <strong>Unix</strong><br />

It works in <strong>the</strong> opposite way to "chmod". The mask specifies which permissions should NOT be given when a file<br />

is created.<br />

Examples:<br />

$ umask 000 set no masked bits<br />

$ date> myfile1 creates "myfile1"<br />

$ ls -1 myfile1 show file permissions<br />

-rw-rw-rw- 1 fred student 15 Jun 21:45 myfile1<br />

$ umask 026 set umask bits<br />

$ date> myfile2 creates "myfile2"<br />

$ ls -1 myfile2 show file permissions<br />

-rw-r----- 1 fred student 15 Jun 21:46 myfile2<br />

$ mkdir mydir creates a directory<br />

$ ls -ld mydir<br />

drwxr-x--x 1 fred student 15 Jun 21:46 mydir<br />

I/O Redirection<br />

Standard Input<br />

(stdin)<br />

TTY<br />

command<br />

process<br />

Standard Output<br />

(stdout)<br />

TTY<br />

TTY<br />

(stderr)<br />

Standard Error<br />

where: TTY = terminal display (output) or keyboard (input)<br />

command > output-file<br />

To redirect <strong>the</strong> output from "ls -l" into <strong>the</strong> a file:<br />

ls -l > mylsfile<br />

">" redirects stdout to be output to a file. Note that errors still output to terminal.<br />

command ">>" output-file<br />

">>" appends stdout to <strong>the</strong> end of <strong>the</strong> output-file<br />

ls -l >> mylsfile<br />

If <strong>the</strong> output file already exists <strong>the</strong>n ">" will overwrite it, whereas ">>" will append to <strong>the</strong> end of it. If <strong>the</strong><br />

output file does not exist <strong>the</strong>n both ">" and ">>" will create a new file.<br />

command < input-file<br />

The command "wc" counts <strong>the</strong> number of lines, words and characters which it read from stdin.<br />

wc < mylsfile<br />

...<strong>the</strong> output to TTY may look like:<br />

17 131 1236<br />

"

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!