Download presentation
Presentation is loading. Please wait.
1
Using the Terminal Lab 3+
2
"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."
3
What is the Terminal There 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.
4
What is BASH? BASH = Bourne Again Shell
BASH 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.
5
Starting a Terminal Applications System Tools Terminal
Print Screen
6
Shell Prompt Terms terminal window shell prompt command line Shell Print Screen
7
Terminal Window The terminal window is the window that contains the shell prompt, command line, and output from the shell.
8
Shell Prompt The 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: @ to separate UserName from ComputerName. : colon to separate the computer name from the directory. ~ tilda to represent your home directory. $ to terminate the prompt.
9
Command Line The command line is where options to a command are placed. The following is an example of a command line: command -options <filename>
10
Shell The shell is the program that interprets commands so that the operating system can understand them.
11
The 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
12
Checking your login session
Login 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) When you log in to 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, use the id command as follows: $ id uid=501(chris) gid=105(sales) groups=105(sales),4(adm),7(lp) This shows that the user name is chris, which is represented by the numeric user ID (uid) 501. Here, the primary group for chris is called sales, which has a group ID (gid) of 105. Chris also belongs to other groups called adm (uid 4) and lp (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 your current login session by using the who command. In the following example, the -m option tells the who command to print information about the current user, -u says to add information about idle time and the process ID, and -H asks that a header be printed: $ who -umH NAME LINE TIME IDLE PID COMMENT chris tty1 Jan 13 20: The output from this who command shows that the user name is chris. Here, chris is logged in on tty1 (which is the monitor connected to the computer), and his login session began at 20:57 on January 13. The IDLE time 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. COMMENT would show the name of the remote computer the user had logged in from, if that user had logged in from another computer on the network, or the name of the local X display if you were using a Terminal window (such as :0.0). $ who -umH NAME LINE TIME IDLE PID COMMENT chris tty jan :
13
-m option tells the who command to print information about the current user
-u says to add information about idle time and the process ID -H asks that a header be printed
14
Checking directories and permissions
To find out what your current directory is: To find out the name of your home directory: $ pwd /usr/bin $ echo $HOME /home/chris
15
To get back to your home directory:
To change the current directory to the directory that you choose: $ cd $ cd /etc
16
File & Directory Commands
To list the contents of the current directory: Date The date of last modification permissions User The user that owns the file, or directory Size The size in bytes $ ls –al /home/chris total 158 drwxrwxrwx chris sales May : drwxr-xr-x root root May : -rw chris sales May : bash_history -rw-r--r chris sales May : bash_logout -rw-r--r chris sales May : bash_profile At this point, list the contents of your home directory, using the ls command. Either you can type the full path to your home directory to list its contents, or you can use the ls command without a directory name to list the contents of the current directory. Using the -a option to ls enables you to view the hidden files (dot files) as well as all other files. With the -l option, 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 (-l option) 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/chris and two dots (..), which is also referred to as the parent directory, represents /home. The /home directory is owned by root. All other files are owned by the user chris (who belongs to the sales group). The file or directory names shown on the right are mostly dot (.) files that are used to store GUI properties (.kde) or shell properties (.bash files). The only non-dot file shown in this example is the one named letter. 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 recently modified (column 5). Group The group that file belongs to, Directories This field specifies the number of links or directories inside this directory. Directory or File The name of the file or directory.
17
File & Directory Commands
List the contents of your home directory List the contents of your root directory $ ls ~ $ ls /
18
Checking system activity
To 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 au USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root ttyp0 S : : login jake jake ttyp0 S : : bash jake ttyp0 R : : ps au it is a snapshot of what is running when you invoked the command. If you want a constantly updated list of running processes Application such as Mozilla and Nautilus are thread-aware — multiple threads are created to handle multiple users or multiple requests, and each thread is given a process ID. By default, ps and top only display the main (initial) thread. To view all threads, use the command ps -m or type [Shift]-[H] in top. If you prefer a graphical interface for top, you can use the GNOME System Monitor. To start it from the desktop, select Main Menu Button (on the Panel) => System Tools => System Monitor or type gnome-system-monitor at a shell prompt from within the X Window System. Then select the Process Listing tab. The GNOME System Monitor allows 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.
19
Checking system activity
To see and monitor all the processes running on the system : use spacebar to page through , and q to end the list $ ps aux | less A pipe lets you direct the output of one command to be the input of the next command.
20
Checking system activity
To stop any process by PID i.e. to kill process To stop all process except your shell $ kill 2310 $ kill 0
21
References Red Hat Linux Bible: Fedora and Enterprise Editionby Christopher Negus
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.