Thanks to visit codestin.com
Credit goes to corecode.wordpress.com

Feeds:
Posts
Comments

Archive for the ‘bash’ Category

Screen tip

How about to use bash configuration in your screen session?
Well that is very simple to config. Just add this into your .screenrc

defshell -bash`

Since sometimes your bash in a screen session is not identify in your terminal, you can also add this info into your PS variable in .bashrc. Just adding something like this in the end of your .bashrc:


set_term_name() {
    current="screen"
    if [ $TERM=$current ];
    then
        echo $TERM
    fi
}
export PS1="\u@\h \[\033[32m\]\w[\033[33m\] \$(set_term_name)\[\033[00m\] $"

That’s all folks!

Read Full Post »

Sometimes you need to delete a bunch of files that has a limit number of lines. One option is to see one by one and rm it. But you can make you day more agile using the follow commands together 🙂

find <directory> -type f -exec sh -c '[ $(wc -l < "$1") -lt 20 ] && rm -- "$1"' inline {} \;

Let’s explain what it does. <directory> is the folder where the files you want to delete are. I set 20 lines as minimum, just change it using your criteria.

find -type f, says that is a file we are looking for. -exec sh says we want to execute some command for each entry we find using find <dir> -type f. In our case  we exec a sh -c. The -c options says to sh<ell> that we will run a inline code without open a file with shell commands. The follows commands into ” says we want to count the number of line in entry file $1 and if it is less than 20 we’ll delete it. inline and {} \; are just some find command conventions.

References:

[1] http://stackoverflow.com/questions/935251/linux-delete-files-that-dont-contain-specific-number-of-lines

Read Full Post »

Design a site like this with WordPress.com
Get started