+ All Categories
Home > Documents > Using the Terminal

Using the Terminal

Date post: 22-Feb-2016
Category:
Upload: carnig
View: 36 times
Download: 0 times
Share this document with a friend
Description:
Using the Terminal. Lab 3 +. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work done without first reading lots of documentation. The traditional Unix environment is a CLI (command line interface) - PowerPoint PPT Presentation

of 21

Click here to load reader

Transcript

Using the Terminal

Lab 3+Using the Terminal1"Under Linux there are GUIs (graphical user interfaces).where you can point and click and drag, and hopefully get work done without first reading lots of documentation.The traditional Unix environment is a CLI (command line interface) where you type commands to tell the computer what to do. That is faster and more powerful, but requires finding out what the commands are."

2What is the TerminalThere are many varieties of Linux, but almost all of them use similar commands that can be entered from a command-line interface terminal. The Terminal = command line interface = shell that gives command to the OS.A "shell" is a program which interprets commands so that the operating system can understand them.the use of the shell can be quicker than a graphical method.Red Hat uses bash as its default shell.3What is BASH?BASH = Bourne Again ShellBASH is a shell written as a free replacement to the standard Bourne Shell which is written by Steve Bourne for UNIX systems.It has all of the features of the original Bourne shell, plus additions that make it easier to program with and use from the command line.Since it is Free Software, it has been adopted as the default shell on most Linux systems.

4Starting a TerminalApplications System Tools Terminal

Print Screen

5Shell Prompt Termsterminal window shell promptcommand lineShell

Print Screen6Terminal Window The terminal window is the window that contains the shell prompt, command line, and output from the shell.

7Shell PromptThe shell prompt is the marker on the screen that shows where the command line should be placed. The following is an example of a shell prompt:UserName@ComputerName:~$@ to separate UserName from ComputerName.: colon to separate the computer name from the directory.~ tilda to represent your home directory.$ to terminate the prompt.8Command Line The command line is where options to a command are placed. The following is an example of a command line:command -options

9ShellThe shell is the program that interprets commands so that the operating system can understand them.10The prompt --- the command you type --- Enter. The lines that follow show the output that results from the command.NOTE:command may have options:command -options

11Checking your login sessionLogin Identity includes: user name, group name, user ID, and group ID.To find out information about your identity:

Linux keeps track of login session:when you logged in, how long you have been idle, and where you logged in from.

$ id uid=501(chris) gid=105(sales) groups=105(sales), 4(adm), 7(lp) $ who -umH NAME LINE TIME IDLE PID COMMENT chris tty1 jan 13 20:57 . 2013 12When you log into a Linux system, Linux views you as having a particular identity. That identity includes your user name, group name, user ID, and group ID. Linux also keeps track of your login session: it knows when you logged in, how long you have been idle, and where you logged in from.To find out information about your identity, usetheidcommand as follows:$ id uid=501(chris) gid=105(sales) groups=105(sales),4(adm),7(lp)This shows that the user name ischris, which is represented by the numeric user ID (uid)501. Here, the primary group for chris is calledsales, which has a group ID (gid) of105. Chris also belongs to other groups calledadm(uid 4) andlp(uid 7). These names and numbers represent the permissions that chris has to access computer resources. (Permissions are described later in this chapter in the section on working with files.)

You can see information about login session your current by using thewhocommand. In the following example, the-moption tells thewhocommand to print information about the current user,-usays to add information about idle time and the process ID, and-Hasksthat a header be printed:$ who -umH NAME LINE TIME IDLE PID COMMENT chris tty1 Jan 13 20:57 . 2013The output from thiswhocommand shows that the user name ischris.Here,chrisis logged in ontty1(which is the monitor connected to the computer), and his login session began at 20:57 on January 13.

TheIDLEtime shows how long the shell has been open without any command being typed (the dot indicates that it is currently active). The pid is the process-ID of the user's shell.COMMENTwould show the name of the remote computer the user had logged in from, if that user had logged in from another computer onthe network, or the name of the local X display if you were using a Terminal window (such as :0.0).

12-moption tells thewhocommand to print information about the current user-usays to add information about idle time and the process ID-Hasksthat a header be printed

1313Checking directories and permissionsTo find out what your current directory is:

To find out the name of your home directory:

$ pwd /usr/bin $ echo $HOME /home/chris To get back to your home directory:

To change the current directory to the directory that you choose:

$ cd$ cd /etc15File & Directory Commands$ ls al /home/chris total 158drwxrwxrwx 3 chris sales 1024 May 12 13:55 .drwxr-xr-x 3 root root 1024 May 10 01:49 .. -rw------- 1 chris sales 2204 May 18 21:30 .bash_history -rw-r--r-- 1 chris sales 24 May 10 01:50 .bash_logout -rw-r--r-- 1 chris sales 230 May 10 01:50 .bash_profileTo list the contents of the current directory:

