The default editor that comes with the UNIX operating system is called vi (visual editor). [Alternate editors for UNIX environments include vim, nano, pico and emacs, a product of GNU.] The UNIX vi editor is a full screen editor and has two modes of operation:
Command mode commands which cause action to be taken on the file, and
Insert mode in which entered text is inserted into the file.
In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the <Esc> (Escape) key turns off the Insert mode.
The vi editor opens in this mode, and it only understands commands
In this mode, you can, move the cursor and cut, copy, paste the text
This mode also saves the changes you have made to the file
Commands are case sensitive. You should use the right letter case.
While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, here’s a list that contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become automatic.
To Start vi
To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.
*
vi filename
edit filename starting at line 1
vi -r filename
recover filename that was being edited when system crashed
To Exit vi
Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file.
Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the <Return> (or <Enter>) key.
*
😡<Return>
quit vi, writing out modified file to file named in original invocation
:wq<Return>
quit vi, writing out modified file to file named in original invocation
:q<Return>
quit (or exit) vi
*
:q!<Return>
quit vi even though latest changes have not been saved for this vi call
Moving the Cursor
Unlike many of the PC and MacIntosh editors, the mouse does not move the cursor within the vi editor screen (or window). You must use the the key commands listed below. On some UNIX platforms, the arrow keys may be used as well; however, since vi was designed with the Qwerty keyboard (containing no arrow keys) in mind, the arrow keys sometimes produce strange effects in vi and should be avoided.
If you go back and forth between a PC environment and a UNIX environment, you may find that this dissimilarity in methods for cursor movement is the most frustrating difference between the two.
In the table below, the symbol ^ before a letter means that the <Ctrl> key should be held down while the letter key is pressed.
*
jor<Return>
[or down-arrow]
move cursor down one line
*
k [or up-arrow]
move cursor up one line
*
hor<Backspace>
[or left-arrow]
move cursor left one character
*
lor<Space>
[or right-arrow]
move cursor right one character
*
0 (zero)
move cursor to start of current line (the one with the cursor)
*
$
move cursor to end of current line
w
move cursor to beginning of next word
b
move cursor back to beginning of preceding word
:0<Return> or 1G
move cursor to first line in file
:n<Return> or nG
move cursor to line n
:$<Return> or G
move cursor to last line in file
Screen Manipulation
The following commands allow the vi editor screen (or window) to move up or down several lines and to be refreshed.
^f
move forward one screen
^b
move backward one screen
^d
move down (forward) one half screen
^u
move up (back) one half screen
^l
redraws the screen
^r
redraws the screen, removing deleted lines
Adding, Changing, and Deleting Text
Unlike PC editors, you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables.
Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step.
*
u
UNDO WHATEVER YOU JUST DID; a simple toggle
The main purpose of an editor is to create, add, or modify text for a file.
Inserting or Adding Text
The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode.
*
i
insert text before cursor, until <Esc> hit
I
insert text at beginning of current line, until <Esc> hit
*
a
append text after cursor, until <Esc> hit
A
append text to end of current line, until <Esc> hit
*
o
open and put text in a new line below current line, until <Esc> hit
*
O
open and put text in a new line above current line, until <Esc> hit
Changing Text
The following commands allow you to modify text.
*
r
replace single character under cursor (no <Esc> needed)
R
replace characters, starting with current cursor position, until <Esc> hit
cw
change the current word with new text,
starting with the character under cursor, until <Esc> hit
cNw
change N words beginning with character under cursor, until <Esc> hit;
e.g., c5w changes 5 words
C
change (replace) the characters in the current line, until <Esc> hit
cc
change (replace) the entire current line, stopping when <Esc> is hit
NccorcNc
change (replace) the next N lines, starting with the current line,
stopping when <Esc> is hit
Deleting Text
The following commands allow you to delete text.
*
x
delete single character under cursor
Nx
delete N characters, starting with character under cursor
dw
4dd
delete the single word beginning with character under cursor
Delete 4 words
dNw
delete N words beginning with character under cursor;
e.g., d5w deletes 5 words
D
delete the remainder of the line, starting with current cursor position
*
dd
3dd
delete entire current line
Delete 3 lines
NddordNd
delete N lines, beginning with the current line;
e.g., 5dd deletes 5 lines
Cutting and Pasting Text
The following commands allow you to copy and paste text.
yy
copy (yank, cut) the current line into the buffer
NyyoryNy
copy (yank, cut) the next N lines, including the current line, into the buffer
p
put (paste) the line(s) in the buffer into the text after the current line
Searching Text
A common occurrence in text editing is to replace one word or phase by another. To locate instances of particular sets of characters (or strings), use the following commands.
/string
search forward for occurrence of string in text
?string
search backward for occurrence of string in text
n
move to next occurrence of search string
N
move to next occurrence of search string in opposite direction
Determining Line Numbers
Being able to determine the line number of the current line or the total number of lines in the file being edited is sometimes useful.
:.=
returns line number of current line at bottom of screen
:=
returns the total number of lines at bottom of screen
^g
provides the current line number, along with the total number of lines,
in the file at the bottom of the screen
Saving and Reading Files
These commands permit you to input and output files other than the named file with which you are currently working.
:r filename<Return>
read file named filename and insert after current line
(the line with cursor)
:w<Return>
write current contents to file named in original vi call
:w newfile<Return>
write current contents to a new file named newfile
:12,35w smallfile<Return>
write the contents of the lines numbered 12 through 35 to a new file named smallfile
:w! prevfile<Return>
write current contents over a pre-existing file named prevfile
VI CHEATSHEET
Quitting
: x
Exit, saving changes
:q
Exit as long as there have been no changes
ZZ
Exit and save changes if any have been made
:q!
Exit and ignore any changes
Inserting Text
i
Insert before cursor
I
Insert before line
a
Append after cursor
A
Append after line
o
Open a new line after current line
O
Open a new line before current line
r
Replace one character
R
Replace many characters
Motion
h
Move left
j
Move down
k
Move up
l
Move right
w
Move to next word
W
Move to next blank delimited word
b
Move to the beginning of the word
B
Move to the beginning of blank delimted word
e
Move to the end of the word
E
Move to the end of Blank delimited word
(
Move a sentence back
)
Move a sentence forward
{
Move a paragraph back
}
Move a paragraph forward
0
Move to the begining of the line
$
Move to the end of the line
1G
Move to the first line of the file
G
Move to the last line of the file
nG
Move to nth line of the file
:n
Move to nth line of the file
fc
Move forward to c
Fc
Move back to c
H
Move to top of screen
M
Move to middle of screen
L
Move to botton of screen
%
Move to associated ( ), { }, [ ]
:0
Move to the beginning of the file
:$
Move to the end of the file
[ctrl] + d
go down half a screen
[ctrl] + u
go up half a screen
[ctrl] + f
go forward a screen
[ctrl] + b
go back a screen
Deleting Text
x
Delete character to the right of cursor
X
Delete character to the left of cursor
D
Delete to the end of the line
dd
Delete current line
:d
Delete current line
Yanking Text
yy
Yank the current line
:y
Yank the current line
Changing text
C
Change to the end of the line
cc
Change the whole line
guu
lowercase line
gUU
uppercase line
~
Toggle upp and lower case
Putting text
p
Put after the position or after the line
P
Put before the poition or before the line
Markers
mc
Set marker c on this line
`c
Go to beginning of marker c line.
‘c
Go to first non-blank character of marker c line.
Search for strings
/string
Search forward for string
?string
Search back for string
n
Search for next instance of string
N
Search for previous instance of string
Replace
:s/pattern/string/flags
Replace pattern with string according to flags.
g
Flag – Replace all occurences of pattern
c
Flag – Confirm replaces.
Modes
Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for “colon” commands which execute when you press the ruturn key.
ASCII stands for American Standard Code for Information Interchange. It’s a 7-bit character code where every single bit represents a unique character. On this webpage you will find 8 bits, 256 characters, according to ISO 8859-1 and Microsoft® Windows Latin-1 increased characters, which is available in certain programs such as Microsoft Word.
How to keyboard imput using ALT+0000
How to generate each character with keyboard. Alt codes work on computers running any of Microsoft’s Windows operating systems.
Find the Alt Code you need from the alt code tables below.
Make sure that “Number Lock” is switched on. There should be a light on your keyboard indicating this. (If not, press the “Number Lock” key at the top left of the numeric keypad.)
Hold down the “Alt” key to the left of the space bar and key the code on the numeric keypad.
Don’t release the “Alt” key until after you’ve typed the alt code. When you release it you should see the special character you include.
Instructions for entering Alt Codes on a lap topEven if you have a laptop or a keyboard with no numeric keypad – you can still use alt codes.
Look for a “function” or “fn” key normally near the bottom left of the keyboard.
Look for a button with “num lock” written in the same colour which is usually near the top right of the keyboard.
While holding “function” press and relase “num lock“.
Enter alt codes using the method above but to enter the actual numeric alt code use the keys with numbers in the same colour as the function (fn) key. Normally “U” has 4 on it for example.
Switch “num lock” off in the same way as you switched it on to continue using your keyboard normally.
ASCII codes
ASCII control characters (character code 0-31)
The first 32 characters in the ASCII-table are unprintable control codes and are used to control peripherals such as printers.
Codes 32-127 are common for all the different variations of the ASCII table, they are called printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols. You will find almost every character on your keyboard. Character 127 represents the command DEL.
DEC
OCT
HEX
BIN
Symbol
HTML Number ( or ALT+)
HTML Name
Description
32
040
20
00100000
 
Space
33
041
21
00100001
!
!
Exclamation mark
34
042
22
00100010
“
"
"
Double quotes (or speech marks)
35
043
23
00100011
#
#
Number
36
044
24
00100100
$
$
Dollar
37
045
25
00100101
%
%
Percentsign
38
046
26
00100110
&
&
&
Ampersand
39
047
27
00100111
‘
'
Single quote
40
050
28
00101000
(
(
Open parenthesis (or open bracket)
41
051
29
00101001
)
)
Close parenthesis (or close bracket)
42
052
2A
00101010
*
*
Asterisk
43
053
2B
00101011
+
+
Plus
44
054
2C
00101100
,
,
Comma
45
055
2D
00101101
–
-
Hyphen
46
056
2E
00101110
.
.
Period, dot or full stop
47
057
2F
00101111
/
/
Slash or divide
48
060
30
00110000
0
0
Zero
49
061
31
00110001
1
1
One
50
062
32
00110010
2
2
Two
51
063
33
00110011
3
3
Three
52
064
34
00110100
4
4
Four
53
065
35
00110101
5
5
Five
54
066
36
00110110
6
6
Six
55
067
37
00110111
7
7
Seven
56
070
38
00111000
8
8
Eight
57
071
39
00111001
9
9
Nine
58
072
3A
00111010
:
:
Colon
59
073
3B
00111011
;
;
Semicolon
60
074
3C
00111100
<
<
<
Less than (or open angled bracket)
61
075
3D
00111101
=
=
Equals
62
076
3E
00111110
>
>
>
Greater than (or close angled bracket)
63
077
3F
00111111
?
?
Question mark
64
100
40
01000000
@
@
At symbol
65
101
41
01000001
A
A
Uppercase A
66
102
42
01000010
B
B
Uppercase B
67
103
43
01000011
C
C
Uppercase C
68
104
44
01000100
D
D
Uppercase D
69
105
45
01000101
E
E
Uppercase E
70
106
46
01000110
F
F
Uppercase F
71
107
47
01000111
G
G
Uppercase G
72
110
48
01001000
H
H
Uppercase H
73
111
49
01001001
I
I
Uppercase I
74
112
4A
01001010
J
J
Uppercase J
75
113
4B
01001011
K
K
Uppercase K
76
114
4C
01001100
L
L
Uppercase L
77
115
4D
01001101
M
M
Uppercase M
78
116
4E
01001110
N
N
Uppercase N
79
117
4F
01001111
O
O
Uppercase O
80
120
50
01010000
P
P
Uppercase P
81
121
51
01010001
Q
Q
Uppercase Q
82
122
52
01010010
R
R
Uppercase R
83
123
53
01010011
S
S
Uppercase S
84
124
54
01010100
T
T
Uppercase T
85
125
55
01010101
U
U
Uppercase U
86
126
56
01010110
V
V
Uppercase V
87
127
57
01010111
W
W
Uppercase W
88
130
58
01011000
X
X
Uppercase X
89
131
59
01011001
Y
Y
Uppercase Y
90
132
5A
01011010
Z
Z
Uppercase Z
91
133
5B
01011011
[
[
Opening bracket
92
134
5C
01011100
\
\
Backslash
93
135
5D
01011101
]
]
Closing bracket
94
136
5E
01011110
^
^
Caret – circumflex
95
137
5F
01011111
_
_
Underscore
96
140
60
01100000
`
`
Grave accent
97
141
61
01100001
a
a
Lowercase a
98
142
62
01100010
b
b
Lowercase b
99
143
63
01100011
c
c
Lowercase c
100
144
64
01100100
d
d
Lowercase d
101
145
65
01100101
e
e
Lowercase e
102
146
66
01100110
f
f
Lowercase f
103
147
67
01100111
g
g
Lowercase g
104
150
68
01101000
h
h
Lowercase h
105
151
69
01101001
i
i
Lowercase i
106
152
6A
01101010
j
j
Lowercase j
107
153
6B
01101011
k
k
Lowercase k
108
154
6C
01101100
l
l
Lowercase l
109
155
6D
01101101
m
m
Lowercase m
110
156
6E
01101110
n
n
Lowercase n
111
157
6F
01101111
o
o
Lowercase o
112
160
70
01110000
p
p
Lowercase p
113
161
71
01110001
q
q
Lowercase q
114
162
72
01110010
r
r
Lowercase r
115
163
73
01110011
s
s
Lowercase s
116
164
74
01110100
t
t
Lowercase t
117
165
75
01110101
u
u
Lowercase u
118
166
76
01110110
v
v
Lowercase v
119
167
77
01110111
w
w
Lowercase w
120
170
78
01111000
x
x
Lowercase x
121
171
79
01111001
y
y
Lowercase y
122
172
7A
01111010
z
z
Lowercase z
123
173
7B
01111011
{
{
Opening brace
124
174
7C
01111100
|
|
Vertical bar
125
175
7D
01111101
}
}
Closing brace
126
176
7E
01111110
~
~
Equivalency sign – tilde
127
177
7F
01111111

Delete
The extended ASCII codes (character code 128-255)
There are several different variations of the 8-bit ASCII table. The table below is according to ISO 8859-1, also called ISO Latin-1. Codes 128-159 contain the Microsoft® Windows Latin-1 extended characters.
Between Y as in yes and G as in go, but with no hard ‘G’ sound – more of a soft ‘H’ followed by the ‘Y’ sound in yes
Delta
Δ
D
Th as in the
Epsilon
Ε
E
E as in very
Zeta
Ζ
Z
Z as in zoo
Eta
Η
E
Ee as in bee
Theta
Θ
Th
Th as in think
Iota
Ι
I
Ee as in bee or I as in bitter or sit
Kappa
Κ
K
K as in look
Lamda
Λ
L
L as in log
Mu
Μ
M
M as in man
Nu
Ν
N
N as in not
Xi
Ξ
X
X as in box
Omicron
Ο
O
O as in box
Pi
Π
P
P as in top, but softer and close to ‘B’
Rho
Ρ
R, Rh
a rolled R
Sigma
Σ
S
S as in sap with a hint of Sh as in sugar
Tau
Τ
T
T as in lot, but softer and close to ‘D’
Upsilon
Υ
U
Same as eta – Ee as in bee
Phi
Φ
Ph
Ph as in photo
Chi
Χ
Kh
Ch as in the scottish ‘loch’ but softer – not a hard sound
Psi
Ψ
Ps
Ps as in upside
Omega
Ω
M
like omicron – O as in box – or longer ‘O’ sound like the vowel sound in oar
Alpha
Α
α
Beta
Β
β
Gamma
Γ
γ
Delta
Δ
δ
Epsilon
Ε
ε
Zeta
Ζ
ζ
Eta
Η
η
Theta
Θ
θ ϑ
Iota
Ι
ι
Kappa
Κ
κ
Lambda
Λ
λ
Mu
Μ
μ
Nu
Ν
ν
Xi
Ξ
ξ
Omicron
Ο
ο
Pi
Π
π
Rho
Ρ
ρ
Sigma
Σ
σ ς
Tau
Τ
τ
Upsilon
Υ
υ
Phi
Φ
φ
Chi
Χ
χ
Psi
Ψ
ψ
Omega
Ω
ω
Europeand Special Chars
Accents and diacritical marks Non-standard characters signs that change the sound of letters and words
Many western languages contain words with letters whose sound is determined by these accents and diacritical marks. The effects are different depending on the language; here are the names and examples of the more common marks and non-standard characters. Usage of these accents and marks is not restricted to the letters shown in the examples.
Clearing typed commands from terminal history: By default, up to the last 500 command lines a user types in the terminal window are saved into a hidden .bash_history file. The previously typed commands can be readily accessed by using the up and down arrow keys. This makes it easy to retrieve and reuse your recently used commands. However, maybe you want to clear the terminal command history list and start fresh?
This simple tutorial explains the process of viewing and then optionally clearing the terminal history.
Viewing the complete terminal command history:
To view the complete history of commands typed in the terminal “for the logged in user”, open the terminal and type history
How to clear the terminal command line history:
Login with the user account whose terminal history you plan to clear
Open a terminal window and type history -c
Repeat the process if necessary for each user account
How to delete a single command from history on a Linux
I‘m working in Ubuntu bash terminal application and remotely on a RHEL server in cloud platform. I typed the wrong and dangerous command. I no longer wish to remember dangerous command in the history file. How can I remove or delete a single command from bash history file?
You can use the history command to clear all history or selected command line.
How do I view history with line number?
Simply type the history command:
$ history
Sample outputs:
How to delete a single command number 1013 from history
The syntax is:
## Delete the bash history entry at offset OFFSET ##history -d offset
history -d numberhistory -d 1013
Verify it:
$ history
How do I delete all the history?
The syntax is: history -c
Tip: Control bash history like a pro
First, you can increase your bash history size by appending the following config option in ~/.bashrc file:
Save and close the file.
Where to find more information about history command?
You can read bash man page by typing the following command: $ man bash Or simply type the following command: $ help history
FIND
Find command examples
Let us try out some examples.
Finding files and printing their full name
You wish to find out all *.c (all c source code) files located under /home directory, enter:
$ find /home -name “*.c”
You would like to find httpd.conf file location:
$ find / -name httpd.conf
Finding all files owned by a user
Find out all files owned by user USER: # find / -user USER Find out all *.sh owned by user USER: # find / -user USER -name “*.sh”
Finding files according to date and time
Files not accessed in a time period – It is useful to find out files that have or have not been accessed within a specified number of days. Following command prints all files not accessed in the last 7 days:
# find /home -atime +7
-atime +7: All files that were last accessed more than 7 days ago
-atime 7: All files that were last accessed exactly 7 days ago
-atime -7: All files that were last accessed less than7 days ago
Finding files modified within a specified time – Display list of all files in /home directory that were not last modified less than then days ago.
# find /home -mtime -7
Finding newer (more recently) modified files
Use -newer option to find out if file was modified more recently than given file.
# find /etc/apache-perl -newer /etc/apache-perl/httpd.conf
Finding the most recent version of file
It is common practice before modifying the file is copied to somewhere in system. For example whenever I modify web server httpd.conf file I first make backup. Now I don’t remember whether I had modified the /backup.conf/httpd.conf or /etc/apache-perl/httpd.conf. You can use the find command as follows (tip you can also use ls -l command):
find / -name httpd.conf -newer /etc/apache-perl/httpd.conf
Locate command
The locate command is often the simplest and quickest way to find the locations of files and directories on Linux and other Unix-like operating systems. For example, the following command uses the star wildcard to display all files on the system that have the .c filename extension: # locate “*.c”
Rename
Linux Rename File Command
I‘m a new Linux user. How do I rename a file called resumezzz.pdf to resume.pdf using Linux bash command prompt?
You need to use the mv command. It is used to rename and move files and directories. The general syntax is as follows:
In this example, the following command would rename a file called resumezzz.pdf to resume.pdf. Open a command-line terminal (select Applications > Accessories > Terminal), and then type:
mv resumezzz.pdf resume.pdf
If resumezzz.pdf is located in /home/user/docs/files directory, type:
cd /home/user/docs/files mv resumezzz.pdf resume.pdf
Change the permission of the file you downloaded to be executable. Type the following command:
$ chmod +x file.bin
Start the installation process or run .bin file. Type the following command:
./file.bin
For example if .bin file name is application.bin. Type the following commands:
$ chmod +x application.bin
$ ./application.bin
Another example for Java Linux self extracting binary file:
$ chmod +x jre-1_5_0-linux-i586.bin
$ ./jre-1_5_0-linux-i586.bin
OR
$ sh jre-1_5_0-linux-i586.bin
Correct way to disable init-scripts to start at boottime on Debian
In several articles and forums I see people telling the way of removing the init-script on a Debian system would be:
update-rc.d -f init-script-name remove
The more appropriate way is to disable the init-script from running at boottime:
update-rc.d init-script-name stop levels
In this way you prevent that in case you upgrade the package a new init-script will be created with the defaults.
If the init-script is written with the defaults the init-script might start the process again at boot-up.
If you disabled the init-script from running at boottime the init-script would not be recreated or overwritten with the init-script in the update.
All modern browsers support the following 140 color names (click on a color name, or a hex value, to view the color as the background-color along with different text colors):
crontab -l ← -l = list user’s crontab
crontab -u USER -l
crontab -e ← -e = edit user’s crontab
crontab -u USER -e
at
queue jobs for later execution
echo “/sbin/shutdown -h now” |at 21:00 02/30/2009
at -t 200902302100
atq
lists the user’s pending jobs
atq
atrm
delete jobs for later execution
atrm JOBID
watch
execute a program periodically, showing output fullscreen
watch ntpq -p ← By default, the program is run every 2 seconds
watch -n 1 ntpq -p ← 1 seconds interval
-d : highlight the differences between successive updates
etc
alias
Alias with no arguments or with the -p option prints the list of aliases
When arguments are supplied, an alias is defined for each name whose value is given.
alias ← check all alias
alias ls=’ls -la –color=auto’
alias grep=’grep –color’
unalias
Remove each name from the list of defined aliases.
If -a is supplied, all alias definitions are removed.
unalias COMMAND
ntpdate
set the date and time via NTP
ntpdate -b -u IP
-b : Force the time (step mode)
-u : If you are running ntpd, “-u” must be added.
chronyc
command-line interface for chronyd
chronyc sources
chronyc sources -v
ntpq
standard NTP query program
ntpq -p
-p : Print a list of the peers known to the server
watch -n 1 ntpq -p
hwclock
query and set the hardware clock (RTC)
hwclock (-r) ← Read the Hardware Clock and print the time on standard output.
hwclock -w ← Set the Hardware Clock to the current System Time.
hwclock -s ← Set the System Time from the Hardware Clock.
man
an interface to the on-line reference manuals
man COMMAND
whatis
display manual page descriptions
whatis KEYWORD
whatis cat
whatis vi
history
GNU History Library
history |less
history 5 ← lists only the last 5 lines.
HISTSIZE=1000
HISTTIMEFORMAT=“%Y/%m/%d %H:%M:%S ”
which
locate a command
which ls
time
time a simple command or give resource usage
time sleep 5
strace
trace system calls and signals
strace -t php test.php
strace -t -o test.txt php test.php
-t : each line of the trace with the time of day.
find . -name “*txt*”
find /dir -type f -name “*.log*” -mtime +7 -exec rm -rf {} \;
← “-mtime +7” is 7 days ago
File Compression
tar
The GNU version of the tar archiving utility
tar warn the order of target and destination.
tar zcvf test.tar.gz Dir ← Create, Verbose, File
tar ztvf test.tar.gz ← Test, Verbose, File
tar zxvf test.tar.gz ← eXtract, Verbose, File
tar jcvf test.tar.bz2 DIR ← Create, Verbose, File
tar jxvf test.tar.bz2
tar zcvf /tmp/user01.tar.gz user01
tar zxvf user01.tar.gz -C /home
echo “password01” | passwd –stdin user01
passwd -S user1 ← check about the status of the password
passwd -l user01 ← Lock the user
passwd -u user01 ← Unlock
chage -l USER ← check
chage -M 90 USER ← the password expires day set 90days
usermod
modify a user account
usermod -g GROUP USER
usermod -g GROUP -G SUBGROUP USER
usermod -G SUBGROUP USER
usermod -G SUBGROUP1,SUBGROUP2 USER
usermod -G “” USER
usermod -l USER_NAME_NEW USERNAME_OLD ← change username
usermod -d HOME_DIR_NEW USER_NAME ← change home directory
usermod -u UID USER ← change UID
gpasswd
gpasswd -a USER sudo ← add USER to GROUP
gpasswd -r USER sudo ← remove USER from GROUP
show / manipulate routing, devices, policy routing and tunnels
ip a ← print ip address
ip addr ← print ip address
ip r ← Show IP Routing
ip route ← Show IP Routing
ss
another utility to investigate sockets
ss -lt ← TCP Listening Port
ss -ltp ← Process Name with Listening TCP
ss -anu
ifconfig
configure a network interface
ifconfig ← check ip
ifconfig -a ← -a : display all interfaces
ifconfig eth0 up
ifconfig eth0 down
ifdown
take a network interface down
ifdown eth0
ifdown eth0 && ifup eth0
ifup
bring a network interface up
ifup eth0
ifdown eth0 && ifup eth0
route
show / manipulate the IP routing table
route ← show the IP routing table
route -n ← show the IP routing table
route add -net 192.168.10.0 netmask 255.255.255.0 gw 10.50.0.1
route add -host 192.168.0.100 gw 192.168.1.100
route del -net 192.168.10.0 netmask 255.255.255.0
sed -e ‘s/xxx/XXX/g’ input.txt > output.txt
sed -i “s/IPADDR=192.168.0.10/IPADDR=192.168.0.11/g” ifcfg-eth0
mail
mailx
send and receive Internet mail
echo test | mail -s “test” -S “smtp=smtp://xx.xx.xx.xx:25” test@example.com
cat test.txt | mail -s “test” -S “smtp=smtp://xx.xx.xx.xx:25”
test@example.com
while
while : ; do uptime ; sleep 1 ; done
while : ; do uptime >> /tmp/tmp.txt ; sleep 1 ; done
while : ; do ps aux |grep httpd |wc -l ; sleep 1 ; done
for
for i in 127.0.0.1 192.168.10.1; do ping -c 2 $i; done
adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems
tune2fs -l /dev/mapper/mpath0
← -l : List the contents of the filesystem superblock.
tune2fs -l /dev/mapper/mpath0 |egrep “count|interval”
tune2fs -i 0 -c 0 /dev/mapper/mpath0
← -i : interval, -c : mount count
fsck
check and repair a Linux filesystem
you must umount the device before fsck.
for example single usermode and umount.
‘shutdown -r -F now’ is force fsck after reboot.
overwrite a file to hide its contents, and optionally delete it
mount
mount
mount a filesystem
mount /mnt/test /dev/sda1
mount -o remount /dev/sda1
mount -t cifs //xx.xx.xx.xx/test /mnt/test -o username=guest,password=
umount
unmount file systems
umount /mnt/test
umount -f /mnt/test
(-f : Force unmount(in case of an unreachable NFS system))
umount -l /mnt/test
(-l : Lazy unmount.Detach the filesystem from the filesystem hierarchy now )
scan all disks for volume groups and rebuild caches
vgchange
change attributes of a volume group
vgchange -a y ← activate
vgchange -a n ← deactivate
vgchange -a y vg01
vgchange -a n vg01
Check : lvdisplay VGDATA |grep Status
vgchange –addtag $(uname -n) VG_TEST
vgchange –deltag $(uname -n) VG_TEST
Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions.
iostat -xtk 1
(cpu, io) ← interval 1sec
mpstat
Report processors related statistics.
mpstat -P ALL
uptime
Tell how long the system has been running.
while : ; do uptime ; sleep 1 ; done
while : ; do uptime » /tmp/tmp.txt ; sleep 1 ; done
w
Show who is logged on and what they are doing.
free
Display amount of free and used memory in the system
free -m ← show output in MB
tcpdump
dump traffic on a network
tcpdump -n port 80 -i any
tcpdump -n not arp and not port 123 and not port 22
tcpdump host 192.168.0.10 -n -w /tmp/20110615.pcap
tcpdump -r /tmp/20110615.pcap ← -r : Read packets from file
Total Commander is a file manager for Windows, a program like Windows Explorer to copy, move or delete files. However, Total Commander can do much more than Explorer, e.g. pack and unpack files, access ftp servers, compare files by content, etc! It was known as Windows Commander and in 2002 there was a name change – the new name is “Total Commander”. See the latest version at https://www.ghisler.com/
Shortcuts
F1
Help
F2
Reread source window
F3
List files
F4
Edit files
F5
Copy files
F6
Rename or move files
F7
Create directory
F8
Delete files to recycle bin /delete directly – according to configuration (or Delete)
F9
Activate menu above source window (left or right)
F10
Activate left menu or deactivate menu
Alt+F1
change left drive
Alt+F2
change right drive
Alt+F3
Use alternate (external or internal) viewer
Alt+Shift+F3
Start Lister and load file with internal viewer (no plugins or multimedia)
Alt+F4
Exit | Minimize (with option MinimizeOnClose in wincmd.ini)
Alt+F5
Pack files
Alt+Shift+F5
Move to archive
Alt+F6
Unpack specified files from archive under cursor, or selected archives (use Alt+F9 on Windows 95)
Alt+F7
Find
Alt+F8
Opens the history list of the command line
Alt+F9
Same as ALT+F6 (because ALT+F6 is broken on Windows 95)
Alt+Shift+F9
Test archives
Alt+F10
Opens a dialog box with the current directory tree
Alt+F11
Opens left current directory bar (breadcrumb bar)
Alt+F12
Opens right current directory bar (breadcrumb bar)
Alt+Shift+F11
Focus the button bar to use it with the keyboard
Shift+F1
Custom columns view menu
Shift+F2
Compare file lists
Shift+F3
List only file under cursor, when multiple files selected
Shift+F4
Create new text file and load into editor
Shift+F5
Copy files (with rename) in the same directory
Shift+Ctrl+F5
Create shortcuts of the selected files
Shift+F6
Rename files in the same directory
Shift+F8/Delete
Delete directly / delete to recycle bin – according to configuration
Shift+F10
Show context menu
Shift+Esc
Minimizes Total Commander to an icon
Alt+Arrow left / Arrow right
Go to previous/next dir of already visited dirs
Alt+Arrow down
Open history list of already visited dirs (like the history list in a WWW browser)
Num +
Expand selection (configurable: just files or files and folders)
Num –
Shrink selection
Num *
Invert selection (also with shift, see link)
Num /
Restore selection
Shift+Num+[+]
Like Num +, but files and folders if Num + selects just files (and vice versa)
Shift+Num+-
Always removes the selection just from files (Num – from files and folders)
Shift+Num+*
Like Num *, but files and folders if Num * inverts selection of just files (and vice versa)
Ctrl+Num +
Select all (configurable: just files or files and folders)
Ctrl+Shift+Num +
Select all (files and folders if CTRL+Num + selects only files)
Ctrl+Num –
Deselect all (always files and folders)
Ctrl+Shift+Num –
Deselect all (always files, no folders)
Alt+Num +
Select all files with the same extension
Alt+Num –
Remove selection from files with the same extension
Ctrl+Page up
Change to parent directory (cd ..) , or Backspace
Ctrl+<
Jump to the root directory (most European keyboards)
Ctrl+\
Jump to the root directory (US keyboard)
Ctrl+Page down
Open directory/archive (also self extracting .EXE archives)
Ctrl+Arrow left / Arrow right
Open directory/archive and display it in the target window. If the cursor is not on a directory name, or the other panel is active, then the current directory is displayed instead.
Ctrl+F1
File display ‘brief’ (only file names)
Ctrl+Shift+F1
Thumbnails view (preview pictures)
Ctrl+F2
File display ‘full’ (all file details)
Ctrl+Shift+F2
Comments view (new comments are created with Ctrl+Z)
Ctrl+F3
Sort by name
Ctrl+F4
Sort by extension
Ctrl+F5
Sort by date/time
Ctrl+F6
Sort by size
Ctrl+F7
Unsorted
Ctrl+F8
Display directory tree
Ctrl+Shift+F8
Cycle through separate directory tree states: one tree, two trees, off
Ctrl+F9
Print file under cursor using the associated program
Ctrl+F10
Show all files
Ctrl+F11
Show only programs
Ctrl+F12
Show user defined files
Tab
Switch between left and right file list
Shift+Tab
Switch between current file list and separate tree (if enabled)
Insert
Select file or directory.
Space
Select file or directory (as INSERT). If SPACE is used on an unselected directory under the cursor, the contents in this directory are counted and the size is shown in the “full” view instead of the string . This can be disabled through ‘Configuration’ – ‘Options’ – ‘Operation’ – ‘Selection with Space’.
Enter
Change directory / run program / run associated program / execute command line if not empty. If the source directory shows the contents of an archive, further information on the packed file is given.
Shift+Enter
1. Runs command line / program under cursor with preceding command /c and leave the program’s window open. Only works if NOCLOSE.PIF is in your Windows directory! 2. With ZIP files: use alternative choice of these (as chosen in Packer config): (Treat archives like directories <-> call associated program, i.e. winzip or quinzip) 3. In the list of last used dirs (History, Ctrl+D), open the directory on a new Tab.
Alt+Shift+Enter
The contents of all directories in the current directory are counted. The sizes of the directories are then shown in the “full” view instead of the string . Abort by holding down ESC key.
Alt+Enter
Show property sheet.
Ctrl+a
Select all
Ctrl+b
Directory branch: Show contents of current dir and all subdirs in one list
Ctrl+Shift+b
Selected directory branch: Show selected files, and all in selected subdirs
Ctrl+c
Copy files to clipboard
Ctrl+x
Cut files to clipboard
Ctrl+v
Paste from clipboard to current dir.
Ctrl+d
Open directory hotlist (‘bookmarks’)
Ctrl+f
Connect to FTP server
Ctrl+Shift+f
Disconnect from FTP server
Ctrl+i
Switch to target directory
Ctrl+l
Calculate occupied space (of the selected files)
Ctrl+m
Multi-Rename-Tool
Ctrl+Shift+m
Change FTP transfer mode
Ctrl+n
New FTP connection (enter URL or host address)
Ctrl+p
Copy current path to command line
Ctrl+q
Quick view panel instead of file window
Ctrl+r
Reread source directory
Ctrl+s
Open Quick Filter dialog and activate filter (deactivate with ESC or CTRL+F10)
Ctrl+Shift+s
Open Quick Filter dialog and reactivate last-used filter
Ctrl+t
Open new folder tab and activate it
Ctrl+Shift+t
Open new folder tab, but do not activate it
Ctrl+u
Exchange directories
Ctrl+Shift+u
Exchange directories and tabs
Ctrl+w
Close currently active tab
Ctrl+Shift+w
Close all open tabs
Ctrl+z
Edit file comment
Ctrl+Arrow up
Open dir under cursor in new tab
Ctrl+Shift+Arrow Up
Open dir under cursor in other window (new tab)
Ctrl+Tab/Ctrl+Shift+Tab
Jump to next tab / jump to previous tab
Ctrl+Alt+Letter
Quick search for a file name (starting with specified letters) in the current directory (Support hotkeys Ctrl+X, Ctrl+C, Ctrl+V and Ctrl+A; use Ctrl+S for search filter on/off)
FTP
Ctrl+F
Connect to FTP Server
Ctrl+SHIFT+F
Disconnect current FTP connection
Ctrl+N
New FTP connection
Selections
Insert/Space
Select current file/folder
Num *
Invert selection
Num /
Restore selection
Ctrl+A
Select all
Ctrl+l
Calculate occupied space of selecte files
Ctrl+Num –
Deselect all
Alt+Num+
Select all files with extension
Alt+Num-
Deselect all files with extension
Selections
Alt+F1
Change left drive
Alt+F2
Change right drive
Alt+Arrow Down
Open list of visited directories
Alt+Arrow Left
Jump to previous directory
Alt+Arrow Right
Jump to next directory
Ctrl+<
Jump to root directory
Backspace
Change to parent directory
Tab
Switch between left and right file list
Navigation
Alt+F1
Change left drive
Alt+F2
Change right drive
Alt+Arrow Down
Open list of visited directories
Alt+Arrow Left
Jump to previous directory
Alt+Arrow Right
Jump to next directory
Ctrl+<
Jump to root directory
Backspace
Change to parent directory
Tab
Switch between left and right file list
View
Ctrl+u
Swap left & right view
F2/Ctrl+r
Refresh current directory
Ctrl+b
Show contents of current dir and all subdirs in one list
Ctrl+Shift+B
Selected directory branch
Alt+Enter
Show file properties window
F1
Help
Ctrl+l
Calculate occupied space (of selecte files)
File manipulation
F3
List file contents
Shift+F3
List file under cursor with multiple files selected
F4
Edit files
Shift+F4
Create new text file and load in editor
F5/Ctrl+c
Copy file
Shift+F5
Copy files (with rename) in same directory
F6
Rename or move files
Shift+F6
Rename files in same directory
F7
Create directory
F8/Delete
Delete files
Ctrl+v
Paste file in current directory
Ctrl+x
Cut file
Ctrl+m
Multi-rename tool
Archiving
Alt+F5
Pack files
Alt+Shift+F5
Move to archive
Alt+F6
Unpack from archive under cursor
Alt+Shift+F9
Test archives
File sorting
Ctrl+F3
Sort by name
Ctrl+F4
Sort by extension
Ctrl+F5
Sort by date/time
Ctrl+F6
Sort by size
Ctrl+F7
Unsorted
Searching
Ctrl+s
Quick search
Alt+F7
Find
Command Line with TC
%comspec% Envoke CMD (ancient times) CMD Envoke CMD CMD /C Carries out the command specified by string and then terminates CMD /K Carries out the command specified by string but remains (For more complete CMD with switches see relevant CMD cheatsheet)
Other
Ctrl+Shift+w Close all open tabs Ctrl+z Edit file comment Ctrl+Arrow up Open dir under cursor in new tab Ctrl+Shift+Arrow Up Open dir under cursor in other window (new tab) Ctrl+Tab/Ctrl+Shift+Tab Jump to next tab / jump to previous tab Ctrl+Alt+Letter Quick search for a file name (starting with specified letters) in the current directory (Support hotkeys Ctrl+X, Ctrl+C, Ctrl+V and Ctrl+A; use Ctrl+S for search filter on/off)
Class A
0. 0. 0. 0 = 00000000.00000000.00000000.00000000
127.255.255.255 = 01111111.11111111.11111111.11111111
0nnnnnnn.HHHHHHHH.HHHHHHHH.HHHHHHHH
Class B
128. 0. 0. 0 = 10000000.00000000.00000000.00000000
191.255.255.255 = 10111111.11111111.11111111.11111111
10nnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHH
Class C
192. 0. 0. 0 = 11000000.00000000.00000000.00000000
223.255.255.255 = 11011111.11111111.11111111.11111111
110nnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHH
Class D
224. 0. 0. 0 = 11100000.00000000.00000000.00000000
239.255.255.255 = 11101111.11111111.11111111.11111111
1110XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX
Class E
240. 0. 0. 0 = 11110000.00000000.00000000.00000000
255.255.255.255 = 11111111.11111111.11111111.11111111
1111XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX
Table
The following table lists the variable length subnets from 1 to 32,
the CIDR [3] representation form (/xx) and the Decmial equivalents.
(M = Million, K=Thousand, A,B,C= traditional class values)
Mask value: # of
Hex CIDR Decimal addresses Classfull
80.00.00.00 /1 128.0.0.0 2048 M 128 A
C0.00.00.00 /2 192.0.0.0 1024 M 64 A
E0.00.00.00 /3 224.0.0.0 512 M 32 A
F0.00.00.00 /4 240.0.0.0 256 M 16 A
F8.00.00.00 /5 248.0.0.0 128 M 8 A
FC.00.00.00 /6 252.0.0.0 64 M 4 A
FE.00.00.00 /7 254.0.0.0 32 M 2 A
FF.00.00.00 /8 255.0.0.0 16 M 1 A
FF.80.00.00 /9 255.128.0.0 8 M 128 B
FF.C0.00.00 /10 255.192.0.0 4 M 64 B
FF.E0.00.00 /11 255.224.0.0 2 M 32 B
FF.F0.00.00 /12 255.240.0.0 1024 K 16 B
FF.F8.00.00 /13 255.248.0.0 512 K 8 B
FF.FC.00.00 /14 255.252.0.0 256 K 4 B
FF.FE.00.00 /15 255.254.0.0 128 K 2 B
FF.FF.00.00 /16 255.255.0.0 64 K 1 B
FF.FF.80.00 /17 255.255.128.0 32 K 128 C
FF.FF.C0.00 /18 255.255.192.0 16 K 64 C
FF.FF.E0.00 /19 255.255.224.0 8 K 32 C
FF.FF.F0.00 /20 255.255.240.0 4 K 16 C
FF.FF.F8.00 /21 255.255.248.0 2 K 8 C
FF.FF.FC.00 /22 255.255.252.0 1 K 4 C
FF.FF.FE.00 /23 255.255.254.0 512 2 C
FF.FF.FF.00 /24 255.255.255.0 256 1 C
FF.FF.FF.80 /25 255.255.255.128 128 1/2 C
FF.FF.FF.C0 /26 255.255.255.192 64 1/4 C
FF.FF.FF.E0 /27 255.255.255.224 32 1/8 C
FF.FF.FF.F0 /28 255.255.255.240 16 1/16 C
FF.FF.FF.F8 /29 255.255.255.248 8 1/32 C
FF.FF.FF.FC /30 255.255.255.252 4 1/64 C
FF.FF.FF.FE /31 255.255.255.254 2 1/128 C
FF.FF.FF.FF /32 255.255.255.255 This is a single host route
First what is the
OSI model? The OSI model is a framework of protocols that allows two
devices to communicate on a network or over the internet. Each layer of
the OSI model makes each layer responsible for over looking and carrying
out a specific task. I’ve made a cheat sheet that breaks everything
down into it’s most basic form. I will be referring to this chart
throughout the rest of this post.
The OSI layer is broken up into 7 layers. The top most layer is layer
7 and the lowest layer is Layer 1. Each layer has been given a name
that helps identify what is happening on each layer.
Let’s go over the OSI Layer in more detail
Layer 7 is the Application layer.
This is the layer that us a humans interact with the most. This layer
the application sets up rules on how an application will send and
receive data. Much like Languages, if both people don’t speak the same
one, a conversation will not likely amount to anything.
Layer 6 is is the Presentation layer. It helps the Application layer by formatting the data in such a way that both parties will be able to read it.
Layer 5 is the Session layer. It helps ensure that the data is synchronized.
Layer 4 is the Transport layer. It is responsible for creating and managing the packets that will go out on the network.
Layer 3 is the Network layer. It is
responsible for Addressing and Routing. This layer is in charge of the
IP address of the hosts as well as knowing how to route information to
another host. Because IP supports routing the destination host can be
local or out the internet.
Layer 2 is the data link layer. It
is responsible for Data frames and the Management of those frames. Data
frames deal with layer 2 addresses (MAC Address) which are non-routable
addresses. Technically Layer 2 can actually be broken up into two
sub-layers:
Logical Link Control
Media Access Control (NIC’s Mac Address)
Layer 1 is the Physical Layer. It
is responsible for talking with a physical device like a NIC. In
particular it’s changing the data into electronic pulses that can be
sent out on the wire.
Device Type by Layer
To give you a better idea what layers the network devices work at I created the device type column.
Layer 7 – I put gateway here. This is not the same
as a “Default Gateway”. This is a device that works kind of like a
translator. It is able to understand application languages like HTTP,
SMTP, etc. The term “Next Generation Firewalls” is some times applied to
these devices.
Layer 3 – Routers and “Swouters” devices go here. A
Swouter is a layer 3 switch. It has more than a couple ports on the back
and is capable of routing.
Layer 2 – This is the typical layer where switches
are put. Switches are able to look at traffic and filter data based on
MAC addresses.
Layer 1 – Typically Hubs and Repeaters are put here.
You don’t really see them anymore because they tend to be slow and
pretty brain dead. Because of this they only work “well” in a very small
network design.
TCP/IP Model
You will notice that the TCP/IP model only has 4 layers. The four
layers correlate to one or more of the OSI Model. Later versions have 5
and have different names. From what I’ve read we need to know both.
TCP/IP Stands for Transmission Control Protocol/Internet Protocol. It
is the basic communication protocol of the Internet. It can be used on
the internet as well as private networks. TCP/IP is based off the 4
layer Darpa model. Looking back at the “Cheat sheet” you will notice
that I’ve filled in a column with what protocols are used at each layer.
Transmission Protocols
There are two types of transmission protocol types in TCP/IP. These
protocols are called TCP and UDP. TCP is like Certified Mail and UDP is
like 1st class Mail. Only Certified mail tells you if the other side has
received all packages.
TCP (Transmission Control Protocol)
One to One
Connection Oriented
Reliable Communication
UDP (User Datagram Protocol)
Multicast (one to many)
Connectionless
Unreliable
Connection orientated communication means that connection must be
established before data can be exchanged. TCP uses a three-way handshake
to establish this connection.
Hi I’d like to talk
Hi I got the info. Here’s how to talk to me
Okay, Let’s begin talking
Internet Layer Protocols
IP
Protocol of the internet
Addressing
Routing
Arp
Type of Address Resolution Protocol
Resolves IP addresses to Hardware Address (MAC)
ICMP – Internet Control Message Protocol
Diagnostic and error reporting.
Ping uses ICMP
IGMP – Internet Group Management Protocol
Manages IP multicast group membership. Is NOT the same as ICMP!