вторник, 25 мая 2010 г.

CPUID from c++

a.cpp:
#include 
 
int main(int argc, char **argv) {
  int b;
  for (int a = 0; a < 5; a++) {
    asm ( "mov %1, %%eax; " // a into eax
          "cpuid;"
          "mov %%eax, %0;" // eeax into b
          :"=r"(b) /* output */
          :"r"(a) /* input */
          :"%eax" /* clobbered register */
         );
    std::cout << "The code " << a << " gives " << b << std::endl;
  }
  return 0;
}


# g++ a.cpp -o a
# exec ./a 
The code 0 gives 5
 The code 1 gives 3908
 The code 2 gives 1616597249
# echo "obase=16; 3908" | bc
F44
http://processorfinder.intel.com
in search sSpec=0F44h
 
 
or
 
sudo dmidecode --type bios 
sudo biosdecode
sudo hwinfo --bios | less
sudo lshw
gksudo lshw-gtk 
 
 

Check if your processor has virtualization support

egrep '^flags.*(svm|vmx)' /proc/cpuinfo

четверг, 20 мая 2010 г.

Unix Toolbox

source: http://cb.vu/unixtoolbox.xhtml
http://sleepyhead.de

Unix Toolbox


This document is a collection of Unix/Linux/BSD commands and tasks which are useful for IT work or for advanced users. This is a practical guide with concise explanations, however the reader is supposed to know what s/he is doing.




Unix Toolbox revision 14.2

The latest version of this document can be found at http://cb.vu/unixtoolbox.xhtml. Replace .xhtml on the link with .pdf for the PDF version and with .book.pdf for the booklet version. On a duplex printer the booklet will create a small book ready to bind. This XHTML page can be converted into a nice PDF document with a CSS3 compliant application (see the script example). See also the about page.

Error reports and comments are most welcome - c@cb.vu Colin Barschel.

© Colin Barschel 2007-2009. Some rights reserved under Creative Commons.


System

Hardware | Statistics | Users | Limits | Runlevels | root password | Compile kernel | Repair grub

Running kernel and system information

# uname -a # Get the kernel version (and BSD version)
# lsb_release -a # Full release info of any LSB distribution
# cat /etc/SuSE-release # Get SuSE version
# cat /etc/debian_version # Get Debian version

среда, 19 мая 2010 г.

GNU Midnight Commander

GNU Midnight Commander User's Guide

http://www.chm.tu-dresden.de/edv/mc/mc4.5/manual1.html#8
M=Alt for me
M-o
If the other panel is a listing panel and you are standing on a directory in the current panel, then the other panel contents are set to the contents of the currently selected directory (like Emacs' dired C-o key) otherwise the other panel contents are set to the parent dir of the current dir.
M-z return history

M-a copy pwd to command line

четверг, 13 мая 2010 г.

Best Vim Tips

http://vim.wikia.com/wiki/Best_Vim_Tips

Ctrl+X Ctrl+F = insert filename in current dir
C^+N = autocomplite word
C^r+" or C^r+ = paste in edit mode or to command line/search
C^x+C^l = autocomplite line

~/.vimrc

set number  
set expandtab
set textwidth=79
set tabstop=8
set softtabstop=4
set shiftwidth=4
set autoindent

syntax on

http://stackoverflow.com/questions/164847/what-is-in-your-vimrc

:%s/fred/joe/igc : general substitute command
:%s/\r//g : delete DOS Carriage Returns (^M)
:'a,'bg/fred/s/dick/joe/gc : VERY USEFUL
:s/\(.*\):\(.*\)/\2 : \1/ : reverse fields separated by :
# non-greedy matching \{-}
:%s/^.\{-}pdf/new.pdf/ : to first pdf)
:s/fred/a/g : substitute "fred" with contents of register "a"
CTRL-R CTRL-W : pull word under the cursor into a command line or search
:%s/^\(.*\)\n\1/\1$/ : delete duplicate lines
:help /\{-}
# multiple commands
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
:%s/suck\|buck/loopy/gc : ORing
:s/__date__/\=strftime("%c")/ : insert datestring

bash sed recursive replace in all files

  • find ./ -type f -exec sed -i ’s/string1/string2/g’ {} \;
  • find ./ -type f | xargs sed -i ’s/string1/string2/g’
  • grep -rl matchstring somedir/ | xargs sed -i ’s/string1/string2/g’
  • grep -rl matchstring somedir/ | xargs sed -i ’s|string1|string2|g’
  • sed -i ’s/oldText/newText/g’ `grep -ril ‘oldText’ *`
  • rpl -x’.cpp’ -x’.h’ -pR “old-string” “new-string” *
  • find . -type f -print0 | xargs -0 perl -i.bak -pe 's/subdomainA\.example\.com/subdomainB.example.com/g'

s//g - g on the end will replace globally – all instances of string1