Ubuntu Technical

Ubuntu technical problems and solutions reference, a modern cookbook.

Monthly Archives: June 2012

Compress and Extract files with tar.gz

Or simply building a “tarball” as it is sometimes called. Even though this is a trivial task, I found myself quite often looking for the command, better yet for the options, because I tend to forget. So why not look for the command on my own blog.

Creating a tar archive

cd location_of_files_to_be_archived
tar cvzf name_of_archive.tar.gz *

Parameters explained:
– c – create
– v – verbose output
– z – –gzip, –gunzip, –ungzip filter the archive through gzip
– f – use the following file for archive

Note: The f option needs to be the last in the list of parameters. Whatever characters are following f, will be the name of the tarball.

Extract a tar archive

cd location_of_files_to_be_archived
tar xvzf name_of_archive.tar.gz *

Parameters explained:
– x – extract

Cheers



Flattr this

Advertisements

Using bash to count number of lines of code in a project

As the title suggests, here are 2 ways of counting the lines of code you just wrote, in whatever language. My examples will look into .java files.

To make the result include commented line, in other words, every line in the files.

cd {project location}
find . -type f -name '*.java' -exec cat {} \; | sed '/^\s*$/d' | wc -l

The second command excludes commented out lines. It only counts code, pure code.

cd {project location}
find . -type f -name '*.java' -exec cat {} \; | sed '/^\s*#/d;/^\s*$/d;/^\s*\/\//d' | wc -l

Cheers



Flattr this

%d bloggers like this: