Index:
[anchor=top][/anchor] How to check the block size and hardware sector size of any disk in your linux: How to have a tree view of your block devices (partitions, raid devices, lvm, etc) How to change the keyboard layout If you want to enable bonjour on your linux system, you may want to know that this protocol is supported by avahi-daemon How to see memory usage Just some sizes explanation How to monitor the processors A simple solution for the following error 0403-027 The parameter list is too long. How to find information about a file, like when it was last modified, updated, accessed How to prevent timeouts in SSH How to set up ssh keys How to get a list of users from /etc/passwd with perl How to unzip/unrar/extract .001 files How to find out the username if you have his real name How to generate random number in bash How to speedup rdesktop session via linux command line How to wipe GPT partition table / MBR from a drive How to wipe partition table / MBR from a drive How to wipe disk label of a drive How to export/unexport nfs mounts with command How to see the processes with I/O wait How to sort processes by context switch number How to monitor processes with I/O wait and cpu usage in the same time How to find the SATA link speed What to do if you keep getting "Enter password for default keyring to unlock" and the password is not working? How to see dmesg timestamp in human readable format [anchor=blocksizehwsectorsize][/anchor]topHow to check the block size and hardware sector size of any disk in your linux:
root@core:~# cat /sys/block/sd?/queue/logical_block_size
512
512
512
512
512
root@core:~# cat /sys/block/sd?/queue/hw_sector_size
512
512
512
512
512
[anchor=blockdevicestreeview][/anchor]top
How to have a tree view of your block devices (partitions, raid devices, lvm, etc):
root@pluto:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 19.8G 0 part
├─rootvg-root (dm-0) 254:0 0 512M 0 lvm /
├─rootvg-usr (dm-1) 254:1 0 2G 0 lvm /usr
├─rootvg-var (dm-2) 254:2 0 2G 0 lvm /var
├─rootvg-tmp (dm-3) 254:3 0 380M 0 lvm /tmp
├─rootvg-home (dm-4) 254:4 0 352M 0 lvm /home
├─rootvg-exploit (dm-5) 254:5 0 1G 0 lvm /exploit
└─rootvg-swap (dm-6) 254:6 0 1G 0 lvm [SWAP]
[anchor=changekeyboardlayout][/anchor]top
How to change the keyboard layout (to us for example):
# loadkeys us
[anchor=linuxenablebonjour][/anchor]top
If you want to enable bonjour on your linux system, you may want to know that this protocol is supported by avahi-daemon.
[anchor=memoryusage][/anchor]topHow to see memory usage (may vary with version of UNIX):
# svmon -u | more
# svmon -P | more
# ps aux | more
# ipcs -ma | more
[anchor=sizesexplanation][/anchor]top
Just some sizes explanation:
2^10 = k
2^20 = M
2^30 = G
2^40 = T
2^50 = P
2^60 = E
2^32 = 2^2 * 2^30 = 4GB
2^64 = 2^4 * 2^60 = 16E
[anchor=processorsmonitoring][/anchor]top
How to monitor the processors:
Linux:
core:~# [color=green]mpstat 1 10[/color]
Linux 2.6.32-core1.1-zubaz (core) 12/07/2011 _x86_64_
03:12:31 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
03:12:32 PM all 1.87 0.00 4.24 0.00 0.00 0.25 0.00 93.64 3431.00
03:12:33 PM all 1.24 0.00 4.96 0.12 0.12 0.12 0.00 93.43 4042.57
03:12:34 PM all 0.37 0.00 4.23 0.37 0.00 0.37 0.00 94.65 3795.05
03:12:35 PM all 1.74 0.00 13.28 0.12 0.00 0.37 0.00 84.49 12002.00
03:12:36 PM all 1.25 0.00 11.72 0.37 0.00 1.50 0.00 85.16 9082.18
03:12:37 PM all 1.12 0.00 10.43 0.00 0.12 1.12 0.00 87.20 6577.00
03:12:38 PM all 3.10 0.00 12.90 0.00 0.00 0.62 0.00 83.37 7377.23
03:12:39 PM all 3.36 0.00 12.20 0.00 0.00 0.25 0.00 84.18 6279.00
03:12:40 PM all 0.50 0.00 6.20 0.12 0.00 0.25 0.00 92.93 4627.72
03:12:41 PM all 0.25 0.00 4.73 0.37 0.00 0.12 0.00 94.53 3858.42
Average: all 1.48 0.00 8.49 0.15 0.02 0.50 0.00 89.36 6103.38
AIX:
root@aix~# [color=green]mpstat 1 5[/color]
System configuration: lcpu=2 ent=0.8 mode=Uncapped
cpu min maj mpc int cs ics rq mig lpa sysc us sy wa id pc %ec lcs
0 17 0 0 455 495 220 1 1 100 825 21 63 0 16 0.03 3.4 380
1 0 0 0 52 10 10 0 0 - 0 0 48 0 52 0.00 0.3 52
U - - - - - - - - - - - - 0 96 0.77 96.3 -
ALL 17 0 0 507 505 230 1 1 100 825 1 2 0 97 0.03 3.7 432
--------------------------------------------------------------------------------
0 1 0 0 419 479 215 1 0 100 641 18 65 0 17 0.02 2.6 366
1 0 0 0 63 10 10 0 0 - 0 0 55 0 45 0.00 0.4 62
U - - - - - - - - - - - - 0 97 0.78 97.1 -
ALL 1 0 0 482 489 225 1 0 100 641 0 2 0 98 0.02 2.9 428
--------------------------------------------------------------------------------
0 0 0 0 440 480 215 1 0 100 653 18 65 0 18 0.02 2.8 374
1 0 0 0 45 10 10 0 0 - 0 0 46 0 54 0.00 0.3 44
U - - - - - - - - - - - - 0 97 0.78 97.0 -
ALL 0 0 0 485 490 225 1 0 100 653 0 2 0 98 0.02 3.0 418
--------------------------------------------------------------------------------
0 0 0 871 621 955 455 1 4 100 19848 44 53 0 3 0.19 23.2 578
1 0 0 871 1043 21 14 0 3 100 9 0 39 0 61 0.01 1.3 1039
U - - - - - - - - - - - - 0 75 0.60 75.5 -
ALL 0 0 1742 1664 976 469 1 7 100 19857 10 13 0 77 0.20 24.5 1617
--------------------------------------------------------------------------------
0 2181 0 196 399 421 194 1 6 100 5937 37 58 0 4 0.09 11.0 324
1 301 0 196 347 173 87 0 9 100 222 17 54 0 29 0.01 1.2 349
U - - - - - - - - - - - - 0 88 0.70 87.8 -
ALL 2482 0 392 746 594 281 1 15 100 6159 4 7 0 89 0.10 12.2 673
[anchor=listtoolong][/anchor]top
A simple solution for the following error 0403-027 The parameter list is too long., example with rm:
# ls | wc -l
7634
# rm *
ksh: /usr/bin/rm: 0403-027 The parameter list is too long.
# [color=green]find . -type f -exec rm {} \;[/color]
# ls | wc -l
0
[anchor=fileinformation][/anchor]top
How to find information about a file, like when it was last modified, updated, accessed:
Linux:
florian@gzlinux:~$ [color=green]stat .profile[/color]
File: `.profile'
Size: 774 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 7 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ florian) Gid: ( 1000/ florian)
Access: 2012-02-27 09:05:28.000000000 +0100
Modify: 2011-09-05 11:57:35.000000000 +0200
Change: 2011-09-05 11:57:35.000000000 +0200
AIX:
[gzaix:root:/home/root:] [color=green]istat .profile[/color]
Inode 96 on device 10/8 File
Protection: rw-r--r--
Owner: 0(root) Group: 0(system)
Link count: 1 Length 129 bytes
Last updated: Thu Nov 4 14:33:25 2010
Last modified: Thu Aug 12 11:25:50 2010
Last accessed: Mon Feb 27 09:56:24 2012
[anchor=preventsshtimeout][/anchor]top
How to prevent timeouts in SSH
Server side:
Add the following two lines to /etc/ssh/sshd_config:ClientAliveInterval 30
ClientAliveCountMax 4
Client side:
Add the following two lines to /etc/ssh/ssh_config (or $HOME/.ssh/config if you don't have root access):ServerAliveInterval 30
ServerAliveCountMax 4
[anchor=setupsshkeys][/anchor]top
How to set up ssh keys:
1. On the client use the following command to generate a dsa key (if you prefer rsa, use it instead):ssh-keygen -t dsa 2. Copy the generated key to the .ssh/authorized_keys to the server where you want to log in without password. The key file is normally ~/.ssh/id_dsa.pub. [anchor=listpasswdperl][/anchor]topHow to get a list of users from /etc/passwd with perl:
# perl -p -e '$_ = (split(/[:\n]/))[0] . "\n"' /etc/passwd | xargs
[anchor=extract001][/anchor]top
How to unzip/unrar/extract .001 files:
florians-MacBook-Pro:ARCH florian$ ls -la
total 14458152
drwxr-xr-x 79 florian florian 2686 Mar 30 11:42 .
drwxr-xr-x@ 7 florian florian 238 Mar 30 09:17 ..
-rw-r--r--@ 1 florian florian 6148 Mar 30 11:31 .DS_Store
-rw-r--r--@ 1 florian florian 100000000 Mar 30 12:46 flt-binb.001
-rw-r--r--@ 1 florian florian 100000000 Mar 30 08:55 flt-binb.002
[...]
-rw-r--r--@ 1 florian florian 100000000 Mar 30 08:46 flt-binb.074
-rw-r--r--@ 1 florian florian 2270390 Mar 30 03:36 flt-binb.075
-rw-r--r--@ 1 florian florian 1725 Mar 29 22:58 flt-binb.sfv
florians-MacBook-Pro:DVD2 florian$ [color=green][b]7z e flt-binb.001 [/b][/color]
7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)
Processing archive: flt-binb.001
Extracting flt-binb.iso
Everything is Ok
Size: 8543797248
Compressed: 7402270390
[anchor=usernamefromrealname][/anchor]top
How to find out the username if you have his real name. This works if GECOS (user information) is filled correctly.
Most LINUX/UNIX (including AIX):gzaix@root:/home/root # grep -i max /etc/passwd
togex:!:216:1:RO/C//GZM/Toge.Max APPLI:/home/togex:/usr/bin/ksh
AIX:
gzaix@root:/home/root # lsuser -a gecos ALL | grep -i max
megot gecos=RO/C//GZM/Toge.Max APPLI
[anchor=bashgeneraterandomnumber][/anchor]top
How to generate random number in bash:
jupiter:~# echo $[ 1 + $[ RANDOM % 10 ]]
1
jupiter:~# echo $[ 1 + $[ RANDOM % 10 ]]
2
jupiter:~# echo $[ 1 + $[ RANDOM % 10 ]]
4
jupiter:~# echo $[ 1 + $[ RANDOM % 10 ]]
6
[anchor=rdesktopspeedup][/anchor]top
How to speedup rdesktop session via linux command line:
This is simple, you just have to add -P and -z which enables local disk cache and transmission compression. Example of such command with custom resolution and user/password requirement:florian@florian:~$ /usr/bin/rdesktop 10.8.10.1:2222 -P -z -u vbox -g 1280x750 -E -p -
Autoselected keyboard map en-us
Password:
WARNING: Remote desktop changed from 1280x750 to 1024x768.
How to wipe disk label of a drive
00:50:21 root@minivm:~# wipefs /dev/sdh
DEVICE OFFSET TYPE UUID LABEL
sdh 0x200 gpt
sdh 0x3a3817d5e00 gpt
sdh 0x1fe PMBR
00:50:51 root@minivm:~# wipefs --all /dev/sdh
/dev/sdh: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sdh: 8 bytes were erased at offset 0x3a3817d5e00 (gpt): 45 46 49 20 50 41 52 54
/dev/sdh: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdh: calling ioctl to re-read partition table: Success
00:51:08 root@minivm:~# wipefs /dev/sdh
00:51:10 root@minivm:~#
00:51:10 root@minivm:~# fdisk -l /dev/sdh
Disk /dev/sdh: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: 2135
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
[anchor=wipegptpartitiontablembr][/anchor]top
How to wipe partition table / MBR from a drive:
The following disk have GPT partition table and one partition:[root@florian ~]# fdisk -l /dev/sdb
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x366ade79
Device Boot Start End Blocks Id System
/dev/sdb1 1 38914 312571192+ 83 Linux
Trying to use DD to wipe the partition table. Actually it only deletes the partion(s):
[root@florian ~]# dd if=/dev/zero of=/dev/sdb bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.263887 s, 1.9 kB/s
[root@florian ~]# fdisk -l /dev/sdb
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
What you have to do in order to achieve this (there are many other ways too):
[root@florian ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable
New disk label type? msdos
(parted) quit
Information: You may need to update /etc/fstab.
[root@florian ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d4499
Device Boot Start End Blocks Id System
[anchor=wipepartitiontablembr][/anchor]top
How to wipe partition table / MBR from a drive:
Just MBR:dd if=/dev/zero of=/dev/sda bs=446 count=1
MBR and partitions: dd if=/dev/zero of=/dev/sda bs=512 count=1
[anchor=exportunexportnfscommand][/anchor]top
How to export/unexport nfs mounts with command, without populating /etc/exports:
exportfs -o rw,sync,mp,fsid=1 192.168.1.0/24:/mnt/fs/to/export
exportfs -u 192.168.1.0/24:/mnt/fs/to/export
[anchor=iowaitprocesses][/anchor]top
How to see the processes with I/O wait (processes in uninterruptible sleep marked with D):
watch -n 1 "ps -eo state,pid,cmd | grep ^D"
[anchor=sortprocessescs][/anchor]top
How to sort processes by context switch number:
watch -n 1 "pidstat -w | sort -k 4n | tail -n 20"
[anchor=monitorprociocpu][/anchor]top
How to monitor processes with I/O wait and cpu usage in the same time:
watch -n 1 "ps -eo state,pid,cmd | grep ^D ; top -b -n 1 -c | head -n 40"
[anchor=satalinkspeed][/anchor]top
How to find the SATA link speed:
Small note before the commands:
SATA REVISION => SPEED ({Gbit|MB}/s) SATA revision 1.0 => 1.5 Gbit/s, 150 MB/s SATA revision 2.0 => 3 Gbit/s, 300 MB/s SATA revision 3.0 => 6 Gbit/s, 600 MB/s SATA revision 3.2 => 16 Gbit/s, 1969 MB/sVia dmesg:
root@gate:~# [color=green]dmesg | grep -i sata | grep 'link up'[/color]
[ 9.603363] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
root@gate:~# [color=green]dmesg | grep -i --color ahci[/color]
[ 9.282782] ahci 0000:00:1f.2: version 3.0
[ 9.283862] ahci 0000:00:1f.2: irq 40 for MSI/MSI-X
[ 9.283917] ahci 0000:00:1f.2: SSS flag set, parallel bus scan disabled
[ 9.284069] ahci 0000:00:1f.2: AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
[ 9.284071] ahci 0000:00:1f.2: flags: 64bit ncq stag only ccc
[ 9.284469] scsi0 : ahci
root@gate:~# [color=green]dmesg | grep -i ahci | grep -i --color Gbps[/color]
[ 9.284069] ahci 0000:00:1f.2: AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
Via messages log:
root@gate:~# [color=green]grep -i SATA /var/log/messages | grep --color -i 'link up'[/color]
Nov 15 16:41:02 gate kernel: [ 1746.589306] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Nov 15 16:48:34 gate kernel: [ 9.176402] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Nov 16 04:21:16 gate kernel: [41571.102917] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Nov 16 06:45:45 gate kernel: [ 9.707394] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Nov 16 17:00:09 gate kernel: [ 9.603363] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Via hdparm:
root@gate:~# [color=green]hdparm -I /dev/sda | egrep "Model|speed|Transport"[/color]
Model Number: VBOX HARDDISK
* Gen2 signaling speed (3.0Gb/s)
[anchor=keyring][/anchor]top
What to do if you keep getting "Enter password for default keyring to unlock" and the password is not working?
Most probably the keyring is corrupt so unfortunately you will have to remove it. This is how I did it, maybe it works for you too! Source: https://bugzilla.redhat.com/show_bug.cgi?id=344611florian@florian:~$ ls -la .gnome2/keyrings/
total 12
drwx------. 2 florian florian 4096 Dec 3 12:46 .
drwx------. 18 florian florian 4096 Jan 29 2015 ..
-rw-------. 1 florian florian 148679 Nov 24 10:57 login.keyring
florian@florian:~/.gnome2/keyrings$ rm .gnome2/keyrings/login.keyring
florian@florian:~/.gnome2/keyrings$
[anchor=dmesgminuscapitalt][/anchor]top
How to see dmesg timestamp in human readable format
Default timestamp (for robots):
root@minivm:~# dmesg | tail
[2334087.877445] =================================== Tue 06 Apr 2021 10:40:01 PM EEST ===================================
[2334687.896271] =================================== Tue 06 Apr 2021 10:50:01 PM EEST ===================================
[2335287.914795] =================================== Tue 06 Apr 2021 11:00:01 PM EEST ===================================
[2335887.933947] =================================== Tue 06 Apr 2021 11:10:01 PM EEST ===================================
[2336487.959855] =================================== Tue 06 Apr 2021 11:20:01 PM EEST ===================================
[2337087.979591] =================================== Tue 06 Apr 2021 11:30:01 PM EEST ===================================
[2337688.000499] =================================== Tue 06 Apr 2021 11:40:01 PM EEST ===================================
[2338288.021460] =================================== Tue 06 Apr 2021 11:50:01 PM EEST ===================================
[2338888.091328] =================================== Wed 07 Apr 2021 12:00:01 AM EEST ===================================
[2339488.144357] =================================== Wed 07 Apr 2021 12:10:01 AM EEST ===================================
Human readable timestamp:
root@minivm:~# dmesg -T | tail
[Tue Apr 6 22:40:36 2021] =================================== Tue 06 Apr 2021 10:40:01 PM EEST ===================================
[Tue Apr 6 22:50:36 2021] =================================== Tue 06 Apr 2021 10:50:01 PM EEST ===================================
[Tue Apr 6 23:00:36 2021] =================================== Tue 06 Apr 2021 11:00:01 PM EEST ===================================
[Tue Apr 6 23:10:36 2021] =================================== Tue 06 Apr 2021 11:10:01 PM EEST ===================================
[Tue Apr 6 23:20:36 2021] =================================== Tue 06 Apr 2021 11:20:01 PM EEST ===================================
[Tue Apr 6 23:30:36 2021] =================================== Tue 06 Apr 2021 11:30:01 PM EEST ===================================
[Tue Apr 6 23:40:37 2021] =================================== Tue 06 Apr 2021 11:40:01 PM EEST ===================================
[Tue Apr 6 23:50:37 2021] =================================== Tue 06 Apr 2021 11:50:01 PM EEST ===================================
[Wed Apr 7 00:00:37 2021] =================================== Wed 07 Apr 2021 12:00:01 AM EEST ===================================
[Wed Apr 7 00:10:37 2021] =================================== Wed 07 Apr 2021 12:10:01 AM EEST ===================================
- Log in to post comments
- 20408 views