Tuesday, February 12, 2013

List recently modified files under a directory in linux shell

In order to list files that have been modified recently, we could use the find command to retrieve the file information and sort them by modified date:

find . -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head

However, this will miss some folders if the folders are symoblic links. So in this case we could specify find to follow symbolic links.

find -L . -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head

Fourther more, if you just want to get files modified in last a few days, it's build in in find:

find . -mtime n

list files that modified n*24 hours ago.

Monday, February 4, 2013

The difference between soft link and hard link in linux

From: http://linuxgazette.net/105/pitcher.html


Unix files consist of two parts: the data part and the filename part.
The data part is associated with something called an 'inode'. The inode carries the map of where the data is, the file permissions, etc. for the data.
                               .---------------> ! data ! ! data ! etc
                              /                  +------+ !------+
        ! permbits, etc ! data addresses !
        +------------inode---------------+

The filename part carries a name and an associated inode number.
                         .--------------> ! permbits, etc ! addresses !
                        /                 +---------inode-------------+
        ! filename ! inode # !
        +--------------------+
More than one filename can reference the same inode number; these files are said to be 'hard linked' together.
        ! filename ! inode # !
        +--------------------+
                        \
                         >--------------> ! permbits, etc ! addresses !
                        /                 +---------inode-------------+
        ! othername ! inode # !
        +---------------------+
On the other hand, there's a special file type whose data part carries a path to another file. Since it is a special file, the OS recognizes the data as a path, and redirects opens, reads, and writes so that, instead of accessing the data within the special file, they access the data in the file named by the data in the special file. This special file is called a 'soft link' or a 'symbolic link' (aka a 'symlink').

Tuesday, November 27, 2012

python program behind proxy


export http_proxy="http://localhost:8118"

All about pip

I was stucked in pip. Just found out that pip is called "pip-python" in RHEL.

 What's more, pip cannot auto detect system proxy settings, manual specify:

 sudo pip sudo pip-python install virtualenv --proxy localhost:8118

Sunday, November 11, 2012

command sort on last column

As you know, the linux sort command is agile, which can sort on column using -k.

However, if we gonna sort on the last column and each row has different number of columns, we can still achieve that with the help of sed.

sed 's/^\(.\+\s\+\)\([0-9]\+ *\)$/\2 \1/'

Tuesday, October 2, 2012

zsh cd tab completion slow

It is quite annoing that zsh seems stuck when completion using tab in a huge directory.

To speed up the zsh completion, append the following lines to ~/.zshrc

# Speed up the zsh completion

zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache


Sometimes, the directory auto completion works slow under git and svn directories.The solution is to disable it from getting git info and svn info:

For GIT, add following to .zshrc:


__git_files () {
    _wanted files expl 'local files' _files  
}


For SVN, append this line to .zshrc:

compdef -d svn