MAL - Memória Auxiliar do Lutieri

segunda-feira, abril 20, 2009

Case-insensitive search on man pages

Open /etc/env.d/70less.

Change from:

LESS="-R -M --shift 5"


To:

LESS="-I -R -M --shift 5"


Also make sure that /etc/env.d/00basic is setting LESS as the pager.

PAGER="/usr/bin/less"


The above instructions works for Gentoo.
If your distro doesn't have /etc/env.d/ you can add those lines to /etc/profile.

Marcadores: ,

quinta-feira, abril 24, 2008

Personalizações

Vou reunir algumas alterações que adoto como padrão nas máquinas desktop ou servers onde tenho contato. Acho interessante se adaptar a um determinado comportamento para que se consiga produzir mais em menos tempo.

Screen:

/etc/screenrc

#Enable UTF8 for input/output
defutf8 on

# Default encoding
defencoding ISO8859-15

# Automatically detach on hangup.
autodetach on

# Don't display the copyright page
startup_message off

# Change default scrollback value for new windows
defscrollback 1000

vbell on
vbell_msg " Mooo ---- Moo!! "

# Welcome the user:
echo "welcome :-)"
sleep 1



Shells:

Gentoo:
/etc/rc.conf

EDITOR="/usr/bin/vim"


/etc/inputrc

#http://lutierigb.blogspot.com/2008/03/bash-buscando-no-histrico-estilo-csh.html

"\e[5~": history-search-backward
"\e[6~": history-search-forward


bash -> /etc/profile.d/aliases.sh

alias ls="ls -F --color"
alias grep="grep --colour"
alias egrep="egrep --colour"

FreeBSD

shell csh -> /etc/csh.cshrc

alias ls ls -FG
alias grep grep --colour
alias egrep egrep --colour


shell sh - > /etc/profile

PS1="`whoami`@`hostname | sed 's/\..*//'`"
case `id -u` in
0) PS1="${PS1}# ";;
*) PS1="${PS1}$ ";;
esac

alias ls="ls -FG"
alias grep="grep --colour"
alias egrep="egrep --colour"

Marcadores:

quarta-feira, março 26, 2008

Bash buscando no histórico estilo CSH

Uma das coisas boas do shell padrão do FreeBSD(csh) é a forma de consultar comandos passados. Ao invés do ctrl-r que busca em qualquer parte dos comandos digitados é possível buscar por comandos que iniciam por algo. Um exemplo facilita a vida.

um trecho do meu histórico:

321 cd ..
322 cp Prison_Break-2006--_Great_Dragon_.part1.rar.part lala.part
323 unrar x lala.part
324 unrar x Prison_Break-2006--_Great_Dragon_.part1.rar
325 vi Prison_Break-2006--\(Great\ Dragon\)/My\ Special\ Programmes.txt
326 cd Desktop/
327 ccorreio

Caso eu queira reutilizar o comando número 325 bastaria eu digitar v ou vi e pressionar a seta para cima. E caso tivessem comandos anteriores a esse iniciados com v ou vi, respectivamente, eles iriam também ser sugeridos.

Como foi dito, no CSH isso já é padrão. Para o Bash fazer o mesmo deve-se fazer ou:

Adicione no arquivo ~/.inputrc:

"\e[A~": history-search-backward
"\e[B~": history-search-forward

Ou

os mesmos comandos em /etc/inputrc que vai refletir para todos usuários.

Uma outra dica que encontrei, no arquivo citado acima, no meu gentoo, foi é a que segue. Usada para descobrir o código das teclas para ser usado no bind.

# Quick dirty little note:
# To get the key sequence for binding, you can abuse bash.
# While running bash, hit CTRL+V, and then type the key sequence.
# So, typing 'ALT + left arrow' in Konsole gets you back:
# ^[[1;3D
# The readline entry to make this skip back a word will then be:
# "\e[1;3D" backward-word
#

Marcadores: ,

segunda-feira, fevereiro 25, 2008

Prompt retorna o último retorno

Compilando algumas dicas de como personalizar o prompt resultou na seguinte função que retorna o último status de algum comando.

Segue o código para ser colocado no arquivo ~/.bashrc

function exitstatus { EXITSTATUS="$?"
BOLD="\[\033[1m\]"
RED="\[\033[1;31m\]"
OFF="\[\033[m\]"

if [ "$EXITSTATUS" -eq "0" ]
then
PS1="${BOLD}\u@\h:\w [${EXITSTATUS}] \$${OFF} "
else
PS1="${BOLD}\u@\h:\w${OFF} [${RED}${EXITSTATUS}${OFF}] \$ "
fi

PS2="${BOLD}>${OFF} "
}

PROMPT_COMMAND=exitstatus

