I2rda Course Cheatsheet
Contents
-
ctrl + a: go to beginning of line -
ctrl + e: go to end of line -
ctrl + w: delete current word backwards, word behind if in space -
ctrl + /: undo changes -
ctrl + x, <BACKSPACE>: search backwards for a character, here? -
ctrl + r, ?: search backwards for a character, here? -
alt + b: move backwards word-wise. -
alt + f: move backwards word-wise -
alt + d: delete current word forwards, next word if in space -
ctrl + k: delete to end of line
Pagers: man, less and vim keys
- This is a continuous and very important activity
- Linux has a large and comprehensive documentation system called
man - Linux manual pages are referred to as man pages.
- To open the man page for a particular command, you just need to type man followed by the name of the command you are interested in.
- To browse through a man page, use the up,down,pgup and pgn keys.
- To close (quit) the man page simply hit the q key on your keyboard.
followed by the type of thing you are trying to do. An example of this is in exercise 1-3, part c).
Exercise
- Look up the manual information for the ls command by typing the following in a terminal:
man echo man mkdir
- What can you say about this command?
Now try:
man ls
- Did you think you knew this command already?
- What does the
-hoption do? What about the-aoption? What would runningls -lrtdo? - Press the
qkey when you want to quit reading the man page. - Try running
lsusing some of the options mentioned above.
- Look up some programs with man pages with the keywords "list directory"
man –k "list directory"
Linux shortcut symbols
-
.the directory you are currently in, often used with mv, cp or ln -s to mean "in here please" -
..the directory one level above the one you are currently in, aka. the parent directory
- - To change directory to the one above your are in:
cd ..
- To returns to the last directory you were working in before this one:
cd – - On its own,
cdbring you to your home directory -
~shorthand for your home directory, where all your data is kept. -
>directs output of one command into a file -
|often called the pipe operator: directs output of one command into another command.
Keybindings for using the history file
-
:<RET>: save command in history, do not execute. -
!$<RET>: the final argument of the last command -
!!<RET>: the entire last command -
!:1-$<RET>: everthing except the first word of the last command -
!$<RET>: the final argument of the last command -
^then^now<RET>: replace the first occurence of then in last command with now -
!!:gs/then/now/<RET>: replace the ALL occurences of "then" in last command with "now" -
!!:gs/then/now/:p<RET>: as above except do not execute.
An important note on line endings – CR and LF
- Besides spaces in filename, there is another major pitfalls when transferring file over to Linux.
- In Linux, the end of line is called a new line, symbol with
\n. - Windows uses
CRandLF.. called theDOSformat. - Old Macs used
LF - the tools
dos2unixandmac2unixconvert
Text editing
- There are very many text editors, but one of the most powerful and dependable is
vi. - It has a steep but tiny learning curve, which we hope to conquer in this section.
- "vi" is an old version and is available on all Unix/linux systems by default
- Vim is the modern version, it used
ncursesto use the whole screen - It's free and has graphical version call gvim and a Windows version too.
Using vim
- type
vimto get in, and:q!to get out without saving. -
ZZto save onto to current filename. ":sav fname" otherwise - It opens in "normal" mode which is similar to less, in that direct editing is not expected.
- This is changed by pressing
i. To get back to normal mode, press theESCkey. - In normal mode
uundoes any changes -
:while in normal mode allows command sto be entered - Visual: enabled by "v" or "V" (visual block), sub-box at the bottom open.
- After v or V, movement keys ":%" will operate on whole document, ":’a,’b" operate between two marks, ":42,45" between two line numbers
- search via "/", ":set hlsearch" to see all the hits
Getting by in only normal mode
- movement keys, "w" jump via start of words; "e" jump via ends; "fc" jump to next c
- "0" for start of line, "A" for end of line and into insert mode
- "x" delete current character, "xp" switch positions of current and next character
- "yyp" copy current line and paste it underneath
- "dd" delete line, "2d" delete this and following two lines. "dgg" delete to start, "dG" delete to end
- "dw" delete current word
- Command: Activated by ":", sub-box at the bottom open, rich command language
- Visual: Activated by "v" or "V" (visual block), sub-box at the bottom open, rich command language
Advanced but really useful commands
- ":colorscheme desert" chang to the desert colour scheme, "morning" "delek" many others
-
:%s/snooze/sneeze/gcalso works -
:g/sneeze/d delete all lines without sneeze" -
:v/sneeze/d delete all lines with sneeze" - ":42y[RET]p" paste line 42
- "d214G" delete to line 214
- "y214G" delete to line 214
-
:set list, all non-printing characters are also shown. -
:set hlsearch, will highlight all search occurences. -
:set nu, show line numbers.
Exercises
Type:
screen
Then:
-
ctrl+l, n: cycle through screen windows -
ctrl+l, :hardcopy RET: create a file with a copy of all inputs and outputs of your session. -
ctrl+l, d: detach screen session - type
screen -rto recover a detached - type exit to get out of your screen sessions