Professional Documents
Culture Documents
02
Note - the domains will change somewhat in March 2015. SW RAID
with mdadm will be removed
** The Command Line
*** Editing text files on the CLI
Covers the use of the basic text editors nano and gedit as well
as the advanced editors _vi_ and _emacs_
- nano
simple CLI-based text editor
- gedit
simple GUI-based text editor
- *vi/vim*
- invocation
+ vi -r myfile :: start vi and edit myfile in recovery mode
after a system crash - vim stores your changes in a swap
file. Using the original file plus the swap file, you can
mostly recover your work.
+ vi myfile :: edit myfile with vi
- _command mode_
initial mode that vim starts in
- movement
+ hjkl :: Left Down Up Right
+ H :: move to top of screen
+ L :: move to bottom of screen
+ 0 :: move to beginning of line
+ $ :: move to end of line
+ :0 or 1G or gg :: move to beginning of file
+ :n or nG :: move to line 'n'
+ :10 :: move to 10th line
+ 10G :: move to 10th line
+ :$ or G :: move to last line in file
+ C-f :: move forward one page
+ C-b :: move back one page
+ /pattern :: forward search for 'pattern'
+ ?pattern :: reverse search for 'pattern'
+ n :: move to next occurrence of search pattern
+ N :: move to previous occurrence of search pattern
+ C-g :: show position and line no; type _nG_ to go to
line number `n`
- editing
+ a :: append text after cursor
+ A :: append text at end of current line
+ I :: insert text at the beginning of current line
+ i :: insert text before cursor
+ o :: start new line below current line, insert text
+ O :: start new line above current line, insert text
+ Nx :: delete N chars, starting at current position
+ dw :: delete the word at the current position
+ D or d$ :: delete the rest of the current line
+ Ndd or dNd :: delete N lines
+ u :: undo the previous operation
+ C-R :: redo
+ yy :: yank(copy) the current line and put in buffer
+ Nyy or yNy :: yank N lines and put in buffer
+ p :: put after the current line
+ P :: put before the current line
- _insert mode_
from command mode, press 'i' to enter Insert mode
- _line mode_
from command mode, press ':' to enter Line mode
+ :r file2 :: read in file2 and insert at current position
+ :w :: write to the current file in buffer
+ :w myfile :: write out the file to myfile
+ :w! file2 :: overwrite file2
+ :x :: exit vi and write out modified file
+ :wq :: exit vi and write out modified file
+ :ZZ :: same as ':x', ':wq' save and exit vi
+ :q! :: quit vi without saving changes
+ external commands
+ :! wc % :: word count of current file (%)
+ :sh cmd :: open an external cmd shell; upon exit
resume vi session
+ %!fmt :: run current file through fmt and return results
- *emacs*
As emacs is our editor of choice, we know most of the
commands required for daily usage. We are only making note
of those cmds were weren't aware of previously
- C-o :: insert a blank line
- C-@ :: same as C-space (set mark)
- M-g-g-n :: goto line n
*** Manipulating text files on the CLI
- I/O Redirection
- read from '<'
- write to '>'
- append to '>>'
- Viewing files
- cat :: list file on stdout (no scrollback)
- tac :: list file on stdout in reverse order (no scrollback)
- less :: useful for viewing larger files as it provides scrollback
pauses at each screenful of text
- head :: print first 10 lines of a file by default
- tail :: print last 1o lines of a file by default
- head -n X | tail -n Y :: view a range of lines from text on stdin
+ _head -n 22 | tail -n 11_
Display from lines 12 to 22, inclusive. Note that _tail_ must
show the last *11* lines (22,21,20,19,18,17,16,15,14,13,12)
starting from 22 in order for line 12 to be included.
0-9: 10 numbers, 0-10: 11 numbers, 12-22: 11 numbers
- Manipulating Text
- cat :: concatenate - read, print, join, view files
+ cat file1 file2 :: concatenate multiple files and display output
+ cat file1 file2 > newfile :: concatenate multiple files and
redirect output to newfile (overwrites)
+ cat file >> file2 :: append file to end of file2
+ cat > file :: interactive mode; redirect stdin to file
Ctrl-d to terminate input
+ cat >> file :: interactive mode; append stdin to file
Ctrl-d to terminate input
- Formatting filesystems
- ext2/3/4 filesystems
- mkfs
- XFS and btrfs filesystems
- Mounting filesystems automatically at boot time
you need to add an entry in /etc/fstab and make sure that the
mountpoint exists
- Mounting networked filesystems
1. NFS client config
_mount -t nfs(nfs4) -o servername:/remoteDir /local/mntpt_
2. Add NFS mount to /etc/fstab
_server:/remote/export /local/mntpt nfsType options 0 0_
_servername:/music /local/music nfs4 rsize=8192,wsize=8192,timeo=1
4,_netdev 0 0_
+ nfsTypes are _nfs_ (for nfs2,3) and _nfs4_
+ rsize :: the number of bytes used when reading from the server
+ wsize :: the number of bytes used when writing to the server
+ timeo :: the amount of time, in tenths of a second,
to wait before resending a transmission after an RPC timeout
+ _netdev :: wait until the network is up before
trying to mount the share. systemd assumes this for NFS,
but anyway it is good practice to use it for all types of
networked file systems
- Partitioning storage devices
- Troubleshooting filesystem issues
- *Linux Filesystem Tree Layout* (LFS201 topic)
- Linux Filesystem Hierarchy
+ /bin
+ /sbin
+ /lib
+ /usr/bin
+ /usr/sbin
+ /usr/lib
- *Linux Filesystems and the VFS* (LFS201 topic)
- Virtual Filesystems
+ /proc
+ /sysfs
- *Encrypting Disks with LUKS* (LFS201 topic)
+ create a LUKS partition
1. _cryptsetup luksFormat /dev/sdaX_
2. _cryptsetup open --type luks /dev/sdaX LUKSname_
** Local system administration
- Creating backups
t
+ tar cvf(z)
- Restoring backed up data
+ tar xvf(z)
- Creating local user groups
+ groupadd groupName
- Managing user accounts
+ user management
+ cat /etc/group
+ usermod :: modify user account
+ -a :: add to group
+ -G :: used with -a
+ group management
+ groupmod :: modify group definition
** Shell scripting
- Basic Shell Scripting
** Software Management
- Installing software packages
+ RPM
+ DPKG
+ yum
+ APT