顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2015年4月10日 星期五

Hello ninja and GYP

My English is not good to describe what is ninja and GYP, so I just list all steps that building a 'hello world' with these tools on Ubuntu.

1. Install ninja
    sudo apt-get install ninja

2. Install GYP
    sudo apt-get install gyp

3. Create a C file
    vi hello.c

with following content
#include <stdio.h>

int main(void)

{

    printf("Hello, world!\n");

    return 0;

}

4. Create GYP file for generating build.ninja or Makefile
    vi hello.gyp

with following content
{

    'targets': [

    {

        'target_name': 'hello',

            'type': 'executable',

            'sources': [

                'hello.c'

            ],

    },

    ],

}

5. Generate build.ninja file
    gyp hello.gyp --depth=. --generator-output=release -f ninja

    for generate Makefile
    gyp hello.gyp --depth=. --generator-output=release

6. Build with ninja
    ninja -C ./release/out/Default/ all

7. Execute
    ./release/out/Default/hello

8. You'll see output
Hello, world!



Reference:
http://erikge.com/articles/HelloGyp/

2015年3月10日 星期二

Add hard disk to Virtualbox

Add new SCSI hard disk to your setting and start Virtual Machine

Check disk partition
# sudo fdisk -l
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table

New hd is mount at /dev/sdb, it need to create new partition by fdisk
# sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x68da59e5.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-33554431, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431):
Using default value 33554431
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Check partition again
# sudo fdisk -l
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
171 heads, 2 sectors/track, 98112 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x68da59e5
Device Boot Start End Blocks Id System
/dev/sdb1 2048 33554431 16776192 83 Linux

Format disk
# sudo mkfs -t ext4 /dev/sdb1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1048576 inodes, 4194048 blocks
209702 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
128 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Mount disk
# sudo mkdir /data
# sudo mount /dev/sdb1 /data

Set auto mount and reboot
# sudo vi /etc/fstab
/dev/sdb1 /data auto defaults,auto,noatime,nodiratime 0 0


2014年9月17日 星期三

Install VBox Guest Additions

The steps to install Guest Additions for Virtual Box.

1. Start you Linux.
2. Select 'Devices' on V-Box menu.
3. Select 'Insert Guest Additions CD Image'
4. Open Terminal appilcation.
5. Execute cd /media/VBOXADDITIONS_4.3.10.93012
6. Execute sudo sh VBoxLinuxAdditions.run

Done.

* If you got error message in step 3 'Unable to mount the CD/DVD image C:\#######\VBoxGuestAdditions.iso on the machine Ubuntu-##.##. Would you like to force mounting of thins medium?'
   Please select 'Device->CD/DVD Devices->Remove disc from virtual drive' and try again.


2014年5月27日 星期二

[Linux] Check linux kernel is 32 bit or 64 bit

Problem:

How to check linux kernel is 32 bit or 64 bit



Command:
Input following command in terminal.

uname -m
OR
file /bin/bash


Example:
allen@www ~/work$ file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

allen@www ~/work$ uname -m
x86_64


Reference:
http://www.linuxquestions.org/questions/linux-general-1/how-to-check-linux-kernel-is-32-bit-or-64-bit-612352/
http://blog.longwin.com.tw/2011/01/linux-check-32-64-bits-2011/

2014年3月28日 星期五

[Linux] Disk quota exceeded

Problem:
I got following message when I am trying to remove some files.

$ rm cmakeconfig.h

rm: cannot remove `cmakeconfig.h': Disk quota exceeded

Solution:
We could use command 'wipe' to delete some file for more disk space and execute rm later on.

$ wipe CMakeCache.txt

Wipe CMakeCache.txt

delete CMakeCache.txt

done


2014年3月21日 星期五

Find string and files on linux

To find files at linux bash command.

$ find [path] -name 'filename'


To find string in files at linux bash command.

$ find [path] | xargs grep 'string'



2014年1月29日 星期三

Tar tool brief manual.

Tar
tar is a tool for file compression on Linux, you can compress files into other format , like gzip (.tar.gz), bzip2 (.tar.bz2) and so on.

Compress Format
tar [cvfz] [tar ball file] [the files or directory are compressed in]

c          Create a tar ball
f          Specify tar ball file name
v          Show the processing verbose.
z          Compress to gzip format.

Example
tar zcvf etc.tar.gz /etc/*

Decompress Format
tar [-xvfz] [tar ball file] [target directory for decompressing out]

x             Decompress tar ball
f             Specify tar ball file name
v             Show the processing verbose.
z             Decompress for gzip format.(.gz)

Example
tar zxvf etc.tar.gz /home/

2013年11月26日 星期二

Step by step to compile a C++ program on Ubuntu.

Reference:
http://www.wikihow.com/Compile-a-C/C%2B%2B-Program-on-Ubuntu-Linux

1. Install compiling tool
sudo apt-get install build-essential

2.Create a directory to hold your programs
mkdir -p CCPP/HelloWorld

3. Go into the directory you created.
cd CCPP/HelloWorld

4. Create CPP file
gedit main.cpp

5. Fill code in main.cpp and save it.
#include<iostream>
using namespace std;
int main()
{
    cout << "\nHello World !\n" << endl;
    return(0);
}

6. Compile it.
g++ -Wall -W -Werror main.cpp -o HelloWorldCPP
7. Execute it.
./HelloWorldCPP



2013年10月22日 星期二

Install LAMP on Ubuntu

Copy from http://www.howtoforge.com/ubuntu_lamp_for_newbies for note.

Install Apache

1. Open up the Terminal (Applications > Accessories > Terminal).
2. Type the following command in Terminal
sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.

Testing Apache

1. Open up any web browser and then enter the following into the web address:
http://localhost/












Install PHP

Step 1. Again open up the Terminal (Applications > Accessories > Terminal).
Step 2. Copy/Paste the following line into Terminal and press enter:
sudo apt-get install php5 libapache2-mod-php5
Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:
sudo /etc/init.d/apache2 restart

Test PHP

Step 1. In the terminal copy/paste the following line:
sudo gedit /var/www/testphp.php
This will open up a file called phptest.php.
Step 2. Copy/Paste this line into the phptest file:
<?php phpinfo(); ?>
Step 3. Save and close the file.
Step 4. Now open you're web browser and type the following into the web address:
http://localhost/testphp.php
The page should look like this:
















Install MySQL

To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)
Step 1. Once again open up the amazing Terminal and then copy/paste this line:
sudo apt-get install mysql-server

It would tip you to set password for 'root' and continue the installing.














Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.
gksudo gedit /etc/mysql/my.cnf
Change the line
bind-address = 127.0.0.1
And change the 127.0.0.1 to your IP address.

Step 3 (optional). Login mysql and set password for root
mysql -u root -p
Following that copy/paste this line:
mysql> set password for root@localhost = password('yourpassword');
(Make sure to change yourpassword to a password of your choice.)

Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
It would ask you to choice http server type and input mysql password to set config.

Now just restart Apache and you are all set!
sudo /etc/init.d/apache2 restart