permissionsDirectoriesThis field specifies the number of links or directories inside this directory.SizeThe size in bytesDateThe date of last modificationGroupThe group that file belongs to,Directory or FileThe name of the file or directory.UserThe user that owns the file, or directoryAt this point, list the contents of your home directory, using thelscommand. Either you can type the full path to your home directory to list its contents, or you can use thelscommand without a directory name to list the contents of the current directory. Using the-aoption tolsenables you to view the hidden files (dot files) as well as all other files. With the-loption, you can see a long, detailed list of information on each file. (You can put multiple single-letter options together after a single dash, for example,-la.)$ ls -la /home/chris total 158

Displaying a long list (-loption) of the contents of your home directory shows you more about file sizes and directories. Directories such as the current directory (.) and the directory above the current directory (..) are noted as directories by the letter "d" at the beginning of each entry. In this case, dot (.) represents/home/chrisand two dots (..), which is also referred to as the parent directory, represents/home. The/homedirectory is owned by root. All other files are owned by the userchris(who belongs to thesalesgroup).

The file or directory names shown on the right are mostly dot (.) files that are used to store GUI properties (.kde) or shell properties (.bashfiles). The only non-dot file shown in this example is the one namedletter. At the beginning of each line are the permissions set for each file. (Permissions and configuring shell property files are described later in this chapter.) Other information in the listing includes the size of each file in bytes (column 4) and the date and time each file was most recentlymodified (column 5).

16File & Directory CommandsList the contents of your home directory

List the contents of your root directory

$ ls ~$ ls /Checking system activityTo list running processes and monitoring system usage:

a option ask to show process of all users who are associated with your current terminal u option asks that user names be shown , as well as other information such as the time process started and CPU usage.VSZ (virtual set size) size of image process(in kilobytes).RSS(resident set size) size of program in memory.

$ ps auUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 2164 0.0 0.8 1908 1100 ttyp0 S 14:50 0:00 login - - jake jake 2147 0.0 0.7 1836 1020 ttyp0 S 14:50 0:00 -bash jake 2310 0.0 0.7 2592 912 ttyp0 R 18:22 0:00 ps auit is a snapshot of what is running when you invoked the command. If you want a constantly updated list of running processes

Application such asMozillaandNautilusarethread-aware multiple threads are created to handle multiple users or multiple requests, and each thread is given a process ID. By default,psandtoponly display the main (initial) thread. To view all threads, use the commandps -mor type[Shift]-[H]intop.If you prefer a graphical interface fortop, you can use theGNOME System Monitor. To start it from the desktop, selectMain Menu Button(on the Panel) =>System Tools=>System Monitoror typegnome-system-monitorat a shell prompt from within the X Window System. Then select theProcess Listingtab.TheGNOME System Monitorallows you to search for process in the list of running process as well as view all processes, your processes, or active processes.

In this example, the -a option asks to show processes of all users that are associated with your current terminal, and the -u option asks that user names be shown, as well as other information such as the time the process started and memory and CPU usage. The concept of terminal comes from the old days, when people worked exclusively from character terminals, so a terminal typically represented a single person at a single screen. Now you can have many "terminals" on one screen by opening multiple Terminal windows.

On this shell session, there isn't much happening. The first process shows that the user named jake logged in to the login process (which is controlled by the root user). The next process shows that jake is using a bash shell and has just run the ps au command. The terminal device ttyp0 is being used for the login session. The STAT column represents the state of the process, with R indicating a currently running process and S representing a sleeping process.

The USER column shows the name of the user who started the process. Each process is represented by a unique ID number referred to as a process ID (PID). (You can use the PID if you ever need to kill a runaway process.) The %CPU and %MEM columns show the percentage of the processor and random access memory, respectively, that the process is consuming. VSZ (virtual set size) shows size of the image process (in kilobytes), and RSS (resident set size) shows the size of the program in memory. START shows the time the process began running, and TIME shows the cumulative system time used.

18Checking system activityTo see and monitor all the processes running on the system :

use spacebar to page through , and q to end the list

$ ps aux | lessA pipe lets you direct the output of one command to be the input of the nextcommand.-x option adds to the list processes that have no controlling terminal, such asdaemons, which are programs that are launched duringbooting.

19Checking system activityTo stop any process by PID i.e. to kill process

To stop all process except your shell

$ kill 2310 $ kill 0 References Red Hat Linux Bible: Fedora and EnterpriseEdition byChristopher Negus21


Recommended