Comandos varios

De gacq wiki
Saltar a: navegación, buscar

Otras recopilaciones


Time Syncronization

ntpdate time.sinectis.com.ar
hwclock --systohc
tzconfig

Recursive file future date fix


Recursive find and replace string in files

#!/bin/sh
for tfile in `find . -type f`
do
   cat $tfile | sed "s^$1^$2^" > $tfile.junk
   mv -f $tfile.junk $tfile
done

Usar una unidad de cinta remota

rsh host dd if=/dev/rmt ibs=10k | tar xobf

Una forma de copiar archivos con ssh pero sin scp

Util para cuando tenemos archivos muy grandes y el scp se queda en "stalled"

tar cvzf - dir-o-file | ssh servidor tar xCzf directorio -


find

Change file and dir permisions

find . -type d -exec chmod 755 '{}' \; find . -type f -exec chmod 644 '{}' \;

delete files older than 7 days

find . -ctime +7 -print | xargs rm -f

Para encontrar IP Address

find / -type f -print | xargs egrep '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'

Misc

Lista de parametros muy grande

intranet:/# grep regexp *
-su: /bin/grep: Argument list too long

Se resuelve con

intranet:/# ls | xargs grep -i regexp

Velocidad de la placa de red

mii-tool

Borrar algo de un archivo

# echo 'g/non-free/d
wq'|ed - /etc/apt/sources.list

Partir un archivo en partes del tamaño de un CD de 700 MB

split -b 

httptunnel

If you are placed behind an HTTP-proxy (with or without user-authentication), you can not simply use ssh to connect to an outside server. Everything else but HTTP is locked.
If for some reason you desperately need to get out, do the following:

server (outside the proxy):
  apt-get install httptunnel
  hts -F localhost:22 1234

client (inside the proxy):
  apt-get install httptunnel
  htc -F 5678 -A proxyuser:proxypwd -P proxy-server remote-host:1234
  ssh -p 5678 localhost

With this, the local port "5678" is tunnelled to "remote-host's" port "22" via an HTTP-protocol-based "connection" between the HTTP-Tunnel-Client and the HTTP-Tunnel-Server (port "1234").
SSH connects to localhost:5678 and reaches remote-host:22 (in this configuration). 

Cambiar hostname

1. Cambiarlo de /etc/hostname
1. init 6

Convertir los archivos txt de DOS a UNIX

Hay varias opciones para sacar los ^M del final de las lineas

# Con tr
tr -d '\15\32' < archivo-dos > archivo-unix

# Con vi
1,$s/^M//g

# Con dos2unix
apt-get install sysutils
dos2unix winfile.txt unixfile.txt

# Con awk
awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt

# Con perl
perl -p -e 's/\r$//' < winfile.txt > unixfile.txt

Convertir los archivos txt de UNIX a DOS

Hay varias opciones para sacar los ^M del final de las lineas

# Con unix2dos
apt-get install sysutils
unix2dos unixfile.txt winfile.txt

# Con awk
awk 'sub("$", "\r")' unixfile.txt > winfile.txt

# Con Perl
perl -p -e 's/\n/\r\n/' < unixfile.txt > winfile.txt

Renombrar muchos archivos a la vez

for i in 'ls *.<oldextension>'; do mv $i ${i/<oldextension>/<newextension>}; done
# Ejemplo:
for i in `ls *.shtml` ; do mv $i ${i/shtml/html}; done


Poner bien permisos

find /xxx -type d -exec chmod 755 '{}' \;
find /xxx -type f -exec chmod 644 '{}' \;

Avisar con sonido cuando se corta la red

En el crontab se puede poner algo como

* * * * *       root if ! ping -c 2 -n 195.22.220.52 >> /dev/null; then aplay informational.au; fi

Filter

en /etc/aliases

gacq:           gacq,"| /usr/bin/filter -o /tmp/filter.err -f /.elm/filter-rules.gacq"

Duplicando discos sobre la red

#dd if=/dev/hda bs=10k | ssh <IP_DESTINO> dd of=/dev/hda bs=10k

Proxy server

Para usar lynx, etc es necesario setar la variable /etc/profile, bashrc, etc.

http_proxy=http://proxy.uolfast.com.ar:80