Wednesday, August 31, 2011

Vim search string case insensitive

Vim search string case insensitive

If \c appears anywhere in a pattern the whole pattern is assumed to be case insensitive. So to search for the string "root" while ignoring case you'd use

/\croot

or

/root\c

Take a look at :help ignorecase in vim for more info.

I use the ignorecase and smartcase settings as default, and they work great for me. Any search with an uppercase character becomes a case sensitive search.

\c is good to know when your working on other people's stations.

To ignore case in the searches, enter the following command:
:set ignorecase
or
:set ic

To turn on smartcase:
:set scs

This command can be abbreviated :set ic. To turn off this feature, use:

:set noignorecase

==========================
CASE IN ONE PATTERN

If you want to ignore case for one specific pattern, you can do this by
prepending the "\c" string. Using "\C" will make the pattern to match case.
This overrules the 'ignorecase' and 'smartcase' options, when "\c" or "\C" is
used their value doesn't matter.

pattern matches ~
\Cword word
\CWord Word
\cword word, Word, WORD, WoRd, etc.
\cWord word, Word, WORD, WoRd, etc.

A big advantage of using "\c" and "\C" is that it sticks with the pattern.
Thus if you repeat a pattern from the search history, the same will happen, no
matter if 'ignorecase' or 'smartcase' was changed.

Reference:
http://unixjunkie.blogspot.com/2006/03/ignore-case-in-vim-searches.html
http://www.linuxquestions.org/questions/programming-9/how-to-search-in-vi-wih-case-insensitive-376770/

Thursday, August 25, 2011

download files from web via the OS x command line


curl -O http://example.com/test.pdf

You might want to include a few extra bits in that post. First, always include the -L (or –location) switch, since that will allow curl to follow any redirects (if the file gets moved, but there is a redirect for it). Also, if the URL’s file part (the section after the last slash) is not pretty, you can give a name for the downloaded file by using a lower-case -o (instead of -O), followed by a space and the name in quotes. Also, always put the URL in single-quotes – ampersands and a few other characters will break on the command line if they aren’t in quotes. Here’s an example of those ideas combined:

curl -L -o ‘myfile.dmg’ ‘http://www.somewebsite.com/files/getdmg?id=24‘

Reference:
http://osxdaily.com/2007/05/11/download-files-from-the-web-via-the-os-x-command-line/

Thursday, August 11, 2011

Download Youtube Video

Download Youtube Video
# cd /usr/ports/www/youtube_dl
# make install clean

step 2)
$ youtube-dl -b -o Linux_WM_show.flv "http://www.youtube.com/watch?v=0ABzP9X0zwI"

參數
-b best rate
-o output file name
"URL"

Wednesday, August 10, 2011

找出目錄下所有壞掉的 symblic link

找出目錄下所有壞掉的 symblic link

find . -type l | perl -lne 'print if ! -e'

配合xargs 做刪除動作

find . -type l | perl -lne 'print if ! -e' | xargs rm -rf

http://hsian-studio.blogspot.com/2011/04/symblic-link.html

Wednesday, August 3, 2011

FreeBSD add a user to group

FreeBSD add a user to group
by Vivek Gite

Q. How do I add a user to group under FreeBSD operating system?

A. You need to use pw command. The pw utility is a command-line based editor for the system user and group files, allowing the superuser an easy to use and standardized way of adding, modifying and removing users and groups. First login as the root using su or sudo command.

Task: Add existing user to group
You would like to add existing user tom to secondary group called ftpusers. Type the command as follows:

# pw groupmod ftpusers -m TEST_NAME

Note: this way user TEST_NAME will be added to group operator without replacing or overwriting anything.

If you want to add the user TEST_NAME to ftpusers group only, and remove the user from other groups:
# pw usermod TEST_NAME -G ftpusers

or specifing multple groups, add TEST_NAME to secondary group ftpusers and wwwusers:
# pw usermod tom -G ftpusers,wwwusers

-G option Set the default groups in which new users are granted membership. This is a separate set of groups from the primary group, and you should avoid nominating the same group as both primary and extra groups.

Task: Add a new user to group
Add new user jerry to system and to secondary group sales:
# pw useradd jerry -G sales
# passwd jerry

First command adds user jerry to secondary group called sales. Second commands set a password for jerry.

Reference:
http://www.cyberciti.biz/faq/freebsd-add-a-user-to-group/