Monthly Archives: January 2011

Linux – Exporting Files From Git (similar to SVN export)

I use git for just about all my code now. For some of my work, I need to export portions of or all of a git repo into some other location without picking up all the git files themselves. This is the way svn export works. There are two ways I do this. One is using git archive. This command always returns a zipped up copy of the repository, so you have to pipe it over to tar if you want to export files (either that or save the tar file and then in a second command extract it). Here’s my one-line command for taking the archive and sending it to a different location:

git archive HEAD | (cd ~/path/where/I/want/it/ && tar -xvf -)

This will extract the ENTIRE library to the specified path (without the .git files and whatnot).

Sometimes, however, I want to pull out just a portion of the library. git archive always gives you the whole enchilada which kinda sucks, and in this case I use rsync, like this:

rsync path/I/want/to/export/ -ri --del -m --exclude ".*" ~/path/where/I/want/it/ |grep sT

That last bit – the grep sT will limit the output of what I see so that I only see the files that are updated. I use that just to sanity check my export. If I see a TON of stuff go to update a path that already has the library and I know I only changed one file, then I know I got the path wrong.

Linux – Remove all .svn directories at once

When you check out a project code base from a svn repository, each downloaded directory (from top to the deepest) contains a .svn hidden directory that keeps svn’s necessary metadata.

If you want to remove them all at once, here’s one way to do it:

 ~/project_dir $> find -name .svn -print0 | xargs -0 rm -rf

find -name .svn searches the current directory hierarchy for files named .svn.

-print0 ensures each filename ended with a null character. This allows filenames that contain newlines/whitespaces to be interpreted correctly by programs that consume the output.

xargs -0 rm -rf receives the output and passes it to rm for file removal. Remember to use -0 option when the input items are terminated by a null character.

Linux – Who’s using all the space on this file system

To find how disk space usage you can use the following simple command lines:

# cd /home
# du -sk *                         ### disk usage command
132685  kathy
52721   tom
9       dick
96242   steve
7482    rose
567     barney
# cd kathy
# ls -l | sort -rn +4 | head -5    ### lists, sorts, and shows the top five
-rw-r--r--  1 kathy staff    2494013 Apr 25 08:55 errpt.myserver
-rw-------  1 kathy staff    1256156 Apr 25 09:45 fifthl.sna.Z
-rw-r--r--  1 kathy staff     805888 Apr 27 10:08 network.pci.txt
-rw-r--r--  1 kathy staff     566070 Dec 14 2006  myinst.log
-rw-r--r--  1 kathy staff     533504 Apr 27 10:08 adobeinstructions

Have your user clean up after him or herself.