TAR command

March 11th, 2010 by dreamluverz

create:
tar -cvf mystuff.tar mystuff/
tar -czvf mystuff.tgz mystuff/
extracting:
tar -xvf mystuff.tar
tar -xzvf mystuff.tgz
testing/viewing:
tar -tvf mystuff.tar
tar -tzvf mystuff.tgz

Note that .tgz is the same thing as .tar.gz
Tar “tars up” a bunch of files into one “tar-file”
gzip is compression, but only works on one file, so the entire “tarfile” is compressed.





Also when creating a tar or cpio backup, never, never, never use an “absolute” path — you have been warned; also linux tar warns you of this too. The problem is that when you want to unpack, you cannot choose where to unpack to, you will be forced to unpack to the “same” absolute path. When creating a tar or cpio you should change the the appropriate directory and tar from there.

Also when creating a tar or cpio it is general good practice to tar up a directory (appropriately named) which contains your files, rather than just the files. This is good courtesy to anyone unpacking your tarfile.

If you would like to create a tar file while saving ownership and permissions, add the “p” flag.

Creating and saving ownership and permissions:
tar -cpvf mystuff.tar mystuff/
tar -cpzvf mystuff.tgz mystuff/

Also take note of the following commands:
gzip
gunzip
cat
zcat
bzcat
bzip2
bunzip2
zgrep
bzgrep

(cd /mydir && tar -czf – .)|(cd /destdir && tar -xzvf -)
tar -czf – . | ssh user@dest “(cd /destdir && tar -xzvf -)”
(cd /mydir && tar -czf – .) | ssh user@dest “(cd /destdir && tar -xzvf -)”

Errors:
If you receive an error such as the following:

[root@localhost test]# ssh user@dest "(cd /rh62/home/kernel && tar -czvf - linux-2.2.22.tar.bz2)"|tar -xzvf -
user@dest's password:
linux-2.2.22.tar.bz2
linux-2.2.22.tar.bz2

gzip: stdin: decompression OK, trailing garbage ignored
tar: Child returned status 2
tar: Error exit delayed from previous errors
[root@localhost test]#

Then try leaving off the compression as follows:

[root@localhost test]# ssh user@dest "(cd /rh62/home/kernel && tar -cvf - linux-2.2.22.tar.bz2)"|tar -xvf -
user@dest's password:
linux-2.2.22.tar.bz2
linux-2.2.22.tar.bz2
[root@localhost test]# echo $?
0
[root@localhost test]#

Spaces in your filenames?
Having fun with spaces in the filename or directory name? Here’s your answer:

find . -type f -name '*jpg' | grep " " | while read REPLY; do
     tar -cf - "$REPLY" | (cd /tmp/jpg && tar -xvf -)
done

Bonus:

find . -type f | while read REPLY; do
     cp -a "$REPLY" /tmp/jpg/`echo $REPLY \
       | sed -e 's/ //g' -e 's/\///g' -e 's/^\._//'`
done

ssh root@dest 'tar -C / -czf - --exclude ./proc/* --exclude ./dev/pts/* .' > gmaster.tgz
proc and dev was empty for the following command, so I didn't exclude them:
tar -czf - . | ssh user@dest "cat - > k12ltsp.master.tgz"

source: http://roffle.us/blog/archives/13-Linux-TAR-Command.html

regex cheat sheet

March 9th, 2010 by dreamluverz




Special Sequences
  • \w - Any “word” character (a-z 0-9 _)
  • \W - Any non “word” character
  • \s - Whitespace (space, tab CRLF)
  • \S - Any non whitepsace character
  • \d - Digits (0-9)
  • \D - Any non digit character
  • . - (Period) – Any character except newline

Meta Characters

  • ^ - Start of subject (or line in multiline mode)
  • $ - End of subject (or line in multiline mode)
  • [ - Start character class definition
  • ] - End character class definition
  • | - Alternates, eg (a|b) matches a or b
  • ( - Start subpattern
  • ) - End subpattern
  • \ - Escape character

Quantifiers

  • n* - Zero or more of n
  • n+ - One or more of n
  • n? - Zero or one occurrences of n
  • {n} - n occurrences exactly
  • {n,} - At least n occurrences
  • {n,m} - Between n and m occurrences (inclusive)

Pattern Modifiers

  • i - Case Insensitive
  • m - Multiline mode – ^ and $ match start and end of lines
  • s - Dotall – . class includes newline
  • x - Extended– comments and whitespace
  • e - preg_replace only – enables evaluation of replacement as PHP code
  • S - Extra analysis of pattern
  • U - Pattern is ungreedy
  • u - Pattern is treated as UTF-8

Point based assertions

  • \b - Word boundary
  • \B - Not a word boundary
  • \A - Start of subject
  • \Z - End of subject or newline at end
  • \z - End of subject
  • \G - First matching position in subject

Assertions

  • (?=) - Positive look ahead assertion foo(?=bar) matches foo when followed by bar
  • (?!) - Negative look ahead assertion foo(?!bar) matches foo when not followed by bar
  • (?<=) - Positive look behind assertion (?<=foo)bar matches bar when preceded by foo
  • (?<!) - Negative look behind assertion (?<!foo)bar matches bar when not preceded by foo
  • (?>) - Once-only subpatterns (?>\d+)bar Performance enhancing when bar not present
  • (?(x)) - Conditional subpatterns
  • (?(3)foo|fu)bar - Matches foo if 3rd subpattern has matched, fu if not
  • (?#) - Comment (?# Pattern does x y or z)

source: http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

regex: match all including new line

March 9th, 2010 by dreamluverz

I was looking for a way to match all characters plus new line and using “.” is not solely the answer because:

The dot matches a single character, without caring what that character is. The only exception are newline characters. In all regex flavors discussed in this tutorial, the dot will not match a newline character by default. So by default, the dot is short for the negated character class [^\n] (UNIX regex flavors) or [^\r\n](Windows regex flavors).

source: http://www.regular-expressions.info/dot.html

So I found some answers on the references below by using the \s

\s
Matches any whitespace character; this is equivalent to the class [ \t\n\r\f\v].

sources:
http://www.amk.ca/python/howto/regex/

http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

So combining it all example showed below:

<?
$str = ‘you \n are \n good’;
preg_match(‘/(.*)/s’, $str, $match);

?>

[additions] After testing several examples I found out that S is not enough for the example below, so instead I added the U pattern modifier so it would be like preg_match(‘/div(.*)<\/div>/sU’, $str, $match);

$a = “
<div>
<p>aaa</p>
</div>
<div>
<p>bbb</p>
</div>
<div>
<p>ccc</p>
</div>
“;

You can also check regular expressions list here.

Happy New Year 2010

December 31st, 2009 by dreamluverz

Happy New Year

Manny Pacquiao “pacman” vs Miguel Cotto replay

November 15th, 2009 by dreamluverz

pacman vs cotto

PART 1

PART 2

Manny Pacquiao Interview

Update your twitter status via facebook and vice versa

July 26th, 2009 by dreamluverz

First you need to login to your facebook account then go to twitter app on facebook and follow the steps there. I’ve also included some pictures below to follow.

Click the twitter app link above or simply click this http://d-url.com/730af4

STEP 1

Add twitter app on facebook by clicking allow, showed on the image below.

step1

STEP 2

login to your twitter account


step2

STEP 3

Then that’s it and if you want 2-way status update, so twitter can also update your

facebook status click allow twitter to update your facebook status as shown below


step3

STEP 4

then click allow status updates and you’re done! :) enjoy!!!


step4