Beruflich Dokumente
Kultur Dokumente
1 / 30
Introduction Working on the command line Manuals Essential command line tools
2 / 30
Introduction Working on the command line Manuals Essential command line tools
Introduction Working on the command line Manuals Essential command line tools
Introduction Working on the command line Manuals Essential command line tools
5 / 30
Introduction Working on the command line Manuals Essential command line tools
Introduction Working on the command line Manuals Essential command line tools
Modern times
In todays graphical world, we have terminal emulators, like xterm gnome-terminal rxvt ...
7 / 30
Introduction Working on the command line Manuals Essential command line tools
Modern times
These terminal emulators run text-based applications. The most fundamental types of such applications are shells, like bash tcsh zsh ...
Introduction Working on the command line Manuals Essential command line tools
Lets assume you are running bash. bash is program, namely a shell meant for interactive use bash is also a powerful scripting language
9 / 30
Introduction Working on the command line Manuals Essential command line tools
When it starts, it runs one or more scripts: When started as an interactive login shell:
/etc/profile ~/.bash profile, ~/.bash login, or ~/.profile
10 / 30
Introduction Working on the command line Manuals Essential command line tools
Lets start with what you see: bbbart@tuxitree:~$ bbbart : my username tuxitree : computers hostname : present working directory ( is the home directory) $ : this means I am not root
11 / 30
Introduction Working on the command line Manuals Essential command line tools
You can change the look of this prompt! Why would you do so? it looks cool; its useful to keep track of system information; dierent machines/users can get dierent colours; have information about work environment available at all time; to quickly spot the prompt when you use scrollback; ...
12 / 30
Introduction Working on the command line Manuals Essential command line tools
\u : users username \h : computers hostname \w : present working directory \$ : $ when user is not root, # when user is root
13 / 30
Introduction Working on the command line Manuals Essential command line tools
Try the following command (put it on one line with spaces in between):
14 / 30
Introduction Working on the command line Manuals Essential command line tools
Keyboard shortcuts
Some useful keyboard shortcuts: tab : autocomplete from the cursor position ctrl-a : move cursor to the line start ctrl-c : send the SIGINT signal to the current task ctrl-d : send an EOF marker (if the line is empty) ctrl-e : move cursor to the line end ctrl-k : clear the line after the cursor ctrl-l : clear the screen content ctrl-u : clear the line before the cursor ctrl-z : send the SIGTSTP signal to the current task
15 / 30
Introduction Working on the command line Manuals Essential command line tools
Stream redirecting
Remember the streams to interact with a terminal (stdin, stdout, stderr). You can redirect them!
16 / 30
Introduction Working on the command line Manuals Essential command line tools
Piping
You can also pipe streams to link commands: $ program1 | program2 is the same as $ program1 > tempfile $ program2 < tempfile $ rm tempfile
17 / 30
Introduction Working on the command line Manuals Essential command line tools
Piping
18 / 30
Introduction Working on the command line Manuals Essential command line tools
DRY is also a principle on the shell: and : navigate through your history ctrl-r : search the command history history : print your recent history !<n> : repeat command number <n> !! : repeat the last command !$ : special variable that contains the last word of the previous command
19 / 30
Introduction Working on the command line Manuals Essential command line tools
Before we begin. . .
The most important command youll ever learn, is man: man : format and display the manual pages Most manual pages contain a synopsis of the command in question: mysql [options] db name mysql can take some options but has to have a name of a database as argument xpdf [options] [PDF-file [page | +dest]] xpdf can take some options and a PDF-le as arguments. If you pass a PDF-le as argument you can also give it a page or a destination, preceded by a +-symbol. Now check the synopsis of the ssh command.
20 / 30 Bart Van Loon Command line essentials
Introduction Working on the command line Manuals Essential command line tools
21 / 30
Introduction Working on the command line Manuals Essential command line tools
cut
Name : cut Description : remove sections from each line of les Synopsis : cut OPTION... Useful options: -d DELIM : use DELIM instead of TAB for eld delimiter -f LIST : select only these elds A LIST is made up or ranges separated by commas. A range is N, N-, N-M or -M. [FILE]...
22 / 30
Introduction Working on the command line Manuals Essential command line tools
du
Useful options: -c : produce a grand total -s : display only a total for each argument -h : print sizes in human readable format
23 / 30
Introduction Working on the command line Manuals Essential command line tools
grep
Name : grep Description : print lines matching a pattern Synopsis : grep [OPTIONS] PATTERN [FILE...] Useful options: -i : ignore case distinctions in the PATTERN -v : invert the sense of matching, to select non-matching lines -n : prex each line of output with the 1-based line number within its input le
24 / 30
Introduction Working on the command line Manuals Essential command line tools
head
Name : head Description : output the rst part of les Synopsis : head [OPTION]... [FILE]...
25 / 30
Introduction Working on the command line Manuals Essential command line tools
nice
Name : nice Description : run a program with modied scheduling priority Synopsis : nice [OPTION] [COMMAND [ARG]...]
26 / 30
Introduction Working on the command line Manuals Essential command line tools
sort
Name : sort Description : sort lines of text les Synopsis : sort [OPTION]... [FILE]...
Useful options: -h : compare human readable numbers -n : compare according to string numerical value -r : reverse the result of comparisons -u : output only the rst of an equal run
27 / 30
Introduction Working on the command line Manuals Essential command line tools
tail
Name : tail Description : output the last part of les Synopsis : tail [OPTION]... [FILE]...
Useful options: -f : output appended data as the le grows -n K : print the last K lines instead of the last 10
28 / 30
Introduction Working on the command line Manuals Essential command line tools
wc
Name : wc Description : print newline, word, and byte counts for each le Synopsis : wc [OPTION]... [FILE]...
29 / 30
Introduction Working on the command line Manuals Essential command line tools
References
30 / 30