0% found this document useful (0 votes)
4 views

Introduction to Linux

The document provides an introduction to Linux, covering its definition, history, and significance as a widely used operating system, particularly in server environments. It discusses essential components such as the Bash shell, I/O redirection, file system navigation, and various commands for file manipulation. Additionally, it outlines how to connect to a Linux host from different operating systems and highlights the importance of environment variables and command help resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction to Linux

The document provides an introduction to Linux, covering its definition, history, and significance as a widely used operating system, particularly in server environments. It discusses essential components such as the Bash shell, I/O redirection, file system navigation, and various commands for file manipulation. Additionally, it outlines how to connect to a Linux host from different operating systems and highlights the importance of environment variables and command help resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Introduction to Linux

Liban Bashir
Network Security Administrator/
Former SYS ADMIN
[email protected]
Introduction to Linux -
agenda
 What is Linux?
 The Bash shell
 I/O redirection (pipes, etc.)
 Navigating the file system
What is
Linux?

The Most Common


O/S Used By BU
Researchers When
Working on a
Server or
Computer Cluster
Where is Linux?
What is Linux?

http://en.wikipedia.org/wiki/Darwin_%28operating_system%29
What is Linux?
 Linux is a Unix* clone begun in 1991 and
written from scratch by Linus Torvalds with
assistance from a loosely-knit team of
hackers across the Net.
 64% of the world’s servers run some variant

of Unix or Linux. The Android phone and the


Amazon Kindle run Linux.

*kernel
What is Linux?
Linux + GNU Utilities = Free Unix

 a set of programs written


 Linux is an O/S core by Richard Stallman and
written by Linus others. They are the GNU
Torvalds and others utilities.
http://www.gnu.org/
AND
What is Linux?
gcc
 Bird’s eye view:
wc bash emacs

multitasking

tcsh
cat device grep
access
Hardware file
system

sh

Kernel awk
sort

Shell

Utilities
Linux Has Many Distributions
What is Linux?
“Small programs that do one thing well”

 From The Unix Programming Environment,


Kernighan and Pike:
… at its heart is the idea that the power of a system comes
more from the relationships among programs than from the
programs themselves. Many UNIX programs do quite trivial
things in isolation, but, combined with other programs,
become general and useful tools.
What is Linux: Selected text
processing utilities
 awk Pattern scanning and processing language
 cat Display file(s)
 cut Extract selected fields of each line of a file
 diff Compare two files
 grep Search text for a pattern
 head Display the first part of files
 less Display files on a page-by-page basis
 od Dump files in various formats
 sed Stream editor (esp. search and replace)
 sort Sort text files
 split Split files
 tail Display the last part of a file
 tr Translate/delete characters
 uniq Filter out repeated lines in a file
 wc Line, word and character count
 tar File archive (similar to zip)
Connecting to a Linux Host – Windows
Client Software

 You need a “xterm” emulation –


software that emulates an “X”
terminal and that connects using
the “SSH” Secure Shell protocol.
◦ Windows
 Recommended: MobaXterm (http
://mobaxterm.mobatek.net/)
 Also available at BU, Xwin32
(http://www.bu.edu/tech/services/support/
desktop/distribution/xwindows/xwin32/)
Connecting to a Linux Host –
Mac OS X Client Software

◦ Mac OS X
 “Terminal” is already installed
 Why? Darwin, the system on which Apple's Mac OS
X is built, is a derivative of 4.4BSD-Lite2 and
FreeBSD. In other words, the Mac is a Unix system!
 For X11 (graphics), see XQuartz
(http://xquartz.macosforge.org/
landing/)
Connecting to a Linux Host -
Windows Client
 MobaXterm
◦ From Windows Desktop
 Double-click MobaXterm_Personal_6.5.exe
 Double-click saved session scc1.bu.edu [SSH]
 Login: <userID>
 Password: <password>
Connecting to a Linux Host -
Mac OS X Client
 Terminal
◦ Type ssh –X scc1.bu.edu or ssh –Y scc1.bu.edu
The Shell
 A shell is a computer program that interprets the
commands you type and sends them to the operating
system. On Linux systems (and others, like DOS/Windows),
it also provides a set of built-in commands and
programming control structures, environment variables,
etc.
 Most Linux systems, including BU’s Shared Computing
Cluster, support at least two shells: TCSH and BASH. The
default shell for your account is BASH. (Which is best?
Caution: flame war potential here!)
 “BASH” = “Bourne-again Shell” (GNU version of ~1977 shell
written by Stephen Bourne)
Bash environment
variables
 Variables are named storage locations. So-called
“environment variables” are conventionally used
by the shell to store information such as where it
should look for commands (i.e., the PATH).
Environment variables are shared with programs
that the shell runs.
 To see the current value of PATH, do:
◦ echo $PATH
 To see all currently defined environment variables
do:
◦ printenv
Help with Commands
 Type
◦ date –-help
◦ man date
◦ info date
 [And yes, you can always Google it]
 For a list of BASH built-in commands, just

type the command ‘help’


(and see also ‘man bash’)
On using ‘man’ with ‘less’
 The ‘man’ command generally pipes its
output through a pager called ‘less’, which
supports many ways of scrolling through text:
◦ Space, f # page forward
◦b # page backward
◦< # go to first line of file
◦> # go to last line of file
◦/ # search forward (n to repeat)
◦? # search backward (N to
repeat)
◦h # display help
◦q # quit help
Plug: emacs has a man page
mode that is convenient.
I/O redirection with pipes
 Many Linux commands print to “standard
