Bash Tipps - pierregermain/MyTux GitHub Wiki

Scripting Bash in Vim

Seguir las instrucciones de http://vim.sourceforge.net/scripts/script.php?script_id=365 https://github.com/WolfgangMehner/bash-support

Esta dpm!

Regular Expresions in Bash

#OPEN REGEX 
shopt -s extglob

# Example 1
mv !(onix*|contrib*) contrib

# Example 2
ls !(upload*)
sudo rm !(upload*)

#CLOSE REGEX
shopt -u extglob

Find Files

find . -name '*old*'

Renombrar ficheros

rename --verbose --no-act 's/^old/new/' old.*
rename --verbose --no-act Instalar 01-Instalar Instalar*

# En otros sistemas se hace así
rename --verbose old new old*

# Para hacerlo recursivamente
shopt -s globstar
rename --verbose old new **

Mover Ficheros a subcarpeta llamada drupal

mv !(drupal) drupal/

Comprimir

alias compress='sudo tar -zcvf archive.tar.gz $1'

-z : Compress archive using gzip program
-c: Create archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name

Descomprimir

tar -xzvf archivo.tar.gz

Scripts

autojump

Search in Files

Use ack

ack --ignore-dir=css seachString *

Replace in Files with Ack

# See content to be changed
ack 'old'
# List the files that will be changed
ack -l 'old'
# Replace command
ack -l 'old' | xargs perl -pi -E 's/old/new/g'