Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, November 8, 2012

Find total number of lines recursively in terminal

Recently I need to do some analyze on code check into certain repository, and thanks to linux provide a very useful to for wc, you can get word count, number of lines types of information easily. And in order to do it recursively, here is the command you need, very handy for me :)

find . -name '*.js' | xargs wc -l

Monday, September 17, 2012

You don't need ssh-copy-id

This is what ssh-copy-id does

cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

If you are using Mac or other *nix flavor that doesn't have ssh-copy-id, the above is what you need.  That's exactly what ssh-copy-id does :)

Saturday, September 10, 2011

Basic Linux commands for LAMP developer

Came across this blog recently, and found it's quite useful.  It covers some basic useful commands that a LAMP developer may need to use from day to day.


http://www.addedbytes.com/blog/basic-linux-command-line-tips/


Besides the list above, let me include some of which I think all LAMP developer should have known.  [ Note:  I'm not including any advanced commands here, since this post is about basic only. ] 


wget - for retrieving stuff
wget http://somewhere.com/release/stuff-0.0.13/stuff.tgz
scp - copy stuff in ssh way
scp fileA.tgz me@yourhostname:/path/you/want
rsync - it keeps an index of sync files which decrease the bandwidth usage when transferring ( yes, dump ftp )
rsync -avu  -e ssh ~/path/to/stuff me@hostname:/path/to/sync-with
top - check running process status, the basic usage is to check which process is taking the most memory, for example.


tar - backup by creating tarball, and you can use with other params to create tgz ( tar gzip ), for example.


alias - create alias for your commands, this will save you tons of time.


export - export a shell variables in your current session.


find - find files
find /mp3-folder -name 'Celio*' -and -size +10000k 


Please don't ask me why you don't see "mv, ls, rm, mkdir ... etc".  Those are not should know, those are MUST know for LAMP developer.


Please feel free to add (comment) what you think the basic commands that we all should know and is not listed above. 

Thursday, June 2, 2011

Fancy diff command with sed

Of course you can just use a simple diff to output the difference between files. But how about if one day you need to generate a custom report from that diff, for example, what is the line number difference between the files?  Well, you may need some diff commands like below to save your day.

Don't be scared by this command. Once you break it down and it is quite easy to understand.

diff file1.txt file2.txt --changed-group-format='line %dF to line %dL is different|' --unchanged-line-format='' | sed 's/|/\n/g'
  1. --changed-group-format  ~ what to output if the line is different
  2. --unchanged-line-format ~ what to output if the line is the same
  3. - sed is a text manuplulate program.
Note : Thanks nano for the comment

The output will be something like
=================================
line 2 to line 1 is different
line 7 to line 6 is different

A brief introduction to sed
sed is used for manupulating strings, for example, you can remove lines, append lines, subsitute string ... etc. You can also use regular expression to  filter your strings ( well, actually regular expression is the most used case for sed ).

Here is a simple sed command

cat mood.txt | sed -e 's/happy/happier/' > mood.txt

This command read the output from mood.txt, replace all happy to happier, and then replace what is inside the mood.txt.

The parameter -e  means using the following criteria / command.

cat mood.txt | sed -f myCommand.txt > mood.txt

The parameter -f means using the commands in the file as the criteria.  So for example, if you have bunch of commands, you can write that into a file.

Well, sed is much more powerful than just the above, keep exploring you will find more ~


Monday, May 16, 2011

Install Compass and Sass in Ubuntu 11.04

Here is a tutorial on setting up your environment to use compass and sass in Ubuntu 11.04 ( should be the same as previous version )

1) Install Ruby
sudo apt-get install ruby-full

2) Install Gem
sudo apt-get install rubygems1.8

3) Install Rails, sqlite3 ( optional, but usually I install that as well )
sudo gem install rails
sudo gem install sqlite3

Try to run this to make your system up-to-date
sudo gem update --system  

4) Install Compass
sudo gem install compass

5) Install Sass
sudo gem install sass

6) Create your first project
(If you want to use normal css syntax, scss)
compass create <myproject>

(If you want to use sass syntax)
compass create <myproject> --syntax sass

How to create your first project
  1. cd /path/to/projects_folder
  2. compass create my_test_project
  3. compass watch my_test_project
Now you can open your favorite IDE, and look into the just created "my_test_project".  You will see a bunch of files are created.  By default, the "sass" folder is the place for holding the sass files, while the "stylesheets" folder is the place for the generated css files.  And you can configure those by changing the  "config.rb" if you will.

Some "extensions" that you may want to install after you setup your project
  • (CSS3 PIE)  compass install  compass/pie

Some "gems" you may be interested 

For more information on Compass and Sass, please visit the official documentation - http://compass-style.org/install/ and http://sass-lang.com/.