Fontes:
http://blog.gnist.org/article.php?story=BashPromptWithExitStatus
http://doocy.net/archives/2004/11/19/add-dynamic-coloring-of-last-return-value-to-your-bash-shell-prompt/

Marcadores:

domingo, fevereiro 10, 2008

Manuais, man, apropos, whatis

Todos sabem consultar os manuais on-line do linux com o comando man. Até aí tudo bem. O problema que acontece freqüentemente comigo está relacionado a minha memória. Até aí nenhuma novidade também.

Acontece que eu sempre gosto de ver todas as opções que eu tenho disponíveis quando tenho que fazer escolhas. De repente existe uma que se encaixe melhor do que as que sabia que existiam. Por isso é da minha natureza fazer buscas genéricas afim de encontrar e me poder me deliciar com o maior número de opções disponíveis. :-) That's me!!

O comand whatis procura por por manuais com o nome informado.
Exemplo:

# whatis ldif
ldif (5) - LDAP Data Interchange Format

Já o comando apropos busca na base de dados do whatis por manuais contendo a palavra informada. Mesmo que seja na descrição do manual.
Exemplo:

# apropos ldif
ldif (5) - LDAP Data Interchange Format
slapcat (8) - SLAPD database to LDIF utility
slapd-ldif (5) - LDIF backend to slapd
slapindex (8) - SLAPD index to LDIF utility

man -k faz a mesma coisa que o comando apropos
man -f faz a mesma coisa que o comando whatis

Porém essa base de dados do whatis NÃO é criada automaticamente e cabe ao administrador do sistema fazer isso quando se sentir confortável. Para isso execute:

makewhatis

para mais informações vai se acostumando e lendo o manual do makewhatis.

Marcadores:

domingo, janeiro 20, 2008

Finding Open Files with lsof Command

When a file is in use by a process, it is possible to delete the file - OR at least it may appear that is the case. The filename is no longer visible via the ls command, but it is there until the process using it exits.

For example, let's say Sysadmin1 runs a sniffer process in the background to capture and save packets to a file. The capture file starts growing bigger over time. Instead of killing the process, he/she simply deletes the capture file, thinking this will recover the disk space. It doesn't. Believing everything is well, Sysadmin1 goes home.

Now Sysadmin2 shows up and notices the box is running out of disk space. Naturally, the admin wants to figure out what’s rapidly consuming disk space. The easiest way for the SysAd to locate the growing file is to use the lsof command.

Another instance the lsof would be helpful is when a filesystem refuses to unmount due to open files.

Here are a few practical examples of using the lsof command.

To list all the open files on the var filesystem:
# lsof +D /var

To list all open files in your current directory only:
# lsof +d .

To list all open Internet files:
# lsof -i

To list all files currently open by user joe:
# lsof -u joe

To list all files open by syslog-ng (this is a great quick way to find
logs!):
# lsof -c syslog-ng

To list all files open by pid:
# lsof -p PID

Note: There are additional parameters you can add to the command to narrow the listing to include or exclude types of files and much more!

# lsof -help



Copiado descaradamente daqui:
http://esofthub.blogspot.com/2008/01/finding-open-files-with-lsof-command.html

Marcadores:

terça-feira, janeiro 15, 2008

PS

ps aux -ww

o -ww exibe toda a coluna COMMAND. Não corta de acordo com o tamanho da tela. As vezes, temos comandos grandes, com vários parâmetros, como no exemplo abaixo, e caso essa opção não seja utilizada o PS ajusta a saída de acordo com o tamanho da tela.



# ps -u -p 38751
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 38751 0.0 0.0 3636 1104 ?? Ss 19Dec07 0:12.22 /usr/sbin/syslogd -l /var/run/log -l /var/chroot/named/var/run

# ps -u -p 38751 -ww
root 38751 0.0 0.0 3636 1104 ?? Ss 19Dec07 0:12.22 /usr/sbin/syslogd -l /var/run/log -l /var/chroot/named/var/run/log -4 -b 172.16.0.1

Marcadores:

"Command not found" para scripts no FreeBSD

# vi /usr/local/sbin/syncsquid

!/bin/sh
/usr/local/bin/rsync -avx --delete serverA::squid/ /usr/local/etc/squid/confs/

:x

# chmod 755 /usr/local/sbin/syncsquid

# syncsquid
syncsquid: Command not found.

# whereis syncsquid
syncsquid: /usr/local/sbin/syncsquid

# rehash

# syncsquid
receiving file list ... done

sent 73 bytes received 424 bytes 142.00 bytes/sec
total size is 103885 speedup is 209.02

# echo ":-D"
:-D

Marcadores: ,



Chat with Lutieri G. B.

Subscribe in a reader