Unix basic tutorial pdf


















Unix operating system is one of the most used and secure operating system which is using in development and deployment of lot of applications. Because of the Security of the UNIX operating system this is used in 90 percent of applications as a server operating system. Unix is Multi-user and Multitasking operating system which is used mainly as server in most of the applications. In this article i will give you the brief description of common unix commands which will useful to begin study of the unix.

These Common Unix Commands are most commonly used commands which are related to date ,time ,username of logged in users,how to display calendar, host-name. This command is most Basic Unix Commands which is used for displaying the log in name of user. The user can be able to log in for multiple users.

So that there is need to display the login name. So to display login name the command is useful. When you save the file, emacs writes the contents of the buffer to the disk. Because the buffer exists in RAM memory, it disappears if the power is turned off, or if the system crashes.

Thus, you should use the save command often, flushing your current buffer to disk. Once the file is on disk, a power outage or system crash shouldn't harm it. Basic operations in emacs Here are some of the fundamental things you'll need to do when you edit a document in emacs. To start emacs, just type the command emacs to the Unix shell. If you want emacs to start with a file already loaded into a buffer, type emacs filename where "filename" is the name of the file you want to edit.

If you have made changes to the buffer since the last time you saved it to disk, emacs will ask you if you want to save. Type y for yes, or n for no. Emacs has an on-line help system that can be invoked by typing Control-H. If you type the question mark? The emacs display The display in emacs is divided into three basic areas. The top area is called the text window.

The text window takes up most of the screen, and is where the document being edited appears. At the bottom of the text window, there is a single mode line.

The mode line gives information about the document, and about the emacs session. The bottom line of the emacs display is called the mini buffer. The mini buffer holds space for commands that you give to emacs, and displays status information. Emacs will ask you for the name of the file. As you type the name of the file, it will be displayed in the mini buffer. When you have entered the file name, press the return key, and emacs will load the file into a buffer, and display it in the text window.

The command to save the contents of the buffer to a disk file is Control-X-Control-S. The save command overwrites the old version of the file. You may also write the contents of the buffer to a different file with the command Control-X-Control-W. Emacs will prompt you for the name of the file you want to create. To create a new file, use Control-X-Control-F, just as if the file already existed.

When emacs asks you for the file name, type in the name you want your new file to have, and emacs will create the file, and display an empty buffer for you to type in. Emacs will perform file name completion for you. Type part of the name of the file you want, and press the spacebar or tab key to get emacs to complete a file name. If the partial name you've given matches more than one file, emacs will display a list of all potential matches. You can continue typing in more of the file's name, and pressing either file completion key, until you zero in on the file you want.

Cursor motion On well-configured systems, you will find that the keyboard arrow keys will function correctly in emacs, moving you forward or backward one character at a time, and up or down one line at a time. Inserting and deleting text To insert text into a buffer, place the cursor where you want to start inserting text, and start typing away. If you want to insert the contents of another file into the current buffer, place the cursor at the desired insertion point, and type Control-X-I.

Emacs will ask you for the name of the file you wish to insert. You may also insert text by cutting it from one place, and pasting it at the insertion point. See the next section for information on cutting and pasting. Deleting text is easy. As you'd expect, the delete key deletes backward one character. Cutting and pasting text regions Emacs allows you to select a region of text, and perform cut and paste operations on the region. It uses a temporary storage area called the "kill buffer" to allow you to store and retrieve blocks of text.

There is only one kill buffer in emacs, which means that you can cut text from one document, and paste it into another. To define a region of text, place the cursor at one end of the region and press Control-spacebar. That sets the mark. Then, move the cursor to the other end of the region.

The text between the mark and the cursor defines the region. To cut a region of text, and place it in the kill buffer, use the command Control-W think of Wipe. The paste command is Control-Y. It Yanks the block of text from the kill buffer, and places it where the cursor rests. The Control-Y command only retrieves the most recently-cut block of text. You may copy a region of text into the kill buffer without cutting it.

Define the text block by setting the mark at one end, and moving the cursor to the other end. That's Control-underscore. On some keyboards, you'll have to hold down both the control and shift keys to enter the underscore character. Customizing Emacs The emacs editor is customizable in several ways. You can set up your own key bindings, create your own macros, and even create your own custom functions. Also, some aspects of the behavior of emacs is controlled by variables that you can set.

You can learn more about emacs functions by invoking the online help facility by typing ESC-X help and then typing the "f" key to list functions.

Pressing the space bar for completion will cause emacs to list all the built-in functions. A list of variables can be similarly obtained by invoking the online help, then typing "v" then the spacebar. If you place variable settings, key bindings, and function declarations, in a text file called ". Here is an emacs configuration file with some basic variable definitions and key bindings for you to peruse. The Unix shell maintains a set of environment variables that are used to provide information, like the current working directory, and the type of terminal being used, to the programs you run.

The environment variables are passed to all programs that are not built in to the shell, and may be consulted, or modified, by the program. By convention, environment variables are given in upper case letters. The creation of the execution environment When you log in, a sequence of events establishes the execution environment. The exact sequence of events depends on the particular flavor of Unix, and also depends upon the default shell for your account.

The following is a description of the login process for the HP-UX operating system. Other operating systems may differ. The getty process The getty process provides the login: prompt that you see on the terminal screen. The getty process reads your username, and invokes the login program.

The login program The login program receives the username from getty, and prompts you for your password. That prevents someone from finding valid usernames by trial and error.

Login turns off terminal echo so that your password is not displayed on the screen. Shell startup: System login scripts When the shell program starts, it reads configuration files called login scripts to configure the execution environment.

After the system login scripts are read, the shell looks for user-specified login scripts. Shell startup: User login scripts After the system login scripts are read, the shell reads user login scripts. User login scripts are kept in one's home directory, and are the means by which one can customize the shell environment.

Sh and ksh look for a file called. Ksh also reads a file defined in the environment variable ENV. Csh reads a file called. Important environment variables Here are descriptions of some of the most important environment variables, and examples of how some variables can affect the execution of commands.

Most Unix systems have a database of terminal types, and the capabilities of each terminal type. When you issue a command to the shell, the shell searches sequentially through each directory in the PATH list until it finds an executable program with the command name you typed. Any time you access a file or directory, the access permissions are checked against the value of USER. When you issue the cd command with no directory argument, you will be placed in the directory defined in the HOME environment variable.

The HOME variable is also where the shell will look for the user login scripts. When you start a mail program, the program will look in the directory stored in the MAIL environment variable for your incoming mail messages. One example is the elm program, which is used to read and send electronic mail.

If you elect to compose a new mail message while in elm, the elm program will check the contents of the EDITOR variable to determine which editor to invoke. When you connect to a remote host through telnet or ftp, the name of your host is relayed to the remote machine, so the administrators of the remote machine can keep track of who is connecting, and from where.

Setting environment and shell variables The exact mechanism for setting the environment and shell variables depends upon the type of shell you're using. Do not put spaces on either side of the equals sign. The export command instructs the shell to propagate the value of the variable to all programs that are run by the shell. If an environment variable is reset, but not exported, the change will only apply to the shell itself. Unsetting an environment variable removes the definition of the variable.

Section Customizing the Unix Shell The Unix shell is a actually a user program that the kernel runs for you when you log in. There is usually more than one shell available on most Unix systems. Choosing your shell It is possible to invoke any available shell from within another shell.

To start a new shell, you can simply type the name of the shell you want to run, ksh, csh, or sh. It is also possible to set the default startup shell for all your future sessions. To change your default shell, use the chsh command The chsh command requires one argument, the name of the shell you want as your default. Default file access permissions Whenever you create a file or directory in a Unix filesystem, the newly created file or directory is stamped with a default set of permissions.

That default set of permissions is stored in a variable called the umask. You can change the value of umask to suit your preferences. To see the current value of the umask variable, enter the shell command: umask The umask is stored as an octal base 8 number, that defines which permissions to deny. As you recall, three kinds of file permissions read, write, and execute are given for each of three classes of users owner, group, and others.

Each of the nine permissions is specified as a zero allow access , or a one deny access. To set your umask to deny write permission to group and others, use the command umask To deny all access to group and others, use the command umask Some versions of Unix provide a more user-friendly way of specifying your umask. In HP-UX sh-posix or ksh , you are allowed to specify the access permissions in manner of the chmod command.

The HP-UX posix shell also allows the use of the command umask -S to print your umask setting in a more readable fashion. Customizing with user login scripts The remainder of this section describes some of the ways you can initialize ksh, by presenting the default user login scripts provided to users of ISU's CWIS machine. The scripts have been annotated with descriptions of the purpose of each set of commands. All logins are logged elsewhere, anyway.

Replace 'vt' with another term type if you want a different default terminal type presented with the user prompt. Replace 'vt' with any desired terminal type. Use this option only if you are always using the same type of terminal, and if the system doesn't seem to properly detect your terminal type. Otherwise, the default terminal handling for terminal access is to have the system attempt to detect your terminal type. Changing this can potentially mess up the security of your account, so make sure you know what you're doing before changing this.

If you want an editor other than pico like vi or emacs to be your default editor, replace pico with the name of your preferred editor. The line with PAGER determines the default pager to use for reading through documents one page at a time. The line with LESS makes it so informative keystroke prompts are put at the bottom of the screen when using the less pager. This line is changed by the 'printers' program, so try not to radically alter this line.

You can manually change the queue name here if you want to. Don't mess with this unless you're a guru. Change this line to 'mesg y' if you want to be open to talk requests by default. Otherwise, you can type 'mesg y' within a session to temporarily open yourself for talk requests. If you prefer, you can replace 'vi' with 'emacs' for emacs-style command line editing i. This can be changed to anything. Feel free to create your own custom commands.

The command 'printers' is necessary for the proper functioning of the cwis printer-choosing utility. The 'printers' program changes the line that sets default printer queue in this file, and this file gets "run" again to load the new value into the user environment. The command 'more' is altered to call the more capable 'less' pager. Disable this alias if you want to use the 'more' pager.

Remove this alias if you want the ls command to behave normally, i. The command 'oldmenu' brings up the old cwis menus. The command 'logout' calls the Unix command 'exit' to log out. The command 'webperms' sets up file permissions to be world-readable, for web publishing.

The command 'regperms' returns file permissions to readable by user only. Section Interactive Use of the Shell This section discusses tips and tricks to make your use of the shell more efficient. File name completion Both ksh and csh will perform file name completion for you. The shell will then complete the name of the file for you. If no file exists that begins with the characters you typed, the shell will beep at you, and will not complete the name.

If more than one file begins with the characters you typed, the shell will complete the name up to the point where the names differ. Command name aliasing Both csh and ksh provide command name aliasing, to allow you to rename commands. Aliasing can save a lot of keystrokes if you must frequently issue the same lengthy command. The alias command requires two pieces of information: The command you wish to alias, and the alias you wish to use to refer to it.

The same command could be accomplished in the C shell with the syntax: alias hi history EXERCISE: Create an alias in the Korn shell called "clean" that would remove any files from your home directory that have the extension.

Command aliasing can be tricky. Surround the alias string with single quotes ' to prevent the shell from interpreting special characters. EXAMPLE: This example, written for the C shell, creates an alias for the cd command, so that it stores the current location in a shell variable called old before it changes to the new location. The aliasOnly. The second part uses history substitution and chdir to change the current location.

The use of chdir prevents an "aliasing loop," where the cd command calls itself. The third part executes the pwd command to print the new location on the screen. The alias for back also has three parts: The first part reads the previous location from the shell variable old, and stores it in a shell variable called foo.

That is necessary because the new cd alias will change the value of old when we call it in the second part of the back alias. The third part cleans up our mess by unsetting the variable foo, removing it from the environment. You can remove an alias using the unalias command. To remove the "clean" alias you created in a previous exercise, enter the command: unalias clean. Command history substitution The C shell and Korn shell will keep an ordered list of the commands you have issued, and allow you to retrieve commands from the list.

That facility, called command history substitution, makes it possible to reuse all or part of your previously issued commands. Each command on the list is given a command number, according to the order it was issued. You can view the command history list by issuing the command: history The exact mechanism of retrieving commands from the command history list depends on the shell you're using, and how you have customized your shell.

By default, the history size is set to lines. The shell command "set -o" is used to specify the editing mode for the command line, either emacs or vi. Since an earlier section of this workshop dealt with emacs, we will confine our discussion to the emacs editing style. To use the emacs editing mode, enter the command set -o emacs In emacs editing mode, recall previous commands with the emacs command for "previous line," or Control-P. Repeated use of Control-P will recall earlier commands.

