• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/98

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

98 Cards in this Set

  • Front
  • Back
bash (descr.)

bsh (descr.)
bash (descr.)
Bourne Again Shell
base on earlier Bourne shell but extended
The most commong default shell

bsh (descr.)
Bourne shell
bsh is base for bash
not often used in linux
tcsh (descr.)

csh (descr.)
tcsh (descr.)
based on C shell (csh)
no major Linux distro use it

csh (descr.)
original C shell
not used on Linux
ksh (descr.)

zsh (descr.)
ksh
The Korn shell
Combines Bourne shell and C shell

zsh
The Z shell
incorporates features from earlier shells and adding still more
What is the file /bin/sh
is a symbolic link to the system's default shell
normaly this is /bin/bash for Linux
for the most part, Linux cmd are ____________________
a few commands are _______ to the shell
for the most part, Linux cmd are EXTERNAL - separate programs from the shell. A few commands are INTERNAL to the shell
change the working directory
cd
cd /home/sally
what ~ stands for
~ is a shortcut it stands for your home directory
cd ~
will have the same effect as
cd /home/sally
display a line of text cmd
execute a program cmd
echo Hello
exec myprog
in most cases executing a program is better done by typing the name of the program
"time" cmd
time cmd
times how long subsequent cmd takes t oexecutre
time pwd - tells you how long the system took to execute
Three times are displayed: total executin time
user CPU time
system CPU time
"set" cmd
set
in its most basic form set displays a wide variety of options relating to bash
PATH enviorment varialbe
When you type a cmd that is not recognized by the sjell as one of its internal cmds, the shell checks its path to fina a program by that name to execute it.
Define by the PATH enviroment variable.
You can adjust by changing the PATH enviorment
Warning for PATH
root’s path should never include the current directory
./.
Placing this directory in root’s path makes it possible for a local miscreant
to trick root into running replacements for common programs, such
as ls, by having root change into a directory with such a program. Indeed,
omitting the current directory from ordinary user paths is also generally a
good idea. If this directory must be part of the ordinary user path, it should
appear at the end of the path so that the standard programs take precedence
over any replacement programs in the current directory
command completion
Type part of a command
or (as an option to a command) a filename, and then press the Tab key. The shell tries to fill
in the rest of the command or the filename.
history
Another helpful shell shortcut is the history. The history keeps a record of every command you type (stored in ~/.bash_history in the case of bash).
open termina in Ubuntu
Ctrl + Alt + T

Dash -> More Apps -> 'See More Results' -> Terminal

Dash -> More Apps -> Accessories -> Terminal
xterm (cmd)
will launch the xterm shell
touch <file name>

clear (cmd)
create a brand new blank file

clears terminal window
shutdown linux cmd
and
how to reboot?
sudo shutdown -h now
sudo shutdown -h 0
sudo shutdown -h 18:45 "Server is going down for maintenance"

Please note that you can also use halt or poweroff or reboot command for stopping and restarting the system:
$ sudo halt
$ sudo poweroff
How do I reboot computer?
sudo shutdown -r 0
sudo reboot
using command history
CTRL + R - backward search
CTRL + S - forward search
CTRL + G - terminates search
move within the command line
CTRL + A/CTRL + E
moves cursor to the start or end of the line
<- and -> move the cursor a character at a time same as (CTRL+B and CTRL+F)
CTRL+K - del. all text from current cursor to the end of line
invoka an editor
lanch full editor by pressing
CTRL + X followed by CTRL + E
Bash shell attempts to launch the editor defined by the $FCEDIT or $EDITOR
delete a file <cmd>
rm -f -r {file-name}

■-f: Forcefully remove file
■-r: Remove the contents of directories recursively
main user config file for bash

main global config file for bash
main user config file for bash
~/.bashrc
~/.profile
main global config file for
bash
/etc/bash.bashrc
/etc/profile
cmd to learn about man itself
man man
for instance, passwd has entries
under both section 1 and section 5. In most cases, man returns the entry in the lowest-numbered
section; but you can force the issue by preceding the keyword by the section number.What cmd does that
man 5 passwd
Some programs have moved away from man pages to info pages. The basic purpose of
info pages is the same as that for man pages, but info pages use a hypertext format
info info
Redirecting Input and Output
echo $NNTPSERVER > nntpserver.txt
What creates a new file containing standard output. If the specified file
exists, it’s overwritten.
>
Appends standard output to the existing file. If the specified file
doesn’t exist, it’s created.
>>
Creates a new file containing standard error. If the specified file
exists, it’s overwritten.
2>
Appends standard error to the existing file. If the specified file
doesn’t exist, it’s created.
2>>
Creates a new file containing both standard output and standard
error. If the specified file exists, it’s overwritten.
&>
Sends the contents of the specified file to be used as standard
input.
<
Accepts text on the following lines as standard input.
<<
Causes the specified file to be used for both standard input and
standard output.
<>
what is /dev/null
This file is a device that’s connected to nothing; it’s used when you
want to get rid of data.
For instance, if the whine program is generating too
many error messages, you can type whine 2> /dev/null to run it and discard
its error messages.
tee command
his command splits standard input so that
it’s displayed on standard output and on as many files as you specify.

someprog | tee output.txt
data pipes (a.k.a. pipelines)
A pipe redirects the first program’s
standard output to the second program’s standard input and is denoted by a vertical bar (|):
$ first | second
general rule for files ending with ~
file ending with ~ denote backups files created by certain text editors
xargs [options] [command [initial-arguments]]

general usage
xargs cmd builds a comand from its standard input.

command - the cmd you want to executre
initial-arguments - list of argumentsyou want to pass to the cmd
options - xargs options
using xargs delete all file that end with ~
$ find ./ -name “*~” | xargs rm
The first part of this command (find ./ -name “*~”) finds all the files in the current
directory (./) or its subdirectories with a name that ends in a tilde (*~). This list is then
piped to xargs, which adds each one to its own rm command.
what is backtick (`)
Text within backticks is treated as a separate command whose results are substituted on the
command line.
$ rm `find ./ -name “*~”`
mac categories
1 Executable programs and shell commands
2 System calls provided by the kernel
3 Library calls provided by program libraries
4 Device files (usually stored in /dev)
5 File formats
6 Games
7 Miscellaneous (macro packages, conventions, and so on)
8 System administration commands (programs run mostly or exclusively
by root)
9 Kernel routines
uses for ` (backtick)
the text within backticks is treated as a separete cmd whose results are substituted on the cmd line

rm `fin ./ -name "*~"` - deletes all files ending with ~
cat (cmd)
links together an arbitrary number of files end to end and send the result to standard output

cat first.txt second.txt > combined.txt
Display line ends cmd

Number lines cmd
cat -E or
cat --show-ends
The result is dollar sign at the end of each file

cat -n
cat --number
Adds line numbers to the beginning of every line even empty
Number lines but not blank
cat -b
car --number-nonblank
adds a line numbers but it numbers only lines that contain text
cmd option that compresses groups of blank lines down to a single blank line
cat -s
cat --squeeze-blank
cmd option to display special character

cmd option that display most control and other special characters using carat (^) and M- notations
cat .. -T
cat .. --show-tabs

cat .. -v
cat .. show-tabs
join cmd (expl)
join command combines two files by matching the contents of specified fields within
the files. Fields are typically space-separated entries on a line, although you can specify
another character as the field separator with the -t char option, where char is the character
you want to use. You can cause join to ignore case when performing comparisons by
using the -i option.
join cmd example
ls1.txt
555-2397 Beckett, Barry
555-5116 Carter, Gertrude
ls2.txt
555-2397 unlisted
555-5116 listed

$ join listing1.1.txt listing1.2.txt
555-2397 Beckett, Barry unlisted
555-5116 Carter, Gertrude listed
paste cmd example
ls1.txt
555-2397 Beckett, Barry
555-5116 Carter, Gertrude
ls2.txt
555-2397 unlisted
555-5116 listed

$ paste listing1.1.txt listing1.2.txt
555-2397 Beckett, Barry 555-2397 unlisted
555-5116 Carter, Gertrude 555-5116 listed
paste (cmd)
paste command merges files line by line, separating the lines from each file with tabs

paste listing1.1.txt listing1.2.txt
Converting Tabs to Spaces (cmd)
expand

By default, expand assumes a tab stop every eight characters. You can change this spacing
with the -t num or --tabs=num option, where num is the tab spacing value.
Displaying Files in Octal (cmd)
od - octal dump

Displaying Files in Octal

od listing1.2.txt
0000000 032465 026465 031462 033471 072440 066156 071551 062564
Sorting Files (cmd)
sort

-f or --ignore-case
-M or --month-sort - sort by three-letter month abbr
-n or --numeric-sort
-k field or --key=field option. (The field can be two numbered fields separated by commas, to sort on multiple fields.)
$ sort -k 3 listing1.1.txt
Breaking a File into Pieces (cmd)
split

Split by bytes -b size or --bytes=size This option can have the usually undesirable consequence of splitting the file mid-line.
Split by bytes in line-sized chunks -C=size or --line-bytes=size option.
Split by number of lines The -l lines or --lines=lines
Translating Characters (cmd)
tr
You specify the characters you want replaced in a group (SET1) and the characters with
which you want them to be replaced as a second group (SET2). Each character in SET1 is
replaced with the one at the equivalent position in SET2
$ tr BCJ bc < listing1.1.txt
Converting Spaces to Tabs (cmd)
unexpand command is the logical opposite of expand; it converts multiple spaces to
tabs.
Deleting Duplicate Lines (cmd)
uniq

$ sort shakespeare.txt | uniq
Reformatting Paragraphs
fmt
If you want to clean up the file a bit, though, you can do so with fmt. If called with no options the program attempts to clean up paragraphs, which it assumes are delimited by two or more blank lines or by changes in indentation
Numbering Lines
Body numbering
Header and Footer numbering
nl
Body numbering style -b style or --body-numbering=style
Header and footer numbering style
-h style or --header-numbering=style
-f style or --footer-numbering=style
Numbering Lines Number format (cmd)
Page separator - Some numbering schemes reset the line numbers for each page
Line-number options for new pages -p or --no-renumber
Number format -n format or --numberformat=
format option, where format is ln (left justified, no leading zeros), rn (right justified,
no leading zeros), or rz (right justified with leading zeros)
Numbering Lines Number only non-blank lines (cmd)
The default behavior is to number lines that aren’t empty.
This corresponds to a style of t.
Numbering Lines Number all lines, Number no lines (cmd)
Number all lines
specify a style of a
Number no lines
specify a style of n
Numbering Lines Number lines matching a regular expression (cmd)
A style of pREGEXP numbers only those
lines that match the regular expression REGEXP.
suppose you’ve created a script, buggy, but you find that it’s not working
as you expect. When you run it, you get error messages that refer to line numbers, so you
want to create a version of the script with lines that are numbered for easy reference. What cmd you use?
$ nl -b a buggy > numbered-buggy.txt
Preparing a File for Printing (cmd)
pr

If you want to print a plain-text file, you may want to prepare it with headers, footers, page
breaks, and so on. The pr command was designed to do this. In its most basic form, you
pass the command a file:
$ pr myfile.txt
pr Generate multi-column output (cmd option)
Passing the -numcols or --columns=numcols option creates
output with numcols columns. Note that pr doesn’t reformat text; if lines are too long,
they’re truncated or run over onto multiple columns.
pr Generate double-spaced output (cmd option)
-d or --double-space option causes double-spaced
output from a single-spaced file.
pr Use form feeds (cmd option)
pr separates pages by using a fixed number of blank lines If you have
problems with this issue, you can pass the -F, -f, or --form-feed option, which causes pr
to output a form-feed character between pages.
pr Set page length (cmd option)
+ Set the header text
+ Set left margin and page width
The -l lines or --length=lines option sets the length of the page in lines.
The -h text or --header=text
The -o chars or --indent=chars option sets the left margin
to chars characters
example of pr in action, consider printing a double-spaced and numbered version
of a configuration file (say, /etc/profile) for your reference
cat -n /etc/profile | pr -d | lpr
Viewing the Starts of Files
head
Specify the number of bytes The -c num or --bytes=num option tells head to display num
bytes from the file rather than the default 10 lines.
Specify the number of lines You can change the number of lines displayed with the -n
num or --lines=num option.
Viewing the Ends of Files
tail

-c/--bytes and -n/--lines options to change the amount of data displayed,
just as with head
tail Track a file (option)
!!!
-f or --follow option tells tail to keep the file open and to display new
lines as they’re added. This feature is helpful for tracking log files because it enables you to
see changes as they’re added to the file.
tail Stop tracking on program termination (option)
--pid=pid option tells tail to terminate
tracking (as initiated by -f or --follow) once the process with a process ID (PID) of pid
terminates
Paging Through Files (option)
less - less filename
less usage options
Pressing the spacebar moves forward through t NN he file a screen at a time.
NN Pressing Esc followed by V moves backward through the file a screen at a time.
NN The Up and Down arrow keys move up or down through the file a line at a time.
NN You can search the file’s contents by pressing the slash (/) key followed by the search
term. For instance, typing /portable
You can search backward in the file by using the question mark (?) key rather than the
slash key.
NN You can move to a specific line by typing g followed by the line number, as in g50 to go
to line 50.
q to exit the program
Extracting Text (cmd)
cut command extracts portions of input lines and displays them on standard output
cut by byte
cut by character
cut by fiels
By byte The -b list or --bytes=list
By character The -c list or --characters=list The -f list or --fields=list option cuts the specified list of fields from the input
file.
extract the mac address from ifconfig using grep and cut
$ ifconfig eth0 | grep HWaddr | cut -d “ “ -f 11
Obtaining a Word Count
wc file.txt
308 2343 15534 file.txt
limit the output
--lines (-l), --words (-w), --bytes (-c), or --chars (-m)
command that searches for files that contain a specified string and returns the name of the file and (if it’s a text file) a line of context for that string
grep [options] regexp [files]
grep Count matching lines

grep Specify a pattern input file
Count matching lines Instead of displaying context lines, grep displays the number of
lines that match the specified pattern if you use the -c or --count option.

Specify a pattern input file The -f file or --file=file option takes pattern input from
the specified file rather than from the command line.
grep Ignore case

grep Search recursively
Ignore case You can perform a case-insensitive search, rather than the default case-sensitive
search, by using the -i or --ignore-case option.

Search recursively The -r or --recursive option searches in the specified directory and
all subdirectories rather than simply the specified directory. You can use rgrep rather than
specify this option.
grep Use an extended regular expression
Use an extended regular expression The grep command interprets regexp as a basic regular
expression by default. To use an extended regular expression, you can pass the -E or
--extended-regexp option. Alternatively, you can call egrep rather than grep; this variant
command uses extended regular expressions by default.
finds all the files in /etc that contain the string eth0
$ grep -r eth0 /etc/*

-r option, it searches recursively, so files in subdirectories of /etc are examined as well as those in /etc itself.
you want to locate all the files in /etc that contain the string
eth0 or eth1
$ grep eth[01] /etc/*
searches all files in /etc that contain the hostname twain.
example.com or bronto.pangaea.edu and, later on the same line, the number 127. This task
requires using several of the regular expression features.
$ grep -E “(twain\.example\.com|bronto\.pangaea\.edu).*127” /etc/*
shell quoting
Because
the shell uses certain characters, such as the vertical bar and the asterisk, for its own purposes,
you must enclose certain regular expressions in quotes lest the shell attempt to parse
the regular expression as shell commands.

$ grep -E “(twain\.example\.com|bronto\.pangaea\.edu).*127” /etc/*
you want to find the process
ID (PID) of a running xterm
You can use a pipe to send the result of a ps command through grep
# ps ax | grep xterm
sed (cmd)
sed command directly modifies the contents of files, sending the changed file to standard
output. Its syntax can take one of two forms:
sed [options] -f script-file [input-file]
sed [options] script-text [input-file]
sed cmd addresses explanation
sed commands operate on
addresses, which are line numbers. Commands may take no addresses, in which case they operate on the entire file; one address, in which case they operate on the specified line; or two addresses (a range), in which case they operate on that range of lines, inclusive
sed cmd Append text to the file.

sed cmd Append text to the file.

sed cmd Append text to the file
a\text - 0|1 - Append text to the file

i\text - 0|1 - Insert text into the file

r filename - 0|1 - Append text from filename into the file
sed cmd Replace the selected range of lines with the
provided text

sed Replace text that matches the regular expression
(regexp) with replacement.
c\text - Range - Replace the selected range of lines with the
provided text.

s/regexp/replacement - Range - Replace text that matches the regular expression
(regexp) with replacement.
sed write the current pattern space to the specified file

sed immediately quit the script, but print the current pattern space

sed immdeiately quit the scropt
w filename - Range - Write the current pattern space to the
specified file
q - 0|1 - Immediately quit the script, but print the current
pattern space
Q - 0|1 - Immediately quit the script
command processes the input file, cal-2008.txt, using sed’s s command to replace
the first occurrence of 2008 on each line with 2009.
$ sed ‘s/2008/2009/‘ cal-2008.txt > cal-2009.txt

By default, sed sends the modified file to standard output,
so this example uses redirection to send the output to cal-2009.txt. The idea in this
example is to quickly convert a file created for the year 2008 so that it can be used in 2009.