Introduction to Linux
“Linux at the Command Line”
Meo Academia
What is
Linux?
It’s an
Operating
System
Today more than 97 percent of the world's
supercomputers (including the complete top 10),
more than 80 percent of all smartphones, many
millions of desktop computers, around 70
percent of all web servers, a large chunk of tablet
computers, and several appliances (dvdplayers,
washing machines, dsl modems, routers, self-
driving cars, space station laptops...)
run Linux. Linux is by far the most commonly
used operating system in the world.
Linux kernel version 4.0 was released in April
2015. Its source code grew by several hundred
thousand lines (compared to version 3.19 from
February 2015) thanks to contributions of
thousands of developers paid by hundreds of
commercial companies including Red Hat,
Intel, Samsung, Broadcom, Texas Instruments,
IBM, Novell, Qualcomm, Nokia, Oracle,
Google, AMD and even Microsoft (and many
more).
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.
Linux Has Many Distributions
Linux Has Many Distributions
Oracle Enterprise Linux is a
free version of RedHat
Enterprise Linux with the
trademarks removed
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
are the GNU utilities.
Torvalds and others
http://www.gnu.org/
AND
What is Linux?
“Small programs that do one thing well”
(see unix-reference.pdf)
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
What is Linux?
“Small programs that do one thing well”
We will not cover the commands below in this
class, but you need to know them. See the man
pages for the process commands and the “sge”
folder inside of the “cheat sheets and tutorials”
folder for the SGE (Sun Grid Engine) command
tutorials: qsh-interactive.pdf, qsh-interactive-
matlab.pdf, qsub-batch.pdf, qsub-batch-matlab.pdf,
and qstat-qhost.pdf.
Process Management: ps, top, kill, killall, fg, bg
SGE Cluster: qsh, qstat, qsub, qhost
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
Mobax
https://mobaxterm.mobatek.net/download
-home-edition.html
If you don’t need windowing, “putty” is
good:
http://www.chiark.greenend.org.uk/~sgtat
ham/putty/download.html
Connection Problems
When there are problems connecting to a login host, try:
Open cmd and test one of the below
ping machine
telnet machine 22
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 BU systems, including the BU 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)
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?
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?
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
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)
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)
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
The permissions on files and directories span fou
Symbolic Notation
SCO SYM
DESCRIPTION
PE BOL
User u The owner of the file or directory
Grou The group of users to who can access the
g
p file or directory
Othe
o Other users (world)
r
All a All users
File System Ownership and
Permissions
CHANGE IN USER CHANGE IN CHANGE IN
COMMAND IN SYMBOLIC NOTATION (U) GROUP (G) WORLD (O)
PERMISSIONS PERMISSIONS PERMISSIONS
chmod +x foo ✓ Execute ✓ Execute ✓ Execute
☐ Read ☐ Read ☐ Read
chmod a=x foo ☐ Write ☐ Write ☐ Write
✓ Execute ✓ Execute ✓ Execute
chmod u-w foo ☐ Write (No change) (No change)
✓ Read
✓ Write
chmod u+wx,g-x,o=rx foo ☐ Execute ☐ Write
✓ Execute
✓ Execute
File System Ownership and
Permissions
Here are some examples of chmod usage with octal
notation:
COMMAND IN OCTAL CHANGE IN USER (U) CHANGE IN GROUP (G) CHANGE IN WORLD (O)
NOTATION PERMISSIONS PERMISSIONS PERMISSIONS
✓ Read ✓ Read ✓ Read
chmod 777 foo ✓ Write ✓ Write ✓ Write
✓ Execute ✓ Execute ✓ Execute
✓ Read ☐ Read ☐ Read
chmod 501 foo ☐ Write ☐ Write ☐ Write
✓ Execute ☐ Execute ✓ Execute
☐ Read ✓ Read ✓ Read
chmod 365 foo ✓ Write ✓ Write ☐ Write
✓ Execute ☐ Execute ✓ Execute
☐ Read ✓ Read ✓ Read
chmod 177 foo ☐ Write ✓ Write ✓ Write
✓ Execute ✓ Execute ✓ Execute
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)
Finish