Skip to main content

Posts

Showing posts from 2015

Recursivamente procurar e substituir uma palavra em vários arquivos

O sistema operacional Linux oferece várias ferramentas para gerenciamento e edição de arquivos, neste artigo mostram como usar alguns comandos para substituir uma ou mais palavras em um arquivo de texto. Um comando bastante útil quando você precisa substituir uma ou mais palavras em alguns arquivos é este: sed -i 's/parola1/parola2/g' *.txt Desta forma será substituído parola1 por parola2 em todos os arquivos de texto no diretório atual. Mas se tivéssemos que fazer isso também substituir os arquivos em algumas pastas, então o comando acima se torna-se: find ./ -type f -exec sed -i 's/parola1/parola2/g' '{}' \; Neste caso, eu fiz sem o filtro do tipo de arquivo, ou seja sem a extensão .txt. Por isso todos os arquivos serão levados em conta no diretório atual e em seus subdiretórios. No comando find que foi utilizado, o “-exec” que permite executar um comando, a cada vez que um arquivo é encontrado, que respeite as regras estabelecidas para a pesquisa

Backup das permissões de arquivos e pastas no Linux

Recentemente precisei fazer backup das permissões de arquivos e pastas no Linux, pois precisava para caso ocorresse alguma coisa errada nas permissões que eu estava mexendo. Então encontrei dois comandos para resolver isso, um para fazer o backup e outro para restaurar. O legal é que ele preserva tudo, tanto as permissões quanto o dono e o grupo, dessa forma é possível fazer um backup completo deles em um simples arquivo texto e restaurá-los depois. O comando responsável para o backup é o getfacl e podemos utilizar a seguinte sintaxe: getfacl -Rp /home/rodrigo/Desktop > /home/rodrigo/permissoes_desktop.txt A opção -R (maiúsculo) é para fazer backup das permissões recursivamente, ou seja, nas pastas e subpastas. O -p (minúsculo) é para preservar o caminho absoluto, caso contrário ele não colocará a barra inicial ( / ). Nesse caso estamos direcionando para um arquivo. O arquivo gerado é um arquivo de texto normal, pode até ser utilizado para consultas com um simples cat ou

Compile squid 3.5.x under Debian Jessie

If you haven’t already, install the “build-essential” package. Additionally, if you want to compile squid with SSL-support, you also need “openssl” and “libssl-dev”: apt-get install -y openssl build-essential libssl-dev Then download and unpack the most recent source archive of squid 3.5. At the time of this writing it’s 3.5.5: wget -O - http://www.squid-cache.org/Versions/v3/3.5/squid-3.5.3.tar.gz | tar zxfv - Luckily we can still use the compile dependencies from the 3.4.x branch: apt-get build-dep squid3 Ok, no we are ready to run configure. Here’s my configuration. You may take it as a jumping-off point: cd squid-3.5.3 ./configure --build=x86_64-linux-gnu \ --prefix=/usr \ --includedir=${prefix}/include \ --mandir=${prefix}/share/man \ --infodir=${prefix}/share/info \ --sysconfdir=/etc \ --localstatedir=/var \ --libexecdir=${prefix}/lib/squid3 \ --srcdir=. \ --disable-maintainer-mode \ --disable-dependency-tracking \ --disable-silent-rules \ --datadir=/usr/sh

5 COMANDOS DO CURL PARA USAR NO DIA-A-DIA

O curl e uma ferramenta de linha de comando para manipulação de URL`s e transferência de dados. O principal benefício do cURL é que você pode usa-lo em arquivos .bat e linux shell-scripts para automatizar a manipulação de URL`s. 1. Lendo uma URL: Leitura simples de uma URL curl http://www.google.com.br
 Salvar o conteúdo de um site para um arquivo. O comando abaixo salva a url http://www.meusite.com no arquivo meusite.html. curl -o meusite.html http://www.meusite.com
 Para que o cURL siga os redirects do site use a opção -L curl -L  http://www.mysiteredirect.com
 2. Lendo URL`s com parâmetros GET curl  http://www.meusite.com?page=2&id=123 3. Lendo mais informações de uma URL Exibir os cabeçalhos de uma URL: curl --head http://www.meusite.com 4. Usando o cURL com FTP Listando um diretório curl  ftp://usuario:senha@meusite.com/diretorio/ Enviando Arquivos. curl -T localfile.txt -u usuario:senha ftp://meusite.com/diretorio 5. Enviando dados via POST

Removing comments and blank spaces

If you want to remove blank lines (using vi): :g/^$/d For commented lines (using vi): :g/^#/d And for lines where windows editor put ^M and you want to remove (using vi): :%s/^V^M//g Note that we cannot just type the accent ^ , instead we must use ^V and then type M, so the final command will look like this (using vi): :%s/^M//g The same as above can be reached using egrep: egrep -v "^#|^$" squid.original > squid.conf And the same using grep command: grep -v ^["#"] /etc/squid3/squid.original > /etc/squid3/squid.conf

Installing PIP in OpenBSD 5.6

pip included with Python Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default [1], so you may have pip already. Install pip To install pip, securely download get-pip.py: #curl --remote-name https://bootstrap.pypa.io/get-pip.py Then run the following (which may require administrator access): #python get-pip.py If setuptools (or distribute) is not already installed, get-pip.py will install setuptools for you. To upgrade an existing setuptools (or distribute), run pip install -U setuptools.

Configure BASH, KSH, TCSH, ZSH Shell To Logout User Automatically After Idle Time

You can configure any Linux system to automatically log users out after a period of inactivity. Simply login as the root user and create a file called /etc/profile.d/autologout.sh , enter: # vi /etc/profile.d/autologout.sh Append the following code: TMOUT=300 readonly TMOUT export TMOUT Save and close the file. Set permissions: # chmod +x /etc/profile.d/autologout.sh Above script will implement a 5 minute idle time-out for the default /bin/bash shell. You can also create tcsh version as follows: # vi /etc/profile.d/autologout.csh Append the following code: set -r autologout 5 Save and close the file. Set permissions, enter: # chmod +x /etc/profile.d/autologout.csh Dealing with ssh clients SSH allows administrators to set an idle timeout interval. After this interval has passed, the idle user will be automatically logged out. Open /etc/ssh/sshd config file, enter: # vi /etc/ssh/sshd config Find ClientAliveInterval and set to 300 (5 minutes) as follows:

Using GnuPG for SSH authentication

“Using GnuPG for SSH authentication” may refer to two distinct things: making the GnuPG agent (which is normally used to cache the passphrase of your OpenPGP key) to also act as a SSH agent, to cache the passphrase of your SSH key; using a key pair of your OpenPGP keyring as a SSH key pair. In this note, I will explain how to do this in GnuPG 2.1 (“modern”).