Thursday, January 30, 2014

Power of Xargs

One can do many tedious tasks in linux easily using its commands, one such task can be:

Move all unwanted files in a code base to a directory.
a) either one can use 'svn st'   command and find all '?' files and manually copy and move them to other dir or

b) use power full linux utilities do it for you.
#svn st  | egrep -v 'M|X|A|cscope|tags|Performing'  | awk -F" " '{print $2}' | xargs -I {} mv {} not_needed/

i) 'svn st' list all files like modified, new etc.

In above command we carefully have to ignore display of modified files
'M' -modified
'A'  - newly added
'cscope' - cscope tags
'tags'  - ctags
'X'  - unknow type and any other unwanted types like file name starting with 'Performing' etc

ii) awk -F" " '{print $2}' --- display filenames


iii)  xargs -I {} mv {} not_needed/

[ {} is a placeholder meaning "the current argument". (You can use xxx or yyy or any other string instead of {} if you want, as well, and it'll do exactly the same thing.) -I implies -n1, because you want to act on each file individually.  ]
Courtesy - http://www.linuxplanet.com/linuxplanet/tutorials/6522/3

You are done, the above command moves all unwanted files to folder name not_needed in above case.

Caution: Above command may also move newly added file or any other svn extension that i've missed, add carefully same in egrep -v option.



magic with egrep

egrep with regex turns out to be very useful utility.

egrep can be used with following:
a) []   Sqaure brace also called Character Class
b) < >
c) {}
d) ()

a) Egrep with Sqaure brace:
One can use square brackets to identify the exact characters one is searching for.
    grep '[Cc]'  file_name      ->To search C or c in a file one can use


.... more to follow soon

Tuesday, January 28, 2014

Best articles on setting up tftp ftp on debain

Setup tftp
http://imranasghar.blogspot.com/2008/09/how-to-setup-tftp-server-on-debian.html

Setup ftp
http://www.server-world.info/en/note?os=Debian_7.0&p=ftp