jueves, 26 de septiembre de 2013

LInux File Permissions

First digit in the above mode number is used to set setuid, setgid, or sticky bit. Each remain digit set permission for the owner, group, and world as follows:

    4 = r (Read)
    2 = w (Write)
    1 = x (eXecute)

So you end up creating the triplets for your user by adding above digits. For e.g.

    To represent rwx triplet use 4+2+1=7
    To represent rw- triplet use 4+2+0=6
    To represent r-- triplet use 4+0+0=4
    To represent r-x triplet use 4+0+1=5

To only give full permission to user, use it as follows:
chmod 0700 file.txt

    0 - Use set setuid, setgid, or sticky bit
    7 - Full permission for owner (rwx = 4+2+1=7)
    0 - Remove group permission (--- = 0+0+0=0)
    0 - Remove world permission (--- = 0+0+0=0)



http://www.cyberciti.biz/faq/unix-bsd-linux-setuid-file/

martes, 24 de septiembre de 2013

Standard Input, Output, And Error

1. Standard Output

To redirect standard output to another file besides the screen, we use the “>” redirection operator followed by
the name of the file.

[me@linuxbox ~]$ ls -l /usr/bin > ls-output.txt


2. Standard error

The answer is that the ls program does not send its error messages to standard output. Instead, like most well-written Unix programs, it sends its error messages to standard error.


[me@linuxbox ~]$ ls -l /bin/usr > ls-output.txt
ls: cannot access /bin/usr: No such file or directory

We received an error message. This makes sense since we specified the non-existent directory /bin/usr, but why was the error message displayed on the screen rather than being redirected to the file ls-output.txt? The answer is that the ls program does not send its error messages to standard output. Instead, like most well-written Unix
programs, it sends its error messages to standard error. Since we only redirected standard output and not standard error, the error message was still sent to the screen.


Redirecting Standard Error

Redirecting standard error lacks the ease of a dedicated redirection operator. To redirect standard error we must refer to its file descriptor. A program can produce output on any of several numbered file streams. While we have referred to the first three of these file streams as standard input, output and error, the shell references them internally as file descriptors zero, one and two, respectively. The shell provides a notation for redirecting files using the file descriptor number. Since standard error is the same as file descriptor
number two, we can redirect standard error with this notation:

[me@linuxbox ~]$ ls -l /bin/usr 2> ls-error.txt

The file descriptor “2” is placed immediately before the redirection operator to perform the redirection of standard error to the file ls-error.txt.

Redirecting Standard Output And Standard Error To One File

There are cases in which we may wish to capture all of the output of a command to a single file. To do this, we must redirect both standard output and standard error at the same time. There are two ways to do this. First, the traditional way, which works with old versions of the shell:

[me@linuxbox ~]$ ls -l /bin/usr > ls-output.txt 2>&1

Using this method, we perform two redirections. First we redirect standard output to the file ls-output.txt and then we redirect file descriptor two (standard error) to file descriptor one (standard output) using the notation 2>&1.