You can also use the emacs command for "next line," or Control-N, to go forward through your command history, toward more recently-issued commands. You can only use Control-N after you have used Control-P at least once.

In the C shell, the history shell variable is used to specify the number of lines the shell will remember. To recall previous commands from the history list, the C shell uses the exclamation point!

Here are some examples of how to use history substitution in the C shell: Recall the last command:!! Recall the third most recent command:! The colon character is used to select specific words from a command. Each word in the command is referred to by position. The command name itself is item number zero. Here are some examples: Recall the third word from the last command:!

Editing the command line The Korn shell ksh provides the ability to edit the command history list almost as if your were in an editor program like vi, or emacs. The current command is always the last line in the history list, and begins blank.

You can type in a new command, or recall an earlier command from the list. You can also modify the text on the current line using basic text editor commands. The mechanism for setting the editor style in ksh is the "set -o" command. To edit in emacs mode, issue the command: set -o emacs Manipulating command line text in emacs mode is done in much the same way as text editing with emacs. When you finish editing the command line, press the return key to issue the command to the shell.

You might want to go back and refresh your memory on emacs by reviewing section ten of this tutorial, titled "Text Editing with Emacs. A disk drive is a device that can store information by making electrical imprints on a magnetic surface. One or more heads skim close to the spinning magnetic plate, and can detect, or change, the magnetic state of a given spot on the disk. The drives use disk controllers to position the head at the correct place at the correct time to read from, or write to, the magnetic surface of the plate.

It is often possible to partition a single disk drive into more than one logical storage area. This section describes how the Unix operating system deals with a raw storage device like a disk drive, and how it manages to make organized use of the space. How the Unix file system works Every item in a Unix file system can be defined as belonging to one of four possible types: Ordinary files Ordinary files can contain text, data, or program information.

An ordinary file cannot contain another file, or directory. An ordinary file can be thought of as a one-dimensional array of bytes. Directories In a previous section, we described directories as containers that can hold files, and other directories. A directory is actually implemented as a file that has one line for each item contained within the directory. Each line in a directory file contains only the name of the item, and a numerical reference to the location of the item.

The reference is called an i-number, and is an index to a table known as the i-list. The i-list is a complete list of all the storage space available to the file system. Special files can be either character special files, that deal with streams of characters, or block special files, that operate on larger blocks of data. Typical block sizes are bytes, bytes, and bytes. Links A link is a pointer to another file. Remember that a directory is nothing more than a list of the names and i-numbers of files.

A directory entry can be a hard link, in which the i-number points directly to another file. A hard link to a file is indistinguishable from the file itself. When a hard link is made, then the i-numbers of two different directory file entries point to the same inode.

For that reason, hard links cannot span across file systems. A soft link or symbolic link provides an indirect pointer to a file. A soft link is implemented as a directory file entry containing a pathname.

Soft links are distinguishable from files, and can span across file systems. Not all versions of Unix support soft links. The I-List When we speak of a Unix file system, we are actually referring to an area of physical memory represented by a single i-list. A Unix machine may be connected to several file systems, each with its own i-list.

One of those i-lists points to a special storage area, known as the root file system. The root file system contains the files for the operating system itself, and must be available at all times. Other file systems are removable. Removable file systems can be attached, or mounted, to the root file system. Typically, an empty directory is created on the root file system as a mount point, and a removable file system is attached there.

When you issue a cd command to access the files and directories of a mounted removable file system, your file operations will be controlled through the i-list of the removable file system.

The purpose of the i-list is to provide the operating system with a map into the memory of some physical storage device. The map is continually being revised, as the files are created and removed, and as they shrink and grow in size. Thus, the mechanism of mapping must be very flexible to accommodate drastic changes in the number and size of files.

The i-list is stored in a known location, on the same memory storage device that it maps. Each entry in an i-list is called an i-node. An i-node is a complex structure that provides the necessary flexibility to track the changing file system. The i-nodes contain the information necessary to get information from the storage device, which typically communicates in fixed-size disk blocks.

An i-node contains 10 direct pointers, which point to disk blocks on the storage device. In addition, each i-node also contains one indirect pointer, one double indirect pointer, and one triple indirect pointer. The indirect pointer points to a block of direct pointers. The double indirect pointer points to a block of indirect pointers, and the triple indirect pointer points to a block of double indirect pointers. By structuring the pointers in a geometric fashion, a single i-node can represent a very large file.

