Show Menu
Cheatography

Bash quick tips Cheat Sheet (DRAFT) by

also http://www.cheatography.com/davechild/cheat-sheets/linux-command-line/ good

This is a draft cheat sheet. It is a work in progress and is not finished yet.

sql_lo­ad_­fro­m_o­rac­le.tmpl

set colsep ,;
set feed off;
set trimspool on;
set linesize 32767;
set pagesize 0;
set heading off;
set echo off;
set termout off;
spool <TM­PL_VAR NAME=C­SV_­FIL­E>
<TM­PL_VAR NAME=S­QL_­BOD­Y>

/
SPOOL OFF
exit;

make_s­ql_­load.pl

#!/usr­/bi­n/perl -w
my $file_name = shift;
use HTML::­Tem­plate;
my $templ­ate_dir = '/home­/te­mpl­ate/';
my $templ­ate­_name = 'sql_l­oad­_fr­om_­ora­cle.tmpl';
my $filename = $templ­ate_dir . $templ­ate­_name;

# open the html template
my $template = HTML::­Tem­pla­te-­>new( filename => $filename );
my $sql_body = '';

{
open my $fh, '<', "­$fi­le_­nam­e" or die;
local $/ = undef;
$sql_body = <$f­h>;
}

my $csv_file = '';
$csv_file = $file_name . '.csv';

# fill in some parameters
$templ­ate­->p­aram( SQL_BODY => $sql_body );
$templ­ate­->p­aram( CSV_FILE => $csv_file );
print $templ­ate­->o­utput;
 

Zip and Cat

1. unzip many files to one directory
echo 'for i in $(ls _xml_20/*.zip);do unzip $i -d sm; done' > unzip.sh; nohup bash unzip.sh &
2. cat many files to big one
find sm -type f -name "­*.x­ml" -exec cat '{}' + > input.txt
3. split zip for several files:
zip 21100_­1.zip --out 21.zip -s 9m
4. cmp2dir perl:
use Test::­Fil­es;use File::­Slurp; $di1='1'; $di2='2'; for $file (read_­dir­($di2)) {compa­re_ok( $di1.$­fil­e,$­di2.$f­ile­,$f­ile.'ok')}
5. remove html tag:
cat test.html | sed 's@<\([<>][<>]\)>­\([­^<>]\)<­/\1­>@\2@g'
6. find scripts modidied last 2 month unix:
find . -mtime -60 -type f -name '*.sh' -exec ls -l {} \;
 

Shell Scripting

Shell Script Files
contain command sequences
$cat testlogin
 
files have been assigned the execute permission (using chmod)
 
simplify repeti­tious command sequences
 
the shell runs each command as if it has been typed at the terminal