Archives | Blog (December-2009-13)
Back to: BlogAdd all new files and folders to subversion with one line in terminal
This is basicly simple oneliner:
svn status | grep "^?" | awk '{print $2}' | xargs svn add
I'll try to explain it...
svn status | grep "^?" | awk '{print $2}' | xargs svn add
What this line uses really well are "pipes", that's these "|" signs. Simply put you have, in this example, 4 commands and each one receives input from previous one (except first one, of course) and does something with it.
First one, svn status, prints out status of the working copy files and directories.
But we're looking only for files we created that are not added to SVN, and those files/folders have "?" as a status symbol, and that's why we're looking for that question mark in second command grep "^?" and because of that we'll get only lines of the output with question mark at the beginning.
Grep really comes handy for many things, if you're listing files in terminal and you're looking for those that contain "document" in their filenames you can simply write: ls | grep document
But in the output we have both status symbol and file/folder name. And we need only filename. And this is where AWK comes handy awk '{print $2}' . It takes only the second part of the line and prints it out (in case where you want to print the first part, for example, you would use $1 instead of $2). And it send the second part, which is filename (folder name) to our next command...
And our last command simply adds the file to subversion: xargs svn add
And this is the definition of "xargs" from Wikipedia: "xargs is a command on Unix and most Unix-like operating systems. It is useful when one wants to pass a large number of arguments to a command. Until Linux kernel 2.6.23, arbitrarily long lists of parameters could not be passed to a command [1], so xargs will break the list of arguments into sublists small enough to be acceptable."
P.S. In case you were wondering that's Mario & Luigi up there on the picture
Recent posts
- Thursday, 21. january 2010. Find files larger than X and delete them in Mac OS/Unix terminal
- Tuesday, 15. december 2009. Bananica.com - Finally!
- Monday, 14. december 2009. MySQL Find and Replace with helper tool that generates SQL for you
- Monday, 14. december 2009. Synchronize two folders on a Mac with Automator and Rsync
- Monday, 14. december 2009. Synchronize two folders on a Mac and other Unix Systems with Rsync
- Sunday, 13. december 2009. Add all new files and folders to subversion with one line in terminal
Recent comments
-
Wednesday, 24. february 2010. karol commented on Add all new files and folders to subversion with one line in terminal Great! However, this doesn't work if your file names contain spaces.
I managed to compile several snippets from the net and came up with this:
svn status | grep "^?" | awk '{$1="";$0=substr($0,2)}1' | sed -e "s,[^.],\'&," -e "s,\$,\'," | xargs svn add
Phew! Works in Snow Leopard. - Tuesday, 23. february 2010. eMancu commented on Synchronize two folders on a Mac and other Unix Systems with Rsync Thanks a lot! I was looking for --delete example :)
-
Wednesday, 13. january 2010. annmarie commented on Ambium Ja, meni je moja spletna stran noro dobra. Na svetovnem nivoju, ni kaj.
Wonderful! Thank you. I will use this for sure!
15. Dec 2009 at 2:58 PM
Great way to make this happen on a single line. Works like a charm on Snow Leopard.
21. Feb 2010 at 7:23 PM
Great! However, this doesn't work if your file names contain spaces.
I managed to compile several snippets from the net and came up with this:
svn status | grep "^?" | awk '{$1="";$0=substr($0,2)}1' | sed -e "s,[^.],\'&," -e "s,\$,\'," | xargs svn add
Phew! Works in Snow Leopard.
24. Feb 2010 at 12:14 PM