It now makes a little more sense to view a Unix directory as a list of i-numbers, each i-number referencing a specific i-node on a specific i-list.

The operating system traces its way through a file path by following the i-nodes until it reaches the direct pointers that contain the actual location of the file on the storage device.

The file system table Each file system that is mounted on a Unix machine is accessed through its own block special file. It includes information about the name of the device, the directory name under which it will be mounted, and the read and write privileges for the device.

It is possible to mount a file system as "read-only," to prevent users from changing anything. File system quotas Although not originally part of the Unix filesystem, quotas quickly became a widely-used tool. Quotas allow the system administrator to place limits on the amount of space the users can allocate. Quotas usually place restrictions on the amount of space, and the number of files, that a user can take. The command quota will let you know if you're over your soft limit.

Adding the -v option will provide statistics about your disk usage. File system related commands Here are some commands related to file system usage, and other topics discussed in this section: bdf On HP-UX systems, reports file system usage statistics df On HP-UX systems, reports on free disk blocks, and i-nodes du Summarizes disk usage in a specified directory hierarchy ln Creates a hard link default , or a soft link with -s option mount, umount Attaches, or detaches, a file system super user only mkfs Constructs a new file system super user only fsck Evaluates the integrity of a file system super user only.

A brief tour of the Unix filesystem The actual locations and names of certain system configuration files will differ under different implementations of Unix. Other places to look for useful stuff If you get an account on an unfamiliar Unix system, take a tour of the directories listed above, and familiarize yourself with their contents. A good systems administrator will ensure that manual pages are provided for the utilities installed on the system.

Open navigation menu. Close suggestions Search Search. User Settings. Skip carousel. Carousel Previous. Carousel Next. What is Scribd? Explore Ebooks. Bestsellers Editors' Picks All Ebooks. Explore Audiobooks. Bestsellers Editors' Picks All audiobooks. Explore Magazines. Editors' Picks All magazines. Explore Podcasts All podcasts. Difficulty Beginner Intermediate Advanced. Explore Documents. Uploaded by sk. Did you find this document useful? Is this content inappropriate?

Report this Document. Flag for inappropriate content. Download now. Related titles. Carousel Previous Carousel Next. Jump to Page. Search inside document. A broad description of the UNIX operating system.

Files and Directories Storing and manipulating files. Pipelines and Filters Creating processing pipelines. Processes and Multitasking Managing processes. Interaction and Job Control More on managing processes. Text Editing with Emacs Creating and editing text files with the emacs editor. The Execution Environment The environment under which shell commands and programs run. Interactive Use of the Shell Tips and tricks to enhance your efficiency with the command line interface.

Starting emacs To start emacs, just type the command emacs to the Unix shell. Getting help Emacs has an on-line help system that can be invoked by typing Control-H.

Aborting a command You can abort an emacs control or escape sequence by typing the command Control-G. To remove the "clean" alias you created in a previous exercise, enter the command: unalias clean Command history substitution The C shell and Korn shell will keep an ordered list of the commands you have issued, and allow you to retrieve commands from the list. File system related commands Here are some commands related to file system usage, and other topics discussed in this section: bdf On HP-UX systems, reports file system usage statistics df On HP-UX systems, reports on free disk blocks, and i-nodes du Summarizes disk usage in a specified directory hierarchy ln Creates a hard link default , or a soft link with -s option mount, umount Attaches, or detaches, a file system super user only mkfs Constructs a new file system super user only fsck Evaluates the integrity of a file system super user only A brief tour of the Unix filesystem The actual locations and names of certain system configuration files will differ under different implementations of Unix.

Tjabring van Egten. Juan Alas Ronaldo Aziong. Nami Patni. Ambar Majumdar. Amos Bwire. SaiKrishna Boyapally. Manoj BE. Akram Fahad. Lucas lopez. Justine Garcia. Hendrick T Hlungwani.

Mohammad Saqib. Ravi Varma D V S. More From sk. Popular in Graphics Software. Walid Mostapha Shbaklo. Marvin Zapata. Daniel Moore. Dayal R Kundani. Relu Chiru. Yoshio Castelan. Sheetal kumar. Sandunika Devasinghe. Daniel Baron.



0コメント

  • 1000 / 1000