Miscellaneous

  Home arrow Miscellaneous arrow Page 4 - The Terminal in UNIX
MISCELLANEOUS

The Terminal in UNIX
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2009-03-11

    Table of Contents:
  • The Terminal in UNIX
  • Speed it up
  • A work session
  • Basic concepts for working with the shell

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    The Terminal in UNIX - Basic concepts for working with the shell


    (Page 4 of 4 )

    Once we start the terminal or login, if we have no graphical interface, the system will start the shell for us. This, on its own, will do a couple of tasks. The shell reads in some configuration-related files and applies them. I will talk about this during a future article. The shell will also print out the prompt string. This is made up by default of the name of the computer and the user or the current working directory.

    Like everything else around here, this can also be changed if you wish. After this, the shell will print out the prompter character. This is by default $ or >. Now it will await a command line from us. It will continue to do so until we enter the exit command or send the end of file signal (^D).

    Inside the shell, there are variables. The settings during run time are preserved in a couple of these. These are pairs of name and values. A few of them are automatically created by the shell and are all upper case. You can of course create new variables as well.

    One of these variables is PS1. To this variable is assigned how the prompter string should look. Now I will present to you the most useful and smartest command inside UNIX. This is the echo. The echo will print back whatever you write after it. So if you write in

    echo alfa beta omega

    You will get back as an echo on the terminal:

    alfa beta omega

    We can refer to terminal variables using the $ character. If we put the $ character ahead of a string, the terminal will try to find it between the already-existing ones, and will replace it with its value. If the variable is not yet made, will create it and assign to it an empty string. The following line will print the current settings for the prompter string.

    echo $PS1

    Notice that you did not get back the $PS1 you would have accepted. Of course, you can still force the shell to ignore the $ sign and print back the $PS1 if you specify it as a string line by enclosing it within single quotes (''). Therefore, echo ‘$PS1’ will print back the $PS1 string.

    Assigning variables in the shell obeys the following syntax:

    [variable name]=[value]

     

    Let us change the prompter string to a simple -> string. We will act as follows:

     

    PS1=”->”

     

    The “ quotes will also determinate a string, it's just that within this, the shell will make its variable/value change. Now that we have assigned to the PS1 the -> string, that is what we will have on our terminal from now on as the prompter string.

    The syntax of commands looks as follows:

     

    [command name] [options] [arguments]

    If there are multiple options or arguments, they will be separated with spaces. Let's try it out with the ls command. This command prints the content of a directory.

    If you use it simple with no extra options, it will just print a list of files. If we add the –l option (these are also called switches), it will print detailed information. By default, it will color the files based on their traits; we can also turn this off. Add the –t option and it will sort based on the time of file creation. The comment character in the shell is the #.

     

    #print default

    ls

     

    #print long list

    ls –l

     

    #print long list with sort by date of creation

    ls –lt

     

    #or

    ls –l –t

     

    #print with no color, use extended option

    ls –color=no

     

    #print in column

    ls -1

     

    #print a long list about the content of the /media folder

    ls –l /media

    Options can be written together or separate, as the third and fourth example demonstrated. In the last example, you can see if we add a folder argument, it will print the content of that folder instead of the current working directory. Other interesting commands you may play around with are who (who is currently working on the system), whoami (my current user name), last (when and for how long a specific user was on the system).

    When the operating system starts a command, in fact, it runs an application. The running program together with the information it carries is called process. The terminal itself is a process.

    Simplifying all of this, the following happens when you push down the enter key to carry out a command: the shell will start a process in which the command will get its result, and while this happens, the terminal will wait for that to finish. Until it achieves this, we will not get the prompter character back, and we need to wait for that to complete. Nevertheless, if the running process prints something on the screen, it will appear inside the terminal this time.

    Once the process finishes, we get the prompter character back and we can continue our work. This is of course a simplified version of what really happens; a more detailed description is the subject of a future article. For today, this will be all. Play around with the commands you learned and make sure you understand them. I invite you to rate my article as you wish. If you have any questions, feel free to express them within the blog commenting system. Live With Passion!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap