System
Change HostName
- Details
- Parent Category: Linux && Unix Services
- Category: System
- Written by Mahdi Bahmani Ciahmard
- Hits: 22
Checking your Linux host name
First, see if your host name is set correclty using the following commands:
#uname -n
#hostname -a
#hostname -s
#hostname -d
#hostname -f
#hostname
If the above commands return correctly with no errors then all may be well; however, you may want to read on to verify that all settings are correct.
Normally we will set the hostname of a system during the installation process.
Change the hostname on a running Linux system
On any Linux system you can change its hostname with the command ‘hostname‘.
#hostname
without any parameter it will output the current hostname of the system.
#hostname –fqd
it will output the fully qualified domain name (or FQDN) of the system.
#hostname NEW_NAME
will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations - see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.
Permanent hostname change on Debian based Linux systems
Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
#cat /etc/hostname
debianadmin
So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run
/etc/init.d/hostname.sh startto make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).
If you want more details check hostname man page
Use sysctl to change the hostname
use sysctl to change the variable kernel.hostname:
Use:
#sysctl kernel.hostname
to read the current hostname, and
#sysctl kernel.hostname=NEW_HOSTNAME
to change it.
If you want more details check sysctl man page
You can use the same process for all debian based distributions and other linux machines
also.
vi Help
- Details
- Parent Category: Linux && Unix Services
- Category: System
- Written by Mahdi Bahmani Ciahmard
- Hits: 67
Cursor movement
h - move left
j - move down
k - move up
l - move right
w - jump by start of words (punctuation considered words)
W - jump by words (spaces separate words)
e - jump to end of words (punctuation considered words)
E - jump to end of words (no punctuation)
b - jump backward by words (punctuation considered words)
B - jump backward by words (no punctuation)
0 - (zero) start of line
^ - first non-blank character of line
$ - end of line
G - Go To command (prefix with number - 5G goes to line 5)
Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.
Insert Mode - Inserting/Appending text
i - start insert mode at cursor
I - insert at the beginning of the line
a - append after the cursor
A - append at the end of the line
o - open (append) blank line below current line (no need to press return)
O - open blank line above current line
ea - append at end of word
Esc - exit insert mode
Editing
r - replace a single character (does not use insert mode)
J - join line below to the current one
cc - change (replace) an entire line
cw - change (replace) to the end of word
c$ - change (replace) to the end of line
s - delete character at cursor and subsitute text
S - delete line at cursor and substitute text (same as cc)
xp - transpose two letters (delete and paste, technically)
u - undo
. - repeat last command
Marking text (visual mode)
v - start visual mode, mark lines, then do command (such as y-yank)
V - start Linewise visual mode
o - move to other end of marked area
Ctrl+v - start visual block mode
O - move to Other corner of block
aw - mark a word
ab - a () block (with braces)
aB - a {} block (with brackets)
ib - inner () block
iB - inner {} block
Esc - exit visual mode
Visual commands
> - shift right
< - shift left
y - yank (copy) marked text
d - delete marked text
~ - switch case
Cut and Paste
yy - yank (copy) a line
2yy - yank 2 lines
yw - yank word
y$ - yank to end of line
p - put (paste) the clipboard after cursor
P - put (paste) before cursor
dd - delete (cut) a line
dw - delete (cut) the current word
x - delete (cut) current character
Exiting
:w - write (save) the file, but don't exit
:wq - write (save) and quit
:q - quit (fails if anything has changed)
:q! - quit and throw away changes
Search/Replace
/pattern - search for pattern
?pattern - search backward for pattern
n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new throughout file
:%s/old/new/gc - replace all old with new throughout file with confirmations
Working with multiple files
:e filename - Edit a file in a new buffer
:bnext (or :bn) - go to next buffer
:bprev (of :bp) - go to previous buffer
:bd - delete a buffer (close a file)
:sp filename - Open a file in a new buffer and split window
ctrl+ws - Split windows
ctrl+ww - switch between windows
ctrl+wq - Quit a window
ctrl+wv - Split windows vertically
source:
http://www.worldtimzone.com/res/vi.html
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
http://www.lagmonster.org/docs/vi.html
dd Disk Speed
- Details
- Parent Category: Linux && Unix Services
- Category: System
- Written by Mahdi Bahmani Ciahmard
- Hits: 29
speed
So how do you find out how fast is your hard disk under Linux? Is it running at SATA I (150 MB/s) or SATA II (300 MB/s) speed w/o opening computer case or chassis?
You can use hdparm command. It provides a command line interface to various hard disk ioctls supported by the stock Linux ATA/IDE/SATA device driver subsystem. Some options may work correctly only with the latest kernels (make sure you have cutting edge kernel installed). I also recommend to compile hdparm with the include files from the latest kernel source code. It provides more accurate result.
Several areas can be looked at troubleshoot or optimize file i/o performance. The order was initially "what came to mind", but I then tried to organize it by complexity and likelihood of getting useful information or results.
1) You might want to test different file systems -- "xfs" is usually faster for large file read/writes, (but sucks at "rm"ing large numbers of files), reiserfs is supposed to be better at handling large numbers of small files better, but I haven't seen any recent statistics. 1a) Note that file system parameters and defaults may have changed between releases if you are using newly formatted partitions.
2) Try comparing the device READ performance try using "hdparm" (in package of same name). I don't know if hdparm will work on pseudo devices like "raid disks", but in the simple case, it does a good job of benchmarking maximum read speeds independent of the file system.
Example:
hdparm -t /dev/sda
(output looks like:
/dev/sda:
Timing buffered disk reads: 60 MB in 3.00 seconds = 20.00 MB/sec)
For a single partition you can use:
hdparm -t /dev/sda1
For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active processes) with at least a couple of megabytes of free memory. This displays the speed of reading directly from the Linux buffer cache without disk access. This measurement is essentially an indication of the throughput of the processor, cache, and memory of the system under test. Here is for loop to run test 3 time in a row:
xen02:~# for i in 1 2 3; do hdparm -tT /dev/sda; done
/dev/sda:
Timing cached reads: 8862 MB in 1.99 seconds = 4453.67 MB/sec
Timing buffered disk reads: 60 MB in 3.02 seconds = 19.88 MB/sec
/dev/sda:
Timing cached reads: 9582 MB in 1.99 seconds = 4807.38 MB/sec
Timing buffered disk reads: 40 MB in 3.02 seconds = 13.22 MB/sec
/dev/sda:
Timing cached reads: 6734 MB in 2.00 seconds = 3374.21 MB/sec
Timing buffered disk reads: 56 MB in 3.06 seconds = 18.30 MB/sec
-t :perform device read timings
-T : perform cache read timings
/dev/sda : Hard disk device file
To find out SATA hard disk speed, enter:
sudo hdparm -I /dev/sda | grep SATA
With IDE disks, hdparm will tell you what transfer mode is being used with your disks. With SCSI drives, the drivers show the maximum transfer speed (bus transfer rate) during the boot process. Theoretically, that shouldn't have changed, but is an unlikely possibility of performance differences.
3) In your "write" tests, you should ensure that the "writes" are completed before they return -- i.e. use a "sync" command after the "dd" to ensure that the contents are actually written to disk, i.e. use:
"sync;time bash -c "(dd if=/dev/zero of=bf bs=8k count=500000; sync)"
The 1st sync makes sure any previous writes are purged before starting "dd", the 2nd makes sure that the blocks written by "dd" are actually written to disk before the time is measured
xen:~# sync;time bash -c "(dd if=/dev/zero of=/root/z1/bf bs=8k count=500000; sync)"
500000+0 records in
500000+0 records out
4096000000 bytes (4.1 GB) copied, 76.0921 s, 53.8 MB/s
real 1m19.257s
user 0m0.744s
sys 0m22.333s
xen:~# hdparm -tT /dev/sdc
.
Linux Get List of Installed Software for Reinstallation / Restore All the Software Programs
- Details
- Parent Category: Linux && Unix Services
- Category: System
- Written by Mahdi Bahmani Ciahmard
- Hits: 50
If you are using Debian or Ubuntu Linux, use the dpkg command to list installed software:
$ dpkg --get-selections
You can store list of installed software to a file called /backup/installed-software.log, enter:
$ dpkg --get-selections > /backup/installed-software.log
RPM based distributions (RHEL, Fedora, Redhat, CentOS, Suse Linux) user try the rpm command to get list of all installed software, enter:
$ rpm -qa
OR
$ rpm -qa > /backup/installed-software.log

