Thursday, December 15, 2011

cd command

Few most useful b commands
cd - # move back to the previous directory
cd ~ # move into your home directory
cd .. # move up one directory

Wednesday, December 14, 2011

Umask

umask is a set of setting default permissions for files or directories that you create on your system.
umask tells the system what permissions to remove from the normal default setting.
umask value can be a three or four digit value.

Global umask value can be change in /etc/bashrc (default value is 0022 or 022).
The extra 0 at the beginning just means that the number is in octal format.
umask can be set temporary using umask command

Example:
umask 077 (Owner - read, write and execute, Group - No Permissions, Others - No Permissions)

How to calculate umasks?
The octal umasks are calculated using bitwise AND of the unary complement of the argument using bitwise NOT. The octal notations are as follows:
Ocatal Value | Permission
0 - read, write and execute
1 - read, write
2 - read, execute
3 - read only
4 - write and execute
5 - write only
6 - execute only
7 - no permissions

Note: Directories must be executable (X) in order to browse them.

Tuesday, December 13, 2011

Scraping

LXML is useful Python library for scraping. Here is an example of scraping script

pip install requests
pip install lxml

#! /usr/bin/python
import requests
import lxml
from lxml import html

r = requests.get('https://www.google.com/')
tree = lxml.html.fromstring(r.content)
elements = tree.get_element_by_id("prm")
for el in elements:
print el.text_content()

Note: It works with Python 2.6.1 (did not work with Python 4). LXML specs