Skip to main content

Posts

Showing posts from November, 2013

Process and Job control in Linux/Unix

 Processes and Jobs A process is an executing program identified by a unique PID (process identifier). To see information about your processes, with their associated PID and status, type % ps A process may be in the foreground, in the background, or be suspended. In general the shell does not return the UNIX prompt until the current process has finished executing. Some processes take a long time to run and hold up the terminal. Backgrounding a long process has the effect that the UNIX prompt is returned immediately, and other tasks can be carried out while the original process continues executing. Running background processes To background a process, type an   &   at the end of the command line. For example, the command   sleep   waits a given number of seconds before continuing. Type % sleep 10 This will wait 10 seconds before returning the command prompt %. Until the command prompt is returned, you can do nothing except wait. To run...

File Permissions in Linux and Unix

 File system security (access rights) In your   home   directory, type % ls -l (l for long listing!) You will see that you now get lots of details about the contents of your directory, similar to the example below. Each file (and directory) has associated access rights, which may be found by typing   ls -l . Also,   ls -lg   gives additional information as to which group owns the file (beng95 in the following example): -rwxrw-r-- 1 ee51ab beng95 2450 Sept29 11:52 file1 In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -, and, occasionally, s or S. If d is present, it will be at the left hand end of the string, and indicates a directory: otherwise - will be the starting symbol of the string. The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3. The left group of 3 gives the file permissions for the user that owns the file (or directory) (ee51...

How wildcards work in Linux and Unix

Wildcards The * wildcard The character   *   is called a wildcard, and will match against none or more character(s) in a file (or directory) name. For example, in your   unixstuff directory, type % ls list* This will list all files in the current directory starting with   list.... Try typing % ls *list This will list all files in the current directory ending with   ....list The ? wildcard The character   ?   will match exactly one character. So   ?ouse   will match files like   house   and   mouse , but not   grouse .   Try typing % ls ?list  Filename conventions We should note here that a directory is merely a special type of file. So the rules and conventions for naming files apply also to directories. In naming files, characters with special meanings such as   / * & %   , should be avoided. Also, avoid using spaces within names. The safest way to name a f...

Redirection in Linux and Unix

 Redirection   Most processes initiated by UNIX commands write to the standard output (that is, they write to the terminal screen), and many take their input from the standard input (that is, they read it from the keyboard). There is also the standard error, where processes write their error messages, by default, to the terminal screen. We have already seen one use of the   cat   command to write the contents of a file to the screen. Now type   cat   without specifying a file to read % cat Then type a few words on the keyboard and press the [ Return ] key. Finally hold the [ Ctrl ] key down and press [ d ] (written as   ^D   for short) to end the input. What has happened? If you run the   cat   command without specifing a file to read, it reads the standard input (the keyboard), and on receiving the 'end of file' ( ^D ), copies it to the standard output (the screen). In UNIX, we can redirect both the input and the ...

Unix/Linux Variables

 UNIX Variables Variables are a way of passing information from the shell to programs when you run them. Programs look "in the environment" for particular variables and if they are found will use the values stored. Some are set by the system, others by you, yet others by the shell, or any program that loads another program. Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower case names.  Environment Variables An example of an environment variable is the OSTYPE variable. The value of this is the current operating system you are using. Type % echo $OSTYPE More examples of environme...