command line interface (cli) csci n321 – system and network administration copyright © 2000, 2011...
TRANSCRIPT
![Page 1: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/1.jpg)
Command Line Interface (CLI)
CSCI N321 – System and Network Administration
Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University
![Page 2: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/2.jpg)
Section Overview
X WindowsConsoles and TerminalsUNIX CommandsUNIX Filesystemvi Editor
![Page 3: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/3.jpg)
References
CQU COIT13146 System Administration Course Chapter 4 Chapter 5
![Page 4: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/4.jpg)
X Windows
Familiar GUI interfaceVirtual screensRemote applicationsX-Terminal Windows Multiple concurrent session Scroll bars Cut, Copy & Paste
![Page 5: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/5.jpg)
X Managers & Environments
X Window Managers Very configurable A lot of variety GUI login mode
X Window Environment Fully integrated environment Window manager runs within the
environment
![Page 6: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/6.jpg)
Why use the command line?
Always available GUI not installed/working Remote sessions
More efficientMore powerfulBetter understanding of what is happening
![Page 7: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/7.jpg)
UNIX Terminals
Old Days Hardwired – serial connections Modems – remote connections
Network – telnetConsole Monitor/keyboard/mouse on system Boot/error messages display Headless servers
![Page 8: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/8.jpg)
Virtual Consoles in Linux
Multiple sessions on one consoleSpecial Consoles Console 1 – default console Console 7 – X Windows
Toggling between consoles Text mode - <Alt><Fn> X Windows - <Ctrl><Alt><Fn> <Fn>: Function Key (n = 1 .. 7)
![Page 9: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/9.jpg)
Basic Philosophy
10% of work solves 90% of problemsSmaller is betterPortabilitySolve at right level
Be Creative!!!
![Page 10: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/10.jpg)
Command Anatomy 101
command [-switches] [arg1] [arg2]…
Command: Name of the programSwitches: Modify command’s behavior Windows typically uses “/” instead of “-”
Arg#: Arguments passed to command
![Page 11: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/11.jpg)
Getting Help
Online manual availableSearchable Command/File name Type/Section Keyword
Not always easy to understand
![Page 12: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/12.jpg)
Man Page SectionsLinuxLinux ContentsContents
1 User commands
2 System calls
3 Library calls
5 File formats
7 Misc. files and documents
6 Games and demos
4 Devices/Network protocols
8 Administration commands
9 Kernel specs/interfaces (?)
![Page 13: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/13.jpg)
Using man
man command Look up command
man n intro Contents of section n
man –k string Search short descriptions (apropos)
man –K string Search all man pages for string
![Page 14: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/14.jpg)
Account Related Commands
login Start session
passwd Change Password
logout / exit Close session
![Page 15: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/15.jpg)
File/Directory Commands
Files cp – Copy mv –
Move/Rename rm – Remove cat – View all more – View page less – View page
Directories ls – List contents mv – Move/Rename cd – Change Dir pwd – Current Dir mkdir – Create rm/rmdir – Remove
![Page 16: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/16.jpg)
Copies, moves, and renaming
cp file1 file2|dir1 Copy file1 to file2 or into directory dir1
cp –r[p] dir1 dir2 Copy directory dir1 to dir2
mv file1 file2|dir1 Moves file1 to file2 or into directory dir1
Renames file1 to file2 if both in same directory
![Page 17: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/17.jpg)
Viewing files
cat file1 Display the contents of file1 to the
screen
more file1 Display the contents of file1 one
screen at a time
less file1 Same as more but more powerful
![Page 18: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/18.jpg)
Removing files and directories
rm file1 file2 ... Removes list of files
rmdir dir1 Removes dir1 only (if it is empty)
rm -r dir1 Removes dir1 and all
subdirectories/files VERY Dangerous!!!
![Page 19: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/19.jpg)
Other directory commands
ls [-la] [file/dir list] Lists files in a directory
mkdir dir1 Creates directory dir1
cd dir1 Makes dir1 the current directory
pwd Displays the current directory path
![Page 20: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/20.jpg)
Windows (MSDOS) File/Directory Commands
Files copy – Copy move – Move rename - Rename del – Remove type – View all more – View page
Directories dir – List contents xcopy – Copy move – Move rename - Rename cd – Change Dir md/mkdir – Create rmdir – Remove
![Page 21: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/21.jpg)
Linux Filesystem Hierarchy
/ (root)
bin var dev libusrrootbootetchomesbin
scott bobalice
n321 public_html
bin sbin local tmplib
man lib srcsharebin
![Page 22: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/22.jpg)
So many bins…
/ (root)
bin usrsbin
bin sbin local
sbinbin
bin directories: User programssbin directories: System programs/bin & /sbin – Needed at boot time/usr/bin & /usr/sbin – available when system fully operating
![Page 23: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/23.jpg)
Windows Files/Directories
UNIX/LinuxUNIX/Linux WindowsWindows
/usr %SystemRoot% (C:\Windows)
/bin & /usr/bin
%SystemRoot%\System32
/dev %SystemRoot%\System32\Drivers
/etc%SystemRoot%\System32\Config
Windows Registry (regedit)
/tmp C:\Temp
/var/spool %SystemRoot%\System32\Spool
Source: Principles of Network and System Administration by Mark Burgess
![Page 24: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/24.jpg)
Windows RegistryHierarchical database of all system settingsRegeditOrganization Hives – Top level Keys – Individual settings within a hive
HKEY_LOCAL_MACHINEHKEY_LOCAL_MACHINE
HKEY_CLASSES_ROOTHKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIGHKEY_CURRENT_CONFIG
HKEY_CURRENT_USERHKEY_CURRENT_USER
HKEY_USERSHKEY_USERS
![Page 25: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/25.jpg)
Relative & Absolute Paths
Absolute Path Given from “root” directory Example:
/usr/local/bin (Linux) c:\windows\system32 (Windows)
Relative Path ‘.’ – Current Directory ‘..’ – Parent Directory ‘~’ – Home Directory Example: ~/.. = /home
![Page 26: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/26.jpg)
Filter Commands
cat – View allmore – View pageless – View pagehead – View firsttail – View lastwc – word count
sort – Sort by fielduniq – Remove dupcut – Get fieldspaste – Merge Filesgrep – Search texttr – Replace text
![Page 27: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/27.jpg)
More or Less
cat file Displays entire file to screen MSDOS - type
more file Displays file one screen at a time Same in MSDOS
less – replacement for more
![Page 28: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/28.jpg)
Heads or Tails
head -# file Displays the first # lines of file1
tail -# file Displays the last # lines of file1
wc [-cwl] file Counts number of characters, words,
or lines in file
![Page 29: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/29.jpg)
Sorting
Lists the contents of a file based on ordersort file Sorts file alphabetically by line
sort -r file Sorts file in reverse order by line
sort –t: -n –k 3 file Sorts file based on the 3rd field –k 3) in numeric order (-n) with fields separated by ‘:’ (-t:)
MSDOS - find
![Page 30: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/30.jpg)
Extracting info
cut –f# [-d%] file Displays # fields separated by %in file awk is a more advanced replacement
grep search-string file Displays all lines with search-string in file
Can create very sophisticated search conditions
MSDOS - find
![Page 31: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/31.jpg)
Changing file contents
paste file1 file2 Merge contents of file1 and file2
line by line
tr c1 c2 < file Changes all occurrences of
character c1 to c2 in file
![Page 32: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/32.jpg)
Misc. Commands
date Set system time/date View (formatted) system time/date
cal Displays calendar
echo Display strings & shell variables Same in MSDOS
![Page 33: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/33.jpg)
Visual Editor (vi)
Very Powerful3 modes Command Insert ex (very similar to MSDOS edlin)
Can be frustrating to learn initiallyImportant to have cheat sheet handy
![Page 34: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/34.jpg)
emacs versus vi
Georgy says…
Slashdot (Asked by markhb): vi or emacs? Georgy:
I'm so glad you asked!! Both. vi for quick editing, emacs (NOT xemacs) for coding projects. :q!:q!:q!
Source: Slashdot.com, 8/20/2003
![Page 35: Command Line Interface (CLI) CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University](https://reader033.vdocument.in/reader033/viewer/2022051619/56649dea5503460f94ae5aa5/html5/thumbnails/35.jpg)
Why vi?!?!?!
Because it is always there!!!
©www.nicedog.com