Logo  

CS469 - Linux and Unix Administration and Networking

Lesson 1

Conventions:

> ⟵ Normal user prompt

# ⟵ Super-user prompt (commands requiring super user (uid 0) access)

Often the super user in Linux and Unix systems is the account by the name of 'root', but that is only a convention. The super user (or priviledged) account may have any name so long as it is using the UID (user ID) of 0. A group ID of 0 has no special significance. Multiple usernames may have the same UID, including UID 0.

[ word ] ⟵ indicates that word is optional.

< word > ⟵ replace word with what it represents. Don't include the <>'s as part of word.

Unix Accounts:

To change your password, at a terminal prompt:

> passwd

To change your finger (identity) information (information that is viewed with the 'finger' command:

> chfn

Basic commands:

The man command:

> man [<section>] <command|config_file|topic>
> man -k <search>

Section What is found in that section
1 User Commands
2,3 System Calls / C Library Functions
4 Devices and Special Files
5 File Formats and Conventions
6 Games et. Al.
7 Miscellaneous
8 System Administration tools and daemons

example:

> man man

> info <command>

  • Like man, but for GNU utilities.

Other sources of documentation:

  • /usr/doc/*
  • /usr/src/linux/*
  • google.com or other less evil search engine
  • wikipedia.org

File and directory commands:

Command What it does
ls [<path>] List files
cd <dir> Change directory
cp <src> <dst> Copy files
mv <src> <dst> Rename / move files
rm <file> Remove file
mkdir <dir> Make a directory
rmdir <dir> Remove empty directory

Basic Networking and file copying:

Command What it does
ssh <user>@<host> Secure shell to another computer.
scp <src> <dst> Copy files using ssh
sftp <user>@<host> Secure FTP client
rsync <src> <dst> Like scp, but only copies changed files.

Editors:

Terminal based
vi Default editor for all Unix systems
vim Improved version of vi
elvis Alternative version of vi
emacs A full featured programmers editor with lisp configuration language
jove A simplified version of emacs
ne A Nice editor with code colorization and graphical drop-down menu system (Not standard in Slackware)
nano A basic text editor
pico Alternative to nano
Graphical based
kate KDE based programmers editor
atom Programmers editor
komodo Programmers editor geared towards web-development

Quiz 1

- Basic Unix commands quiz

Videos

Using vim:

vi is usually a link to vim or elvis. Vi is the default editor for Unix systems and a system administrator should learn to use it since it may be the only available editor on a newly installed system.

In vi there are 2 edit modes, 'command mode' & 'insert mode'. Use the escape key to switch back to command mode when in insert mode.

Command mode:

In command mode the letters you type are edit commands.

[<#>]<cmd>

  • Does the following command an optional <#> times:
    ex: 2dd - deletes 2 lines.

Movement:

Key What it does
←/h, ↓/j, ↑/k, →/l, Cursor movement keys.
w / b Forward/backword word at a time
0 / $ Move to beginning / end of line
H/M/L Top/Middle/Bottom of screen
G/1G Last / First line in file
Ctrl-f/b Forward/backward one screen
/search Search for <search> in file
n/N Repeat last search in same/opposite direction

Deleting:

Key What it does
x Delete character under the cursor
X Delete character before the cursor
dw Delete word under the cursor
dd Delete line the cursor is on
D Delete from cursor to end of line

Editing:

Key What it does
C Overwrite text from cursor to end of line (switches to insert mode)
i Insert text before cursor (switches to insert mode)
a Append text
o Open a new line below the cursor
O Open a new line above current line
J Join lines together
u Undo most recent edit
U Undo all edits on a single line
:w Write changes
:wq Save and quit (also ZZ)
:q Quit w/o saving
:q! Really quit w/o saving

Quiz 2

- Vi commands quiz

Basic wildcards:

  • Wild-cards are not regular expressions. They are expansions performed by the shell and can be "escaped" by either quoting them or back-slashing (\) the special characters.
Wildcard Example(s)

~ (tilde)

  • When at the beginning of a path, represents your home directory.

cd ~
cp xy ~/dir/

`~`*user*
  • Represents user's home directory, ex: ~user

cp ~user/public_html/cs469/code/xx .

* (asterisk)

  • matches zero or more characters

R*

  • Anything beginning with R.

*.txt

  • Anything ending in .txt

? (question mark)

  • Matches any single character

b???

  • Matches anything starting with b and exactly 4 characters in length.

[...] (brackets)

  • Like ?, but only matches any of the specified characters given within the brackets.
  • A character range can be specified with a dash (-) between
    two characters which specifies that it will match all ASCII characters
    between and including the two characters.

[a-z]

  • Matches any letter in the range a to z. Dash (-) must appear at the beginning or end or be escaped if you want an actual -.

cs469[0-9][0-9]

  • Starts with cs469 and ends with 2 digits.

[^...]

  • Matches any letter NOT listed.

*.[^ch]

  • Match all files with a single character extension except for .c or .h.

{<pattern>,<pattern>,...}

  • Matches any of the given patterns.

ls -la {a,[q-t],z}*

  • Match any files beginning with a, q through t, or z.

Quiz 3

- Basic wildcards quiz