Unix is a computer Operating System which is capable of handling activities from If you are willing to learn the Unix/Linux basic commands and Shell script but. Unix is an operating system (OS): it manages the way the computer works by . card is located here: portal7.info~dbindner/mirror/portal7.info 5. PDF | On May 5, , Sulieman Bani-Ahmad and others published Introduction to UNIX Operating System Ubuntu–based Lab manual.
|Language:||English, Spanish, Indonesian|
|ePub File Size:||21.44 MB|
|PDF File Size:||16.58 MB|
|Distribution:||Free* [*Sign up for free]|
An operating system (OS) is software that manages the resources of a computer. Like most managers, the OS aims to manage its resources in a safe and. THE UNIX OPERATING SYSTEM. William Stallings. This document is an extract from. Operating Systems: Internals and Design Principles, Fifth Edition. Prentice. It is meant as an introduction for beginners to help them understand concepts behind the UNIX/linux operating system. Intermediate users may.
Created by just a handful of programmers , UNIX was designed to be a small, flexible system used exclusively by programmers. Due to its portability, flexibility, and power, UNIX has become a leading operating system for workstations. Historically, it has been less popular in the personal computer market. This meant that it could be installed on virtually any computer for which a C compiler existed. This natural portability combined with its low price made it a popular choice among universities.
Manufacturer things. Hewlett Packard. Solaris but support supercomputers. Archlinux, Free Operating Microsoft, which Android etc. System OS. OSX is distributed through expensive.
A types including PowerPC Linus 7operating to Windows 8's Torvalds oversees system, but Metro. Linux default shell. PowerShell that uses more Unix- Linux is developed Windows 7is like commands.
Development by Open Source developed and and Distribution development i. The ted, and sold by source defining component Microsoft. Update method Many Windows Update of Linux is the Linux Microsoft kernel, an operating introduced an Multi Terminal -- Terminal system kernel first operating Windows released environment 5.
Windows 7 O. Linux is an open source, free to use language s operating system widely used for computer hardware and software, game development, tablet PCS, mainframes etc. The Unix and Linux are more secure operating System than Windows 7. Bershad and C. Pinkerton, 4. Coulouris, J. Dollimore, and T. Farrow, "Security for Superusers, or How to versions 1. Forrest, S. The lefthand column tells you what will happen. Comments and Questions Please address comments and questions concerning this book to the publisher: You can access this site at: Acknowledgments H.
Milton Peek reviewed the first draft of this edition. Jeff Kawski acted as the technical editor. The account is identified by your user name, which is usually a single word or an abbreviation.
Other users may also be at work on the same system. At many sites, there will be a whole network of Unix computers. So in addition to knowing your username, you may also need to know the hostname name of the computer that has your account. Alternatively, your account may be shared between all computers on the local network, and you may be able to log into any of them.
Working in the Unix Environment Each user communicates with the computer from a terminal. To get into the Unix environment, you first connect to the Unix computer. Your terminal is probably already connected to a computer. In this case, log into your local computer first, then use a remote login command to connect to the remote computer.
On these terminals, start by telling the port contender which computer you want to connect to. Getting Started After connecting your terminal, if needed, you start a session by logging in to your Unix account.
To log in, you need your username and a password. Logging in does two things: They can read private information, corrupt or delete important files, send email messages as if they came from you, and more.
If your computer is connected to a network — the Internet or a local network inside your organization — intruders may also be able to log in without sitting at your keyboard!
Your password is what keeps others from logging in as you. If you suspect that someone is using your account, ask system staff for advice. Unix systems are case sensitive. Most usernames, commands, and filenames use lowercase letters though good passwords use a mixture of lower- and uppercase letters.
Connecting to the Unix Computer If you see a message from the computer that looks something like this: There are just too many possibilities. You may recognize your situation.
You might also find a program named either telnet, eXceed, ssh, VMware, procomm, qmodem, kermit, or minicom, or something relating to remote access. Logging in Nongraphically The process of making yourself known to the computer system and getting to your Unix account is called logging in.
There are generally two ways to log in: Otherwise, to log in nongraphically, enter your username usually your name or initials and your private password. The password does not appear as you enter it. A successful login to the system named nutshell could look like Example Getting Started Example Nongraphical login nutshell login: Last login: Mon Oct 8 SunOS 5.
Tue Oct 9 The last line to appear is the Unix shell prompt. The messages you see at login time differ from system to system and day to day. Shell prompts can also differ. If needed, connect your terminal or terminal window to the Unix system. Type in your username in lowercase letters at the prompt. The system should prompt you to enter your password.
For security, your password is not displayed as you type it: Problem checklist Nothing seemed to happen after I logged in. Wait a minute, since the system may just be slow. If you still get nothing, ask other users if they have the same problem. Otherwise, try logging in again, taking care to enter the username and password correctly. Also make sure to use the exact combination of upper- and lowercase letters your password contains.
If you still fail after trying to log in a few more times, check with the person who created your account to confirm your username and password. You probably entered your username in uppercase letters. Type exit at the shell prompt and log in again. The shell interprets command lines you enter, runs programs you ask for, and generally coordinates what happens between you and the Unix operating system. Common shells include Bourne sh , Korn ksh , and C csh shells, as well as bash and tcsh.
Getting Started For a beginner, differences between shells are slight. If you plan to work a lot with Unix, though, you should learn more about your shell and its special commands. Figure shows an example, but yours may look different; the important thing is that the window have a shell prompt in it. The Shell Prompt When the system is ready to run a command, the shell outputs a pr ompt to tell you that you can enter a command line.
The prompt can be customized, though, so your own shell prompt may be different. Each command line includes the name of a Unix program. Like most things in Unix, program names are case sensitive; if the program name is lowercase and most are , you must type it in lowercase. Some simple command lines have just one word, which is the program name. Entering the command date displays the current date and time: The who program can also tell you who is logged in at your terminal. The command line is who am i.
They can even remember commands from previous login sessions. This handy feature can save you a lot of retyping common commands. If your shell is configured to understand this, you should see the previous command line after your shell prompt, just as you typed it before. Pressing the up-arrow again recalls the previous command line, and so on.
Correcting a Command Line What if you make a mistake in a command line? The shell will give you an error message: This can be caused by typing control characters that are invisible on the screen. Once the prompt returns, reenter your command. They take more time to learn than we can spend here, 7 January The erase character differs from system to system and from account to account, and can be customized.
The most common erase characters are: The key labeled DEL may be used as the interrupt character instead of the erase character. Other common control characters are: CTRL-D Used to signal end-of-input for some programs such as cat and mail, explained in Chapter 1 and Chapter 6 and return you to a shell prompt.
Getting Started Find the erase and interrupt characters for your account and write them here: You should not end a session by just turning off your terminal!
If you logged in graphically, that should end your login session. But, if you logged in nongraphically before you started the window system, closing the window system should take you back to a shell prompt where you originally typed xinit or startx. In that case, use the following steps to finish logging out.
In many cases, the command logout will also work. Otherwise, if you were connected to a remote computer, the shell prompt from your local computer should reappear on your screen. Repeat the process if you want to log out from the local computer.
But, if the power switch for your terminal is the same as the power switch for the whole Unix computer system, do not simply turn off that power switch! Ask a local expert for help with shutting down your Unix system safely. But you may encounter these problems later, as you do more advanced work.
Enter fg to bring each stopped job into the foreground, then quit the program normally. See Chapter 7 for more information. Syntax of Unix Command Lines Unix command lines can be simple, one-word entries such as the date command.
They can also be more complex; you may need to type more than the command or program name. An argument can be an option or a filename. The general format for Unix command lines is: Multiple options in one command line can be set off individually such as —a —b. Some commands, including those on Linux systems, also have options made from complete words or phrases and starting with two dashes, like ——delete or ——confirm—delete. When you enter a command line, you can use this option style, the single-letter options which all start with a single dash , or both.
You can read more precise definitions of these terms and others in Glossary. Getting Started The argument filename is the name of a file that you want to use. Most Unix programs also accept multiple filenames, separated by spaces.
In a few cases, an option has another argument associated with it; type this special argument just after its option. The sort command is an example of this: In the following example, sort reads the file sortme given as an argument , and writes to the file sorted given after the —o option: But —n is a more standard option; it has nothing to do with the final argument sortme on that command line. So, we also could have written the command line this way: If a command needs an option like this, its documentation will say so.
They also can have several separate commands. For instance, you can write two or more commands on the same command line, each separated by a semicolon ;. Commands entered this way are executed one after another by the shell. Unix has a lot of commands!
We cover some useful Unix commands in later chapters. The ls program displays a list of files. You can use it with or without options and arguments. If you enter: But if you enter: You can also get information about a particular file by using its name as the second argument.
For example, to find out about a file called chap1, enter: For instance, ls has the —a all option for listing hidden files. You can use multiple options in either of these ways: Remember that almost all Unix commands are typed in lowercase. Enter date List logged-in users. Enter who Obtain more information about users. Enter who -u or finger or w Find out who is at your terminal.
Enter who am i Enter two commands in the same line. Enter who am i;date Mistype a command. How can you tell it what job you want done? There are three general ways to give commands on a Unix system, three different kinds of programs. Some Unix programs work only with a window system. For instance, when you type netscape at a shell prompt or click a button or choose the command from a menu , the Netscape web browser starts.
It opens one or more windows on your screen. The program has its own way to receive your commands—through menus and buttons on its windows, for instance.
These programs work in a window system from a terminal window or from any terminal. Control those programs from the Unix command line— that is, by typing options and arguments from a shell prompt before you start the program running. Some Unix programs that work in terminals have commands of their own. These programs may accept options and arguments on their command line. Enter Pine commands to handle email messages. When you enter the special command q to quit the pine program, pine will stop prompting you.
A session can hang for several reasons. For instance, the connection between your terminal and the computer can get too busy; your terminal has to wait its turn.
Other users or computers probably share the same connection. In that case, your session starts by itself in a few moments. Try the following steps in the order shown until the system responds: But, before you turn off your terminal, read the notes earlier and later in this chapter about turning off the power. This suspends a program that may be running and gives you another shell prompt. This interrupts a program that may be running. A long-running program may thus appear to hang the terminal.
Chapter 1: Note that some systems will automatically issue CTRL-S if they need to pause output; this character may not have been typed from the keyboard. This key stops the screen display from scrolling upward. Check the physical connection from the terminal to the system. Some programs such as mail expect text from the user.
Otherwise, turn your terminal off, wait ten seconds or so, then turn it on again. This may also log you out, but it may not; your old login session could still be running. On most modern Unix versions, you can also use a window system. A window system is software that lets a single screen handle many sessions at once. The pointer can be used to select and move parts of the screen, copy and paste text, work with menus of commands, and more.
Figure shows a typical screen with windows. This chapter introduces the X Window System, which is called X for short, the most common Unix window system. This introduction should also help you use window systems other than X. See the Glossary for a definition and more information. The appearance of windows, the way menus and icons work, as well as other features, are controlled by a program called the window manager.
A window manager can make your desktop look a lot like a Macintosh or Microsoft Windows system, or it can look completely different. Details of other window managers, including how they make your screen look, are somewhat different—but this chapter should help you use them, too. This section explains a few common ways. Figure shows some steps along a few different paths to starting X. If your screen is like any of the following, refer to the section noted.
If none fits your situation, skim through the next three sections or ask another X user for help. Start reading at Section A.
Start reading at Section B. Read Section C. Your terminal has probably been set up to use one of the X display managers called xdm, gdm, kdm, or others; these log you in to your account and usually also start the window manager. The login window disappears. Or, if you get a blank screen, press and release your mouse buttons one by one, slowly, to see if a menu pops up.
Using Window Systems A B login: Four scenarios that may occur while starting X B. Next, you need to start X. Try this command first: If all goes well, your screen sprouts at least one window. If the window looks like Figure C, without a titlebar or border from a window manager, read Section C. No screens found. Try another terminal or ask a local expert. To make your life easier, get help from an X-pert and fix your account!
If you need to start the window manager by hand, move your pointer into the terminal window. For example: Running Programs A window manager can open windows of its own. But the main use of a window manager is to manage windows opened by other programs. Using Window Systems One of the most important X features is that windows can come either from programs running on your local computer, or over a network from programs running on remote computers.
The remote computers can run Unix or another operating system. Researchers can run graphical data analysis programs on supercomputers in other parts of the country and see the results in their offices. Setting Focus Of all the windows on your screen, only one window receives the keystrokes you type. This window is usually highlighted in some way.
For instance, the titlebar of the window that receives your input may be blue instead of the default grey color. In some systems, you may need to click on the titlebar at the top of the window. Your window manager may be configured to give the input focus automatically to any new windows that pop up. Terminal Windows One of the most important windows is a ter minal window.
A terminal window has a Unix session inside with a shell prompt, just like a miniature alphanumeric terminal. You can have several terminal windows running at the same time, each doing something different.
To enter a Unix command or answer a prompt in a window, set the focus there and type. One of the best-known programs is xterm. All perform the same basic job: Although you can start new programs such as terminal windows, xcalc, and so on from any open terminal window on your computer, we recommend starting them all from the first terminal window that you open.
To start the calculator called xcalc, enter this command from a terminal window: Chapter 7 has more information on this subject. You should get another shell prompt, where you can re-enter the xcalc command correctly.
The new window may be placed and get the focus automatically. You can also start a new terminal window from an existing one. The same method will start other X programs. Using Window Systems Window Manager Menus Your window manager probably has one or more menus, buttons, and dialogs of its own.
These let you control the way the window manager works, overall. For instance, a window manager menu might let you set how many rows of program launching buttons are in the panel or the color of the frame around each window. Different window managers have different ways to do these things. To find the menus on your window manager, read its documentation or experiment a bit. You might also find that pressing different mouse buttons will open different menus.
You may need to hold down the button to keep a menu visible. Move your mouse pointer around to places shown in the following, then try your mouse buttons: You might add window manager operations or commands to open other windows. Different window managers have different ways to do this.
Check your documentation. The absolute pathname varies system-to-system; you might find it using the command which or type from a shell prompt, like this: Enter cd. Open two terminal windows. Practice setting focus on both new windows and entering Unix commands in each.
Enter who am i, etc. Start a clock from one terminal window. Start a calculator from one window and try it. Check the working directory in both terminal windows.
Enter pwd in both windows. Terminate xcalc. Set the focus on the xcalc, and either type your interrupt character such as CTRL-C or click the close-box often an X in the top-right corner of the window frame.
Ask for help or check X Window System documentation. Why are the columns of text in my terminal window jagged? We recommend fixed-width fonts, such as Courier, for terminal windows. This can happen if a program fails or is interrupted. We assume that your mouse has three buttons, as mice on Unix systems usually do. If your mouse has two buttons, you may be able to simulate the missing middle button by pressing both of the other buttons at once. Your X system may need to be reconfigured to work this way, though.
Under X, a mouse can be set for either left-handed or right-handed users, so the button you use to click on and drag is the button under your index finger. The pointer may change to an hourglass shape to tell you to wait. When you resize a window, the pointer could change to a cross with arrows. Using a Mouse with xterm Windows One advantage terminal windows have over plain nonwindowing terminals is you can copy and paste text within an xterm window or between xterm windows.
Although this section is specifically about xterm windows, most tips here also apply to other kinds of terminal windows. Check your documentation or just try these and see! But xterm and some other windows also have separate cursors to show where text will be entered. We discuss this I-beam pointer later in this section. The mail command, shown in Figure and explained in Chapter 6, is a good example, but you can use any command line that you want to rerun from another window.
The I-beam pointer selects text for copying. Point to the first character of a command line not the prompt and click the first mouse button. Next, move the pointer to the end of the text you want to select and click the third button. The text between the first and third clicks should be highlighted; your xterm window should look something like Figure If you select the wrong text, you can undo the selection by clicking the first button anywhere in the window.
If you accidentally click the second button, this may paste some random text at the block cursor; in that case, you can erase the pasted text with your backspace key. Another way to select text is by pointing to the first character you want to copy, then holding down the first mouse button while you drag the pointer across the text. By the time you release the mouse button, the whole area of text should be highlighted.
The instant you highlight text as you did a moment ago , the text is also automatically copied, so you can paste it somewhere else. In most X window programs — the original X programs, at least—highlighting text copies it automatically. You can paste text in the window you copied it from or in another window. With the block cursor at a shell prompt, click the middle mouse button anywher e in the window. The selected text will be inserted pasted into the window at the block cursor, just as if you had typed it in.
Using Window Systems You can also select text in a window just by clicking. Point to a word and double-click the first button; the word should be highlighted.
Point to any character on a line a space is OK too and triple-click the first button to highlight the whole line. You can select and copy any text, not just command lines. With the mail command, for instance, you can copy a line from the body of the email message. Copying a command line The same copying and pasting works between xterm windows and between many other but not all windows that handle text. Before you paste text into an xterm window, always be sure the block cursor is at the place you want to insert the newly pasted text!
One common mistake is clicking the mouse at a particular point in the terminal window and expecting the text to be pasted there. In most terminal-based Unix applications, you need to move the insertion point typically, a block-shaped cursor using keyboard commands or the arrow keys.
Before you paste, be sure that the insertion point is at the place you want it. Unfortunately, there are several possible causes, including the following list: If you have a two-button mouse, pressing both buttons to act like the missing middle button can be tough: Try copying the text again, then pasting it right away.
You may be able to paste the text into another window such as a window-based text editor , then copy the text again and paste it where you want it. Can you save some or all of the text you want to copy into a temporary file? If so, you may be able to open that file in another type of window such as a text editor , then copy from that new window. Also try using a text editor to put just the text you want into the temporary file, then read that file into the program where you originally wanted to paste the text.
Working with Windows A window manager program helps you control windows. Various window managers do the same kinds of things, with some variation. The edges of the window can be used to resize the window. The top of every window has a titlebar that includes the window title as well as three buttons.
See Figure The three buttons at the top right corner have boxes inside them. With some window manager configurations, a minimized window turns into an icon; on others, the window may have a title button in a list of window buttons at the bottom of a window or elsewhere. No matter how your window manager treats a minimized window, though, the important point here is that minimizing puts unneeded windows out of the way without quitting the program inside them; it also keeps you from accidentally typing into a window.
One way to do this—which is different in different window managers, of course—is to click the button on the window frame that has a large square. Maximizing windows that have graphical applications in them—such as a web browser — works just fine. But it can be a bad idea to maximize terminal windows and give them more than 80 characters per 7 January In some window managers, clicking with the third mouse button is a more emphatic kill.
Although it may seem to work because the window closes , the programs running inside the window may not have time to finish their work and exit gracefully. If you have a shell prompt, type exit or press CTRL-D ; if the program has a menu or button with which to quit, use it. Moving Windows and Icons To move a window, start by pointing to the titlebar. Hold down the first mouse button and drag to the new location—then let go of the button. Resizing Windows If you have the pointer inside a window and then move the pointer to an edge, the pointer will probably change to another shape—an arrow, for example.
If you point to a corner, you may be able to resize both sides that meet at the corner. To resize when you have the arrow pointer, press and hold typically the first button, then drag the window border until the window size is what you want and release the button.
Also, remember that standard terminals are 80 characters wide. Stacking Windows You can have many windows open at once. To get some or all out of the way, minimize them. Then log off the Internet to free your phone line and read each window.
You may not need to shrink windows to keep them from overlapping. This is a handy feature of most X window managers. The Window Menu Many window managers let you control each window by its own window menu.
There are lots of ways to get a window menu. Here are two: Figure shows a window menu from the Sawfish window manager. When the menu pops up, you can point to an item and click it. Use this as a last resort. If the program has a separate menu or quit command for example, entering exit at a shell prompt in a terminal window , use it instead of Close. When you point to this item, a submenu appears with a list of desktops where the window can be moved.
If you have the GNOME Terminal window at a particular spot near the lower-left corner of the desktop, and you choose the Remember position entry on this submenu, then the next GNOME Terminal window you open will open at the same place on the desktop. Once a window has opened in this particular spot, you can always move it somewhere else.
A Sawfish window menu On the mwm menu not shown here , a keyboard shortcut follows each command. Other window managers may have keyboard shortcuts but not list them on the menu they could be listed on a configuration menu somewhere else. Other window managers may have different keyboard shortcuts — or none at all. Highlight the who am i, set focus to the other terminal window, paste the command there, and run it.
Move a window. Grab and drag the window by its titlebar. Iconify a window from the titlebar. Use the Mimimize button. Restore de-iconify the window. Panel A panel is a thin bar across the top or bottom of the screen. If you have a panel, it probably has icons you can click to launch a program. Pagers and Virtual Desktops Sophisticated window managers can manage multiple desktops on the same physical screen.
A pager lets you choose between these virtual desktops. Each virtual desktop is like the desktop you see when you open the window system—but you can open different windows on each virtual desktop. All virtual desktops appear on the same screen, but only one is visible at a time. Using Window Systems Think of these desktops arranged in a grid, as Figure shows.
Active Desktop Figur e The pager lets you choose which desktop you want to see. If your window manager has a panel, each virtual desktop probably has its own panel. For instance, if your system has a console window where you can monitor system log messages, you might want to see that window from every desktop. On KDE, clicking the push-pin icon near the top left corner of a window frame does the same thing. By the way, many window-based programs — such as web browsers — can open multiple windows.
You then move each new Netscape window to the desktop where you want it. Quitting Netscape in this situation would remove all of its windows from all of the desktops. Unresponsive Windows While your window system is running, windows may seem to stop responding to commands or mouse clicks. Some or all of the window contents — but not necessarily the window frame itself—may go partly or completely blank.
If the window is showing something from a network, such as a web browser showing a web page from the Internet — or, especially, if the window is from another computer across the network—the cause may be a network delay. If you can wait a minute or two without pressing extra keys or clicking the mouse around; just wait! Here are some things to try at that point: Using Window Systems If you have other windows open, try to use them.
For instance, if a text editor is open, try to add a word to the text or use a command from one of its menus. If other windows seem to work normally, you can guess that the problem is only in the one window or family of windows, from one program that seems frozen. Try to minimize and maximize that window, move it around the screen, and so on. If this seems to work normally, the trouble is probably in the original frozen window.
But, if nothing seems to work, the whole window system may be frozen. Next, handle the frozen window or windows: If several windows are frozen, try these techniques on each window. Start by trying to close the window system normally from its main menu, with whatever command you normally use. The next step is to try to kill your entire X Window System server.
You can do this by holding down three keyboard keys at once: If you started the window system 7 January Or, if you started the window system nongraphically, you should see a shell prompt on your screen; you can repeat the same command xinit or startx, for instance that you used to start the window system before.
If you killed windows, or the whole window system—and you were doing work in any of those windows—any changes you made to a file in a text editor, for instance may have been lost. The key to shutting down X is to know which of your programs your windows or window manager is the contr olling pr ogram.
When the controlling program quits, any leftover X programs are killed immediately. The controlling program is usually either the window manager or the single terminal window that started your X session. Find the controlling program for your X session and write it down: No matter what your controlling program is, closing it sooner than last means the other windows will be killed quickly and automatically.
Here are the steps to shut down X: Quit all noncontrolling programs all programs other than the controlling program. Most terminal windows will close when their shell program exits. Quit the controlling program.
After X shuts down, you may get a Unix shell prompt. If you do, you can log out by entering exit. As an authorized system user, you have an account that gives you: The Unix Filesystem A file is the unit of storage in Unix, as in most other systems.
A file can hold anything: In Unix, files are organized into directories. A dir ectory is actually a special kind of file where the system stores information about other files. You can think of a directory as a place, so that files are said to be contained in directories and you are said to work inside a directory. This section introduces the Unix filesystem. Later sections in this chapter show how you can look in files and protect them.
Chapter 4 has more information. This directory, a unique place in the Unix filesystem, contains the files you use almost every time you log in. In your home directory, you can make your own files.
Like folders in a file cabinet, this is a good way to organize your files. Every time you log in, your home directory is your working directory. You may change to another directory, in which case the directory you move to becomes your working directory.
Unless you tell Unix otherwise, all commands that you enter apply to the files in your working directory. For instance, if you type the command pico report, the Pico editor is started on a file named report in your working directory. The Directory Tree All directories on a Unix system are organized into a hierarchical structure that you can imagine as a family tree.
The root contains several directories. Figure shows a visual representation of the top of a Unix filesystem tree: Example of a directory tree bin, etc, users, tmp, and usr are some of the subdir ectories child directories of the root directory.
These subdirectories are fairly standard directories; they usually contain specific kinds of system files. For instance, bin contains many Unix programs. Not all systems have a directory named users.
In our example, the parent directory of users one level above is the root directory. It has two subdirectories one level below , john and car ol. On a Unix system, each directory has only one parent directory, but it may have one or more subdirectories. To specify a file or directory location, write its pathname. A pathname is like the address of the directory or file in the Unix filesystem. We look at pathnames in a moment. On a basic Unix system, all files in the filesystem are stored on disks connected to your computer.
Your system may have an easier way: Some systems have another directory above the root. Absolute Pathnames As you saw earlier, the Unix filesystem organizes its files and directories in an inverted tree structure with the root directory at the top. An absolute pathname tells you the path of directories you must travel to get from the root to the directory or file you want.
It locates one only one! Figure shows this structure. In other words, an absolute pathname always starts with a slash. Relative Pathnames You can also locate a file or directory with a relative pathname. A relative pathname gives the location relative to your working directory. Like absolute pathnames, relative pathnames can go through more than one directory level by naming the directories along the path.
Notice that neither pathname in the previous paragraph starts with a slash. Relative pathnames start at the working directory, not the root directory. In other words, a relative pathname never starts with a slash. Look again at Figure Please think about that before you read more.
It says to look in the root directory for a subdirectory named car ol. But there is no subdirectory named car ol one level directly below the root, so the pathname is wrong. As you saw earlier, you can also go down the tree by using subdirectory names. If your working directory in the figure is work, then there are two pathnames for the play subdirectory of car ol.
Figure illustrates this. Relative pathname from work to play The relative pathname would be.. Absolute and relative pathnames are totally interchangeable. Unix programs simply follow whatever path you specify to wherever it leads. If you use an absolute pathname, the path starts from the root. If you use a relative pathname, the path starts from your working directory. Choose whichever is easier at the moment. The pwd command takes no arguments. The cd command has the form: Note that you can only change to another directory.
You cannot cd to a filename. If you try, your shell in this example, bash gives you an error message: Files in the Directory Tree A directory can hold subdirectories. And, of course, a directory can hold files. The four files are shown along with the work subdirectory.
Files in the directory tree Pathnames to files are made the same way as pathnames to directories. You may see some of them as you explore the filesystem. Listing Files with ls To use the cd command, you must decide which entries in a directory are subdirectories and which are files.
The ls command lists entries in the directory tree and can also show you which is which. The syntax is: Using Your Unix Account made any files in your working directory. The screen should look something like this: The —a option for all is guaranteed to show you some more files, as in the following example showing a directory like the one in Figure As mentioned earlier,.. A single. There may also be other files, such as. To get more information about each item that ls lists, add the —l option.
The long format provides the following information about each item: Total n n amount of storage used by everything in this directory. This is measured in blocks. On many systems, but not all, a full block holds bytes.
A block can also be partly full. Output fr om ls -al Type Tells whether the item is a directory d or a plain file -. Access modes Specifies three types of users yourself, your group, all others who are allowed to read r , write w , or execute x your files.
Links The number of files or directories linked to this one. Owner The user who created or owns this file or directory. Gr oup The group that owns the file or directory. Size in bytes The size of the file or directory. A directory is actually a special type of file. Using Your Unix Account Modification date When the file was last modified, or the directory contents last changed when something in the directory was added, renamed, or removed.
If an entry was modified more than six months ago, ls shows the year instead of the time. Name The name of the file or directory. Notice especially the columns that list the owner and group of the files, and the access modes also called permissions.
You also belong to a group, set by the person who created your account. Files you create are either marked with the name of your group, or in some cases, the group that owns the directory. The per missions show who can read, write, or execute the file or directory; we explain what that means in a moment. The permissions have ten characters.
The first character shows the file type d for directory or - for a plain file. The other characters come in groups of three. The third group, characters 8—10, show permissions for all other users. For example, the permissions for. The owner, john, has both read and write permissions. No one has execute x permission, which should only be used for executable files files that hold programs.
In the case of directories, x means the permission to access the directory — for example, to run a command that reads a file there or to use a subdirectory. Notice that the two directories shown in the example are executable accessible by john, by users in the doc group, and by everyone else on the system.
A directory with w write permission allows deleting, renaming, or adding files within the directory. Read r permission allows listing the directory with ls. You can use the chmod command to change the permissions of your files and directories.
If you give the pathname to a directory, ls lists the directory but it does not change your working directory.
The pwd command in the following example shows this: In our example, guide and ideas are directories. The file testpgm is an executable file.
This can make a very long list—especially when you list a directory near the root! Piping the output of ls to a pager program solves this problem. You can combine other options with —R: On Linux and other systems with the GNU version of ls, you may be able to see names in color. For instance, directories could be green and program files could be yellow. Like almost everything on Unix, of course, this is configurable. The details are more than we can cover in an introductory book.
Try typing ls ——color and see what happens. Take a tour of the directory system, hopping one or many levels at a time, with a mixture of cd and pwd commands.
Using Your Unix Account Go to your home directory. Enter cd Find your working directory. Enter pwd Change to new working directory with its absolute pathname. Enter ls Change directory to root and list it in one step.
Use the command separator, a semicolon. Enter pwd Change to a subdirectory; use its relative pathname. Enter cd usr Find your working directory. Enter pwd Change to a subdirectory. Enter cd bin Find your working directory. Enter pwd Give a wrong pathname. Enter cd xqk List files in another directory.