Download presentation
Presentation is loading. Please wait.
Published byPamela Ellen Melton Modified over 9 years ago
1
NETW-240 Shells Last Update 2013.04.09 1.4.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 1
2
Objectives of This Section Learn –What a shell is –How to use a shell Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 2
3
What is a Shell It is a command line interpreter In other words if you type something on the command line and press enter, the shell will either do something with that command or tell you it cannot Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 3
4
Common Linux Shells The most common shells on Linux and UNIX systems are the –sh - Bourne Shell –csh - C Shell –ksh - Korn Shell –bash - Bourne Again Shell bash is an advanced version of the sh shell first written for Unix systems Bash is the one most often used in Linux Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 4
5
Common Linux Shells To leave a shell –Ctrl D or exit Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 5
6
bash When Linux is started after the load finishes the shell presents a prompt such as Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 6
7
bash Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 7
8
bash A nice feature of bash is the command history It will keep track of a certain number of previously issued commands in the –~/.bash_history file The number of commands in the history is likewise customizable Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 8
9
bash When bash is first started, the history list is initialized by the defined history file - ~/.bash_history The history list is kept in memory until you exit the shell, at which point the list is written to the history file, overwriting its current contents Even when you log in initially, you have a history of what you did during your last login session Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 9
10
bash You can access the commands that are stored in the history file by using the up and down arrow keys to move to a previously issued command Once you've selected a command, you can edit it by inserting or deleting characters Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 10
11
bash Another method of accessing the command history is to use the history command The history command, by default, lists the lines that are contained in the history file For example, issuing the command –history 10 displays the last 10 lines in the history file Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 11
12
bash The command-line options for history are quite simple –-r Tells history to read the contents of the history file and use them as the current history list –-w Tells history to write the current history list to the history file and overwrite its current contents Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 12
13
bash –-a Tells history to append the current history list to the history file –-n Causes the lines that are in the history file to be read into the current history list Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 13
14
bash Pipes are a way to string a number of commands together The output from the first command is piped or sent into the second command as input, the output from the second command is piped into the third command as input, and so on The output from the last command is printed to the screen or redirected to a file Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 14
15
bash In order to pipe commands, you must use the pipe - vertical bar, which is the | character It tells bash where one command ends and the next begins There's no limit to the number of pipes that can be used bash, like every other shell, supports redirection for commands Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 15
16
bash You can redirect the output from a command to a file or device other than the local console Likewise, you can use a file or device to provide input to a command To redirect the output from a command to a new file, use the > symbol Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 16
17
bash Another feature of bash is its ability to suspend currently running processes, known as Job Control Pressing –CTRL Z suspends the currently running process Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 17
18
bash Then these two commands move the process to the background or back to the foreground –bg –fg To start a command in the background use the &, as in –commandname & Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 18
19
bash Like everything in Linux bash uses several startup files One of these is a common file The other three are user specific The common file is –/etc/profile Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 19
20
bash The user specific files are –~/.bash.profile Contains information about the user’s shell environment –~/.bash.login Executed at each login to the shell –~/.profile Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 20
21
bash –~/bashrc A configuration file that is executed each time the bash shell is entered And also each time a subshell is generated –~/bash_logout Executed on user logout of the shell Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 21
22
bash.bash_profile is executed at user login To reexecute it after a change to the file precede it with –. – a period As in –..bash_profile or –source.bash_profile Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 22
23
bash The ~ means from the user’s home directory bash does it this make just to make it harder on you as an administrator or user /etc/profile –This is the main startup file for bash –It is used for the commands that all users need Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 23
24
Common Commands pwd –Shows the current directory cd –Change directories cp –Copy mv –Rename Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 24
25
Common Commands rm –Remove mkmir –Make a directory rmdir –Delete empty directories Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 25
26
Common Commands ls –Show a list of whatever is in the directory –Switches -a –Show everything -F –List by type -l –Long listing -t –List by date Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 26
27
Common Commands To show one screen full of filenames at a time –ls –l | less Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 27
28
Common Commands ln –Create a link file –To find out what type of file the file is cat –Display what is inside a file Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 28
29
Common Commands head –Show the first 10 lines of a file –As in head filename –Or specify the number of lines with head –n20 filename Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 29
30
Common Commands tail –Show the last 10 lines of a file –As in tail filename –Or specify the number of lines with tail –n20 filename Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 30
31
Common Commands more –Shows a file one page at a time less –Shows a file one page at a time –But allows scrolling through the file –q to quit it Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 31
32
Common Commands grep –To search through a file –For example grep whattosearchfor filetolookin or grep ‘word word’ filetolookin find –Looks through directories for a file Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 32
33
Getting Help locate –The same as find, but faster help –Basic information –Such as cat --help Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 33
34
Getting Help man –More information –As in man apache –Switches -k –Shows commands Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 34
35
Getting Help info –Provides more structure to the information than plain man does –But does not cover all man pages Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 35
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.