output”, which defaults to the terminal screen.
The ‘|’ (pipe) character can be used to divert or
“redirect” output to another program or filter.
◦w # show who’s logged on
◦ w | less # pipe into the ‘less’ pager
◦ w | grep ‘tuta’ # pipe into grep, which will print
only lines containing ‘tuta’
◦ w | grep –v ‘tuta’ # print only lines not containing
‘tuta’
◦ w | grep ‘tuta’ | sed s/tuta/scholar/g # replace
all ‘tuta’ with ‘scholar’
More examples of I/O redirection
 Try the following (use up arrow to avoid retyping
each line):
◦ w | wc # count lines, words, and characters
◦ w | cut –d’ ‘ –f1 | less # extract first column, page with
‘less’
◦ w | cut –d’ ‘ –f1 | sort # sort users (with duplicates)
◦ w | cut –d’ ‘ –f1 | sort | uniq # eliminate duplicates
 We can also redirect output into a file:
◦ w | cut –d’ ‘ –f1 | sort | uniq > users
 Note that ‘awk’ can be used instead of ‘cut’:
◦ w | awk ‘{print $1;}’ | sort | uniq > users
 Quiz:
◦ How might we count the number of distinct users currently
logged in? For extra credit, how can we avoid over-counting by
2? (Hint: use ‘tail’.)
The Linux File System
 The structure resembles an upside-down
tree
 Directories (a.k.a. “folders” in Windows) are

collections of files and other directories.


 Every directory has a parent except for the

root directory.
 Many directories have subdirectories.
 Unlike Windows, with multiple drives and

multiple file systems, a Unix/Linux system


only has ONE file system.
The Linux File System
A Typical Linux File System
Navigating the File System
 Essential navigation commands:
◦ pwd print current directory
◦ ls list files
◦ cd change directory
Navigating the File System
 We use “pathnames” to refer to files and directories in the
Linux file system. There are two types of pathnames:
◦ Absolute – the full path to a directory or file; begins with /
◦ Relative – a partial path that is relative to the current
working directory; does not begin with /
 Special characters interpreted by the shell for filename
expansion:
◦~ your home directory (e.g., /usr1/tutorial/tuta1)
◦. current directory
◦ .. parent directory
◦* wildcard matching any filename
◦? wildcard matching any character
◦ TAB try to complete (partially typed) filename
Navigating the File System
 Examples:
◦ cd /usr/local/lib # change directory to
/usr/local/lib
◦ cd ~ # change to home directory (could
also just type ‘cd’)
◦ pwd # print working (current) directory
◦ cd ..
◦ cd / (root directory)
◦ ls –d pro* # (a listing of only the directories
starting with “pro”)
The ls Command
 Useful options for the “ls” command:
◦ ls -a List all files, including hidden files beginning
with a period “.”
◦ ls -ld * List details about a directory and not its
contents
◦ ls -F Put an indicator character at the end of
each name
◦ ls –l Simple long listing
◦ ls –lR Recursive long listing
◦ ls –lh Give human readable file sizes
◦ ls –lS Sort files by file size
◦ ls –lt Sort files by modification time (very useful!)
Some Useful File
Commands
cp [file1] [file2] copy file
 mkdir [name] make directory
 rmdir [name] remove (empty) directory
 mv [file] [destination] move/rename file
 rm [file] remove (-r for recursive)
 file [file] identify file type
 less [file] page through file
 head -n [file] display first n lines
 tail -n [file] display last n lines
 ln –s [file] [new] create symbolic link
 cat [file] [file2…] display file(s)
 tac [file] [file2…] display file in reverse order
 touch [file] update modification time
 od [file] display file contents, esp. binary
Manipulating files and
directories
 Examples:
◦ cd (also takes you to your home directory like cd ~)
◦ mkdir test
◦ cd test
◦ echo ‘Hello everyone’ > myfile.txt
◦ echo ‘Goodbye all’ >> myfile.txt
◦ less myfile.txt
◦ mkdir subdir1/subdir2 (FAILS)
◦ mkdir -p subdir1/subdir2 (Succeeds)
◦ mv myfile.txt subdir1/subdir2
◦ cd ..
◦ rmdir test (FAILS)
◦ rm –rf test (Succeeds)
Symbolic links
 Sometimes it is helpful to be able to access
a file from multiple locations within the
hierarchy. On a Windows system, we might
create a “shortcut.” On a Linux system, we
can create a symbolic link:
◦ mkdir foo # make foo directory
◦ touch foo/bar # create empty file
◦ ln –s foo/bar . # create link in current dir.
Finding a needle in a
haystack
 The ‘find’ command has a rather unfriendly syntax, but can
be exceedingly helpful for locating files in heavily nested
directories.
 Examples:
◦ find . –name my-file.txt # search for my-file.txt in .
◦ find ~ -name bu –type d # search for “bu” directories
in ~
◦ find ~ -name ‘*.txt’ # search for “*.txt in ~
 Quiz:
◦ Can you use find to locate a file called “needle” in your
haystack directory?
◦ Extra credit: what are the contents of the “needle” file?
Questions?

You might also like