text
stringlengths
0
33k
UNIX allows you to set the permissions on files that you own. The command to change the file permission mode is chmod. Chmod requires you to specify the new permissions you want, and specify the file or directory you want the changes applied to.
To set file permissions, you may use to the "rwx" notation to specify the type of permissions, and the "ugo" notation to specify those the permissions apply to.
To define the kind of change you want to make to the permissions, use the plus sign (+) to add a permission, the minus sign (-) to remove a permission, and the equal sign (=) to set a permission directly.
EXAMPLE: Type the command
chmod g=rw- ~/.shrc
to change the file permissions on the file .shrc, in your home directory. Specifically, you are specifying group read access and write access, with no execute access.
EXERCISE: Change the permissions on the .shrc file in your home directory so that group and others have read permission only.
EXPLANATION: Typing the command
chmod go=r-- ~/.shrc
would accomplish the task.
<|endoftext|>
Changing Directories
In UNIX, your location in the filesystem heirarchy is known as your "current working directory." When you log in, you are automatically placed in your "home directory." To see where you are, type the command
pwd
which stands for "print working directory."
To change your location in the filesystem heirarchy, use the cd (change directory) command, followed by an argument defining where you want to go. The argument can be either an absolute path to the destination, or a relative path.
EXAMPLE: Type the command
cd /tmp
to go to the /tmp directory. You can type
pwd
to confirm that you're actually there.
If you type the cd command without an argument, the shell will place you in your home directory.
EXERCISE: Type the command
pwd
and note the result. Then type
cd ..
to the shell. Type
pwd
again to see where you ended up.
EXPLANATION: The "cd .." command should have moved you up one level in the directory tree, because ".." is UNIX shorthand for the parent directory. The result of the second "pwd" command should be the same as the first, with the last directory in the path omitted.
Listing the contents of a directory
The ls command allows you to see the contents of a directory, and to view basic information (like size, ownership, and access permissions) about files and directories. The ls command has numerous options, so see the manual page on ls (type man ls) for a complete listing. The ls command also accepts one or more arguments. The arguments can be directories, or files.
EXAMPLE: Type the command
ls -lr /etc/i*
to the UNIX shell.
In the example, the "l" and "r" options of the ls command are invoked together. Some commands permit you to group options in that way, and some commands require the options to be named separately, e.g., ls -l -r. The l option calls for a long output, and the r option causes ls to operate recursively, moving down directory trees.
The last part of the example, "/etc/i*", directs the ls command to list files and directories in the /etc directory, that
begin with the letter i. The wildcard character, "*", matches any character(s).
EXERCISE: Type the command
ls -m /etc/i*g
to the shell. How did the shell respond, and why?
EXPLANATION: The shell responded by printing all the entries in the /etc directory that start with the letter i, and end with the letter g. The -m option causes the output to be streamed into a single line. See the manual page for ls to get a complete description of the ls command's options.
EXERCISE: Find the permissions on your home directory.
EXPLANATION: There are many ways to accomplish this. You could type
cd
to get to your home directory, and then type
ls -la
The -a option instructs the ls command to list all files, including those that start with the period character. The directory permissions are listed next to the "." symbol. Remember that "." is UNIX shorthand for the current working directory.
Viewing the contents of a file
CONCEPT: Text files are intended for direct viewing, and other files are intended for computer interpretation.