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

Introduction to Linux

The document provides an overview of Linux, its philosophy, and various commands for navigating and managing the Linux operating system. It covers connecting to Linux hosts, the structure of the Linux file system, and essential commands for file manipulation and system information retrieval. Additionally, it introduces tools for editing output and managing permissions within the Linux environment.

Uploaded by

SAIKO HARSH YT
Copyright
© © All Rights Reserved
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 overview of Linux, its philosophy, and various commands for navigating and managing the Linux operating system. It covers connecting to Linux hosts, the structure of the Linux file system, and essential commands for file manipulation and system information retrieval. Additionally, it introduces tools for editing output and managing permissions within the Linux environment.

Uploaded by

SAIKO HARSH YT
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Linux Essentials: From Novice

to Navigator

“Linux at the Command Line”


Ayan Ghosh,
Assistant Professor, Dept of Information Science
MAKAUT,WB
What is
Linux?

It’s an
Operating
System
What is Linux?
? Linux is a Unix clone written from scratch by
Linus Torvalds with assistance from a
loosely-knit team of hackers across the Net.
? Unix is a multitasking, multi-user computer
operating system originally developed in
1969 by a group of AT&T employees at Bell
Labs.
? Linux and Unix strive to be POSIX compliant.
? 64% of the world’s servers run some variant
of Unix or Linux. The Android phone and the
Kindle run Linux.
The Linux Philosophy
The *Nix Philosophy of Doug McIlroy
(i) Make each program do one thing well. To do a new
job, build afresh rather than complicate old programs
by adding new features.
(ii) Expect the output of every program to become
the input to another, as yet unknown, program. Don't
clutter output with extraneous information. Avoid
stringently columnar or binary input formats. Don't
insist on interactive input.
(iii) Use tools in preference to unskilled help to
lighten a programming task, even if you have to
detour to build the tools and expect to throw some of
them out after you've finished using them.
Linux Has Many
Distributions
What is Linux?
Linux + GNU Utilities = Free
Unix

?a set of small programs


? Linux is an O/S core written by Richard
written by Linus Stallman and others. They
Torvalds and others are the GNU utilities.
http://www.gnu.org/
AND
What is Linux?
“Small programs that do one thing well”

? Network: ssh, scp, ping, telnet, nslookup, wget


? Shells: BASH, TCSH, alias, watch, clear, history, chsh, echo, set,
setenv, xargs
? System Information: w, whoami, man, info, which, free, echo,
date, cal, df, free, man, info
? Command Information: man, info
? Symbols: |, >, >>, <, &, >&, 2>&1, ;, ~, ., .., $!, !:<n>, !<n>
? Filters: grep, egrep, more, less, head, tail
? Hotkeys: <ctrl><c>, <ctrl><d>
? File System: ls, mkdir, cd, pwd, mv, ln, touch, cat, file, find,
diff, cmp, /net/<hostname>/<path>, mount, du, df, chmod, find
? Line Editors: awk, sed
? File Editors: vim, gvim, emacs –nw, emacs
? Process Management: ps, top, kill, killall, fg, bg
? SGE Cluster: qsh, qstat, qsub, qhost
Connecting to a Linux Host
? You need a “xterm” emulator: software that
emulates an “X” terminal and connects using the
“SSH” secure shell protocol.
? You are sitting at the “client,” either a Windows,
Macintosh or even possibly a Linux machine.
? You are connecting to a “server,” typically the
“head” or “gateway” node of a cluster of
computers. You will be working on the head node
or submitting jobs to execution nodes, all of them,
Linux machines.
? You can also connect to a Linux machine by using
VNC to get a whole desktop if it’s supported by the
server.
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
●If you don’t need windowing, “putty” is
good:
http://www.chiark.greenend.org.uk/~sgtat
ham/putty/download.html
●If you need windowing, use StarNet “X-
Win32:”
http://www.bu.edu/tech/desktop/site-licens
ed-software/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!
Let the Linux Lab Begin!

Your Instructor Today

The Ideal Lab Facility


Connecting to a Linux Host -
Mac OS X Client
?Terminal
◦Type ssh –X <domain> or ssh –Y <domain> (less secure)
Connection Problems
When there are problems connecting to a login host, try:
? ping <server ip>
? telnet <server ip> <port no>
Connecting to a Linux Host:
Send and Email
? Try
◦ telnet localhost 25
●ehlo me
●mail from:<your email address>
●rcpt to:<destination email address>
●data
●Subject:<subject of email>
●<Body of email>
●.
●<CR>
? What Happened?
Connecting to an Linux Host
Send and Email
The Shell
? A shell is a computer program that interprets the commands
you type and sends them to the operating system. Secondly, it
provide a programming environment consisting of environment
variables.
? Most Linux systems, including the Linux Cluster, support at
least two shells: TCSH and BASH. The default shell for your
account is TCSH. The most popular and powerful Linux shell
today is BASH.
? To determine your shell type:
◦ echo $SHELL (shell prints contents of env
◦ echo “$SHELL” (shell still processes env. variable)
◦ echo ‘$SHELL’ (shell treats env. variable as simple literal)
? The complete environment can be printed with set, setenv
(TCSH) and set (BASH).
? To determine the path to the shell program, type:
◦ which bash
◦ which tcsh
? Change the shell with “chsh /bin/bash” (provide path to new
shell as a “parameter,” meaning to be explained soon)
The Shell
Output of the echo, which and chsh commands
System Information
? After you connect, type
◦ shazam
◦ whoami
◦ hostname
◦ date
◦ cal
◦ free
? Commands have three parts; command, options and parameters.
Example: cal –j 3 1999. “cal” is the command, “-j” is an option
(or switch), “3” and “1999” are parameters.
? Options have long and short forms. Example:
◦ date –u
◦ data --universal

What is the nature of the prompt?


What was the system’s response to the command?
System Information
Output of the whoami, hostname, date, cal and free
Command History and Simple
Command Line Editing
? Try the history command
? Try <Ctrl><r> (only works in BASH shell)
? Choose from the command history by using
the up ↑ and down ↓ arrows
? What do the left ← and right → arrow do on
the command line?
? Try the <Del> and <Backspace> keys
Help with Commands
? Type
◦ hostname –-help
◦ man hostname
◦ info hostname (gives the same or most
information, but must be paged)
? And “Yes,” you can always Google it
Connect Commands Together with
the Pipe Symbol “|” and Using Filters
? The pipe “|” feeds the OUTPUT of one
command into the INPUT of another
command. Our first example will use the pipe
symbol to filter the output of a command. Try:
◦w
◦ w | grep ‘root’
◦ ps -e -o ruser,comm | grep 'tut‘
? The ps command is using both “options
(dash)” and parameters
? Try both “man grep” and “info grep”. See
the difference?
Editing the Command Line with
Emacs Keys
? <Ctrl-a> go to beginning
? <Ctrl-e> go to end
? <Alt-f> forward one word
? <Alt-b> back one word
? <Ctrl-f> forward one character
? <Ctrl-b> back one character
? <Ctrl-d> delete character
? <Alt-d> delete word
? <Ctrl-u> delete from cursor to beginning of line
? <Ctrl-k> delete from cursor to end of line

Go to through command history in shell and practice editing.


The Linux File System
? The *Nix (Unix or Linux) file system is a hierarchical
directory structure
? The structure resembles an upside down tree
? Directories are collections of files and other
directories. The structure is recursive with many
levels.
? Every directory has a parent except for the root
directory.
? Many directories have children directories.
? Unlike Windows, with multiple drives and multiple file
systems, a *Nix system only has ONE file system.
? The Linux Standard Base (LSB) specifies the structure
of a Linux file system.
The Linux File System
A Typical Linux File System
Examining the File System
? Try
◦ nautilus –-browser –-no-desktop
◦ tree –L 3 –d / | less
◦ tree –L 3 / | less
◦ file /bin/alsac then press <tab>
◦ cd ~; pwd (This is your home directory where
application settings are kept and where you have write
privileges)
◦ ls
◦ mkdir myPics;mkdir myPics/work;mkdir
myPics/friends;mkdir myPics/friends/BU; mkdir
myPics/friends/MIT
◦ tree myPics
Examining the File System
Output from the tree, file, pwd and ls commands
Demonstration of using the mkdir command
Navigating the File System
? There are two types of pathnames
◦ Absolute (Abs) – the full path to a directory or file; begins with
the root symbol /
◦ Relative (Rel) – a partial path that is relative to the current
working directory
? Examples
◦ Abs cd /usr/local/lib
◦ echo $HOME (one of may environment variables maintained by
the shell)
◦ Abs cd `echo $HOME`
◦ pwd
◦ Rel cd ..
◦ Rel cd ..
◦ Abs cd /lib (location OS shared libraries)
◦ ls –d */ (a listing of only the directories in /lib)
Navigating the File System
Moving around the file system using the cd command
Modifying the Linux File
System
? More useful commands
◦ cd (also takes you to your home directory like cd ~)
◦ mkdir test
◦ echo ‘Hello everyone’ > test/myfile.txt
◦ echo ‘Goodbye all’ >> test/myfile.txt
◦ less test/myfile.txt
◦ mkdir test/subdir1/subdir2 (FAILS)
◦ mkdir -p test/subdir1/subdir2 (Succeeds)
◦ mv test/myfile.txt test/subdir1/subdir2
◦ rmdir test (FAILS)
◦ rm –Rv test (Succeeds)
Modifying the Linux File System
Demonstration of the mkdir, less, mv, rmdir and rm commands
The List Command
? Useful options for the “ls” command:
◦ ls -a List all file including hidden file 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 –lh Give human readable file sizes
◦ ls –lS Sort files by file size
◦ ls –lt Sort files by modification time
File System Ownership and
Permissions
? All files and directories have a individual
and a group ownership.
? All files and directories have read (r), write
(w), and execute (x) permissions assigned
as octets to the individual owner (u), the
group (g) owner and all others (o) that are
logged into the system.
? You can change permissions if you are the
individual owner or a member of the group.
? Only root can change ownership.
root
The root user is the master
File and Directory Ownership
and Permissions
? Try
◦ cd
◦ touch myfile (create file)
◦ mkdir mydir (create directory)
◦ ls –l myfile (examine file)
◦ ls –ld mydir (examine directory)
◦ chmod g+w myfile (add group write permission)
◦ ls –l myfile
◦ chmod ugo+x myfile (add user, group and other execute
permission)
◦ ls –l myfile
◦ chmod ugo+w mydir (add user, group and other write permission)
◦ ls –ld mydir
◦ chmod a-w (a=ALL, remove user, group and other write
permission)
File and Directory Ownership and Permissions
Examining and changing file and directory permissions
Editing Output Lines With awk

? Syntax:

BEGIN { Actions}
{ACTION} # Action for every line in a file
END { Actions }
? Try

◦ls –l /usr
◦ls –l /usr | awk ‘{print $9 “\t” $5}’
◦ls –l /usr > usr.txt
◦awk ‘print $9 “\t” $5}’ usr.txt (gives same results as 2 nd
command line, but awk is acting on a file instead of saved
output)
◦ls –lh /lib | awk ‘{printf “%20s\t%s\n”,$9,$5}’
◦ls –l /lib | awk ‘BEGIN {sum=0} {printf “%20s\t%s\n”,
$9,$5; sum+=$5} END{sum/=1000000; printf “\nTotal:
%d GB\n”,sum}’
Editing Output Lines With awk
Output from awk commands
Editing Output Lines With sed
? sed replaces one substring with another
? sed operates on every line in a file or processes
every line piped into it
? sed matches patterns using regular expressions
(See regular-expressions.pdf cheat sheet)
? Common regular expression metacharacters:
◦ . – any character
◦ ? – quantified zero or one
◦ * - quantifier none or more
◦ + - quantifier one or more
◦ ^ - beginning of line
◦ $ - end of line
◦ [XxYy] – character class matching upper or lower case “X”
or “”Y”
Editing Output Lines With sed –
continued
? Try
◦ echo “The rain in Spain stays mainly in the
plain.” > easy_sed.txt; cat easy_sed.txt
◦ sed –i.bak
‘s/rain/snow/;s/Spain/Sweden/;s/plain/mountains
/’ easy_sed.txt; cat easy_sed.txt
◦ ls -l /lib | awk 'BEGIN {sum=0} {printf "%s\t%s\
n",$9,$5; sum+=$5} END{printf "\nTotal: %d\
n",sum}' | sed -e 's/\.so\(\.[0-9]*\)*//' | less
(challenge: get rid of soname extension)
◦ ls -l /lib | awk 'BEGIN {sum=0} {printf "%s\t%s\
n",$9,$5; sum+=$5} END{printf "\nTotal: %d
GB\n",sum}' | sed -e 's/\.so\(\.[0-9]*\)*//' | awk
'{printf "%20s\t%s\n",$1,$2}‘ | less (pretty print)
Editing Output Lines With sed
Output from sed commands
Editing Files with Emacs and Vim
You don’t have to take sides and there is always “nedit”
Editing Files with Emacs and Vim
? Movement: <C-b>,<C-n>, ? Movement: <h>,<j>,
<C-p>,<C-f>,<M-b>,<M- <k>,<l>,<b>,<e>,<0>,<
e>,<C-a>,<C-e>,<M-’<‘
$>,<gg>,<G>
>,<M-’>’ >,
? Change/Delete/Replace: <C-
? Change/Delete/Replace:
d>,<M-d-esc>,<M-d>,<C- <x>,<cw>,<dw>,<dd>,<
kk>,<C-d’char’>,<Insert> r>,<R>
? Copy/Paste: <C-space>,<C- ? Copy/Paste:
y>,<C-_>,<M-w>,<C-aky> <v>,<P>,<u>,<y>,<yy>
? Search/Replace: <C-s ? Search/Replace:
enter>,<C-s>,<C-r>,<M-x, </>,<n>,<N>,<:
‘replace-
%s/’regex’/’replacement’/
string’<CR>’srchstr’<CR>’re
placement’<CR> g>
? Save/Quit: <C-xs>,<C- ? Save/Quit:
xw>,<C-xc,’n’,’yes’<CR>> <:q>,<:w>,<:q!>
Emacs – Control Keys Vim – Modal
C=Ctrl and M=Meta (Alt) Cmd, Insert, and Visual
Mission Possible: Editing Files with Emacs and Vim
• Someone has corrupted Edgar Allen Poe’s poem, “The Raven.” Your
mission, should you decide to accept it, is to repair the damage
with emacs or vim and then confirm with the “diff” command.
Hint: Also use diff to find corruption.

• emacs –nw bad-the-raven.txt


or
• vim bad-the-raven.txt

• After editing and saving your file, confirm you work with:
• diff bad-the-raven.txt good-the-raven.txt
Finis

You might also like