Some commands allowing a user to manipulate files are:
File name completion is supported under csh and tcsh (turn it on by issuing the command ``set filec.'' In csh, use the ESCAPE key; in tcsh, use the TAB key.
UNIX also supports ``wildcards.'' A ``?'' will be replaced by any matching single character, while a ``*'' will be replaced by any number of matching characters. For example, ls abc*.c will list all files whose name starts with ``abc'' and ends in ``.c''.
To gain access to a UNIX system, a user must first identify his/her account in response to the login prompt,
Login: username Password: passwordthen give a unique password. A user can change his/her password by issuing the command passwd, followed by the old and new passwords.
The user can exit the system with the command logout . On login, UNIX starts up a new shell interpreter (e.g. the C-shell interpreter csh, or bash), and sets up the computing environment for the user by scanning the ``hidden'' (i.e. not normally listed by ls) set-up files, .login and .cshrc (.orifile and .bashrc in bash). The .cshrc file is also scanned each time a new ``task'' (e.g. a new window) is launched. These hidden files are how a user can customize his/her computing environment at will, typically with commands like
alias name definitionin csh, or
alias name=definitionin bash, which defines ``name'' (usually something short) to mean ``definition'' (often long and/or complicated).
Each file is marked for ownership by a user and as belonging to a group of users. Each file is also marked for ``reading'', ``writing'' and ``execute'' permissions by its owner, members of its group and by ``others'' The directory command ``ls -l'' lists these permissions as ``r'', ``w'' and ``x'' if they are allowed. For instance, the following dialog
> ls -l total 6 -rw-rw-r-- 1 steve 4322 Jan 10 12:30 file1 drwxrwxr-x 2 steve 512 Jan 10 12:29 file2 >shows that file1 has can be read and written by the owner and all group members, and read by all, while file2 is unprotected, except that it cannot be written by ``others''. Furthermore, file2 is a directory (name of a sub-directory within the current one -- indicated by a ``d'' in the first column). For a full description of ls and its options, type 'man ls'.
The protections of a file or group of files can be modified using the chmod command. For example, to make all files whose names begin with abc executable by your group and unreadable by others, type
> ls -l abc* -rw-r--r-- 1 steve staff 123 Mar 31 10:38 abc1 -rw-r--r-- 1 steve staff 2331 Mar 31 10:38 abc2 -rw-r--r-- 1 steve staff 2 Mar 31 10:38 abc34 > chmod g+x,o-r abc* > ls -l abc* -rw-r-x--- 1 steve staff 123 Mar 31 10:38 abc1 -rw-r-x--- 1 steve staff 2331 Mar 31 10:38 abc2 -rw-r-x--- 1 steve staff 2 Mar 31 10:38 abc34To change the default file permissions, i.e. the permissions applied to every new file you create, use the umask command:
> umask 022 > touch xyz > ls -l xyz -rw-r--r-- 1 steve staff 0 Mar 31 10:57 xyz > umask 026 > touch pqr > ls -l pqr -rw-r----- 1 steve staff 0 Mar 31 10:58 pqrThe algorithm is a little obscure: take the number following the umask command, subtract it from 666, and the result is the user/group/other permissions, in octal! As a practical matter, 022 gives everyone read permission, 026 denies read access to others (outside your group), and 066 means that noone else can read or execute your files. The umask command is normally placed in your .login or .profile file, so that it is executed every time to log in to the system.
The ownership of a file can be modified by the command chown ; this is a restricted command, however -- it can be executed only by the system ``super-user.''
There are many other commands that facilitate the users' interaction with the computer in small ways; for instance:
Help on any UNIX command can be obtained via the man command. The command ``man cmd'' prints to standard output the content of the manual pages concerning the UNIX command ``cmd''. You can also search by context with man -k cmd .
ls -lFg file
will execute the ``ls'' command, with arguments ``-lFfg'' (a switch) and ``file'', resulting is a very complete directory listing for the file ``file''. The same goes for any executable file that you might create.
#!/bin/csh # # example of a C-shell script # --------------------------- # # store the wordlist resulting from # the ls command in variable files # set files = `ls` # # foreach is a loop; files takes on the # value of each entry in files # # $variable_name is the content of # that variable # foreach file ( $files ) echo 'File name:' $file end
The script explicitly calls for the C-shell interpreter; the ``set'' command transfers the result of the ls command into the variable ``files'' as a wordlist. Then the ``foreach ... end'' loops over the wordlist, assigning each member to the variable ``file''. The command ``echo'' writes a message to standard output. The syntax ``$variable'' means the ``content'' of the variable; $var[i] means the content of the ith position in the variable.
At the script level, the differences between bash and csh become more evident. A bash version of the above script might look like:
#!/bin/bash # # example of a bash script # ------------------------ # # store the wordlist resulting from # the ls command in variable files # files=`ls` # # for is a loop; files takes on the # value of each entry in files # # $variable_name is the content of # that variable # for file in $files; do echo 'File name:' $file done