Varis

De whats Wiki

Dreceres ràpides: navegació, cerca

Per regenerar la taula de hash que utitliza bash per a cachejar el path dels executables

hash -r

Llistar funcions que té definides o utilitza un binari o llibreria

whats@x61s:~/Desktop/ipartyx$ objdump -T l13 

l13:     file format elf32-i386 

DYNAMIC SYMBOL TABLE:
00000000      DF *UND*  000000ab              mod_check_password
08048354 g    DF .init  00000000  Base        _init
00000000      DF *UND*  000002f6  GLIBC_2.0   getpass
080496cc g    D  *ABS*  00000000  Base        __bss_start
00000000      DF *UND*  000000e7  GLIBC_2.0   __libc_start_main
08048584 g    DF .fini  00000000  Base        _fini
080496cc g    D  *ABS*  00000000  Base        _edata
080496d0 g    D  *ABS*  00000000  Base        _end
080485a4 g    DO .rodata        00000004  Base        _IO_stdin_used
00000000  w   D  *UND*  00000000              _Jv_RegisterClasses
00000000  w   D  *UND*  00000000              __gmon_start__


whats@x61s:~/Desktop/ipartyx$ objdump -T auth_module.so 

auth_module.so:     file format elf32-i386

DYNAMIC SYMBOL TABLE:
00000460 l    d  .init  00000000              .init
000004b0 l    d  .text  00000000              .text
00000724 l    d  .fini  00000000              .fini
00000740 l    d  .rodata        00000000              .rodata
000007a4 l    d  .eh_frame      00000000              .eh_frame
000017a8 l    d  .ctors 00000000              .ctors
000017b0 l    d  .dtors 00000000              .dtors
000017b8 l    d  .jcr   00000000              .jcr
000018a4 l    d  .data  00000000              .data
000018ac l    d  .bss   00000000              .bss
00000630 g    DF .text  000000ab  Base        mod_check_password
000005e0 g    DF .text  0000004b  Base        mod_get_next_level_pwd
00000000      DF *UND*  0000017f  GLIBC_2.0   puts
00000460 g    DF .init  00000000  Base        _init
00000000      DF *UND*  000001d4  GLIBC_2.0   malloc
000018ac g    D  *ABS*  00000000  Base        __bss_start
00000724 g    DF .fini  00000000  Base        _fini
00000000  w   DF *UND*  000000b6  GLIBC_2.1.3 __cxa_finalize
000018ac g    D  *ABS*  00000000  Base        _edata
000018b0 g    D  *ABS*  00000000  Base        _end
00000580 g    DF .text  00000052  Base        compara
00000000  w   D  *UND*  00000000              _Jv_RegisterClasses
00000000  w   D  *UND*  00000000              __gmon_start__


Llistar els simbols d'un objecte

 nm llibreria

whats@x61s:~/Desktop/ipartyx$ nm /lib/libpthread.so.0
nm: /lib/libpthread.so.0: no symbols


Utilitat per descobrir errors en codi C

pscan
http://www.striker.ottawa.on.ca/

Redirigim la sortida del grub cap a un port sèrie (/boot/grub/menu.lst)

serial -unit=0 -speed=115200
terminal -timeout=10 serial console

Redirigim la sortida del kernel cap a un port sèrie (parametres d'arrencada)

console=tty0 console=ttyS0,115200

Assignar la direcció del port sèrie a un dispositiu de port sèrie

setserial /dev/ttyS0 uart 16550A port 0x0408 irq 4

Iniciar una sessió a un port sèrie

sx:2345:respawn:/sbin/agetty 115200 ttySx vt100

Canviar la velositat d'una interficie

ethtool -s eth0 speed 1000 duplex full autoneg off

Per a redhat afegir

ETHTOOL_OPTS="speed 1000 duplex full"


Remove beeps, from all GNU-readline programs

echo 'set bell-style none' >> ~/.inputrc

Remove all X-console beeps

xset b off

Remove all system-console beeps

setterm -blength 0


Re-read partition table

/sbin/blockdev --getsize /dev/sda

capar la sortida a colunes, pero acabar mostrant tota la línia

fold -w3


Compilar un .po

msgfmt arxiu.po

Fork Bomb per bash

:(){ :|:& };: 

Per desactivar la randomització de la pila

sysctl -w kernel.randomize_va_space=0


Configurar mtrr

echo "disable=0" >| /proc/mtrr 
echo "base=0x00000000 size=0x40000000 type=write-back" >| /proc/mtrr

mapejar un fitxer a un dispositiu

losetup /dev/loop0 imatge.iso

Desactivar ipv6

/etc/modutils/keep
alias net-pf-10 off
alias ipv6 off

Reinstal·lar el grub a l'MBR

grub> root (hd1,0)
grub> setup (hd1) 

Formatejar un sistema del fitxers optimitzant-lo per l'ús que s'en vol fer

mkfs.ext3 -T [small, floppy, news, largefile, and largefile4] /dev/sda8

enviar fitxers per consola:

uuencode grep.tar.gz | mail -s "grep" asellares@gnuine.com

posar la ethernet en un mode:

ethtool -s eth0 speed 100 duplex full autoneg off

Per veure la temperatura del disc i altre informacio

smartctl -A /dev/hda

Per canviar el grup primari

newgrp - share

Per veure les opcions del kernel que es poden canviar en calent

sysctl -a

Per veure distro i versió (només LSB compilants)

lsb_release -a


Per veure el q esta fent un altre usuari.

script /dev/pts/4
         $ smartctl -i /dev/hda
         $ smartctl -Hc /dev/hda
         $ smartctl -A /dev/hda
stty -a

Per canviar el nom a multiples fitxers alhora

rename .htm .html *.htm

Per recollir informació de la màquina

sysreport

Determinar el tamanx dels diferents segments

whats@localhost:~$ size /bin/ls
  text    data     bss     dec     hex filename
 71329     892     940   73161   11dc9 /bin/ls


Kernel performance

TIP 176:
    Kernel Performance Tuning - /Documentation/sysctl/vm.txt documents kernel settings to
    improve performance. Below are some examples.
      overcommit_memory:  0 -- default estimates the amount of memory for malloc
                          1 -- kernel pretends there is always enough memory until it runs out
                          3 -- never overcommit
         $ cat /proc/sys/vm/overcommit_memory
         0
      page-cluster:
           The Linux VM subsystem avoids excessive disk seeks by reading
           multiple pages on a page fault. The number of pages it reads
           is dependent on the amount of memory in your machine.
       
           The number of pages the kernel reads in at once is equal to
           2 ^ page-cluster. Values above 2 ^ 5 don't make much sense
           for swap because we only cluster swap data in 32-page groups.
         $ cat /proc/sys/vm/page-cluster
         3
      min_free_kbytes:
           This is used to force the Linux VM to keep a minimum number
           of kilobytes free.  The VM uses this number to compute a pages_min
           value for each lowmem zone in the system.  Each lowmem zone gets
           a number of reserved free pages based proportionally on its size.
         $ cat /proc/sys/vm/min_free_kbytes
         3831
      max_map_count:
           This file contains the maximum number of memory map areas a process
           may have. Memory map areas are used as a side-effect of calling
           malloc, directly by mmap and mprotect, and also when loading shared
           libraries.
           While most applications need less than a thousand maps, certain
           programs, particularly malloc debuggers, may consume lots of them,
           e.g., up to one or two maps per allocation.
           The default value is 65536.
         $ cat /proc/sys/vm/max_map_count
         65536
       Also see http://people.redhat.com/alikins/system_tuning.html


TIP 177:

    IO Scheduler - /Documentation/block/as-iosched.txt documents kernel settings for disk
    performance.
    If you're not sure what partitions you have "$ cat /proc/partitions". This example
    assumes hda, and you can see some of the kernel settings:
         $ ls /sys/block/hda/queue/iosched
         back_seek_max  back_seek_penalty  clear_elapsed  fifo_batch_expire  fifo_expire_async
          fifo_expire_sync  find_best_crq  key_type  quantum  queued
    References: http://lwn.net/Articles/102505/
                http://bhhdoa.org.au/pipermail/ck/2004-September/000961.html



Crear una llibreria dinàmica

gcc -c -fpic ../src/test.c -o test.o
gcc -shared -o libpersonal.so test.o


Modificar l'execució

$ exec > mfile
$ ls
$ date
$ exec > /dev/tty

Closing the "output" file descriptor

$ >&3-

Closing the "input" file descriptor

$ 3<&-

Crear un patch

diff -c prog.c.old prog.c > prog.patch

Aplicar-lo

 $ patch < prog.patch

Per veure com s'escriu una paraula

look

Per ampliar una comanda i tirar-la amb alguna variant

echo f{ee,ie,oe,um}

Per editar una comanda molt llarga

fc

Logrotate

# see "man logrotate" for details
# rotate log files weekly
#chirico changes to monthly
monthly
# keep 4 weeks worth of backlogs
# keep 12 months of backup
rotate 12
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
   monthly
   create 0664 root utmp
   rotate 1

Fitxers oberts en un directori o subdirectoris

lsof +D /etc

Estat de memoria compartida, semafors o cues de missatges:

ipcs
ipcs -l

Per veure les estadístiques del sistema i l'ample de banda dels dispositius del sistema

iostat -k

Per veure l'ús de la memòria

vmstat -S M

Per borrar un fitxer de forma segura

shred -n 100 -z -u test2

Per veure totes les conexions a internet de la màquina i els processos relacionats

lsof -i -U
       Software RAID: Two good references
         http://www.tldp.org/HOWTO/Software-RAID-HOWTO-1.html
         http://lists.us.dell.com/pipermail/linux-poweredge/2003-July/014331.html
       Note, you must setup grub for each RAID 1 device. Suppose you have
       2 SCSI drives (sda and sdb). By default grub is setup on sda; but, you
       need to enable it for sdb (/dev/hdb for ide) as follows:
          grub>device (hd0) /dev/sdb
          grub>root (hd0,0)
          grub>setup (hd0)
          Checking if "/boot/grub/stage1" exists... no
          Checking if "/grub/stage1" exists... yes
          Checking if "/grub/stage2" exists... yes
          Checking if "/grub/e2fs_stage1_5" exists.. yes
          Running "embed /grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded.
         succeeded
          Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub
        .conf"... succeeded.
        Done.
         grub>
         grub>quit


Arrencar en mode root al grub

afegir single

Permisos "especials"

Octal digit  Binary value      Meaning                      
           0           000       all cleared                       
           1           001       sticky                                  
           2           010       setgid                                  
           3           011       setgid, sticky                          
           4           100       setuid                                  
           5           101       setuid, sticky                          
           6           110       setuid, setgid                          
           7           111       setuid, setgid, sticky                  
    cp --parents. What does this option do?
    Assume you have the following directory structure
           .
           |-- a
           |   `-- b
           |       `-- c
           |           `-- d
           |               |-- file1
           |               `-- file2
           `-- newdir


    Issue the following command:
        $ cp --parents ./a/b/c/d/* ./newdir/
    Now you have the following:
           .
           |-- a
           |   `-- b
           |       `-- c
           |           `-- d
           |               |-- file1
           |               `-- file2
           `-- newdir
               `-- a
                   `-- b
                       `-- c
                           `-- d
                               |-- file1
                               `-- file2

Ensamblador AS

     Learning Assembly.
    Once you have written the source, assuming the file is "exit.s", it can be compiled as follows:
           $ as exit.s -o exit.o
           $ ld exit.o -o exit


    Here is the program:
        #
        #INPUT:  none
        #
        #OUTPUT:         returns a status code. This can be viewed
        # by typing
        #
        # echo $?
        #
        # after running the program
        #
        #VARIABLES:
        # %eax holds the system call number
        # (this is always the case)
        #
        # %ebx holds the return status
        #
                .section .data
                .section .text
                .globl _start
        _start:
                movl $1, %eax # this is the linux kernel command
                # number (system call) for exiting
                # a program
                movl $0, %ebx # this is the status number we will
                # return to the operating system.
                # Change this around and it will
                # return different things to
                # echo $?
                int $0x80 # this wakes up the kernel to run
                # the exit command
    After running this program, you can get the exit code.
           $ exit $?
           0
    That is about all it does; but, get the book for more details. The
    book is free.
         http://savannah.nongnu.org/download/pgubook/



Fitxers modificats els ultims 5 a 10 minuts

find . -mmin +5 -mmin -10 

Per montar un directori dins d'un altre sense els montages que té per sota

mount --bind olddir newdir

A l'fstab hi aniria una línia com:

/tmp/source                  /destination                    none    bind

Per montar un directori dins d'un altre amb els montages que té per sota

mount --rbind olddir newdir

Per moure un montatge a un altre lloc. Amb la comanda mount et mostra com si estigues montat a dos llocs, pero realment no és així.

mount --move olddir newdir

Per saber els processos que escriuen en disc

echo 1 > /proc/sys/vm/block_dump
Dins els logs del sistema hi apareixerà el PID i el nom de procés

Canviar la codificació d'un fitxer

recode ISO-8859-15..UTF-8

Accedir a l'ajuda del jstar

ctrl + j

Matar tots els processos que la paraula apareix en el nom

pkill paraula

Comanda per a separar per columnes

columns

o

col

Per a que el kernel redirigeixi un tty a un port sèrie

append="console=tty0 console=ttyS0,9600n8"

Per fer whois a un servidor en concret

whois -h whois.cat nosaltres.cat

Per arrencar les X en mode verbose

startx -- -verbose

preseed

debian/priority=critical
preseed/url=http://172.16.12.158/repo/preseed.cfg
#   debconf-get-selections --installer > file
#   debconf-get-selections >> file
debconf-set-selections -c preseed.cfg

Caducitat de contranenyes

chage -l tecnicrm