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

2015年7月2日 星期四

[ubuntu] Shell Script 筆記


function 使用方式
    function Sync() {
        echo "sync $1"
        p4 sync "@$1"
    }
    Sync

時間使用方式
    Date=$(date +%Y%m%d)
    Time=$(date +%H%M%S)


if else 使用方式
    if [ -d "$tar" ]
    then
        echo "$tar found."
    else
        mkdir "$tar"
    fi



[ string1 = string2 ] string1 and string2 are equal
[ string1 != string2 ] string1 and string2 are not equal
[ string1 \< string2 ] string1 is lexically less than string2(e.g. 'a' is less than 'b')
[ string1 \> string2 ] string1 is lexically greater than string2(e.g. 'b' is greater than 'a')
[ -e file ] file exists
[ -f file ] file is a file
[ -d file ] file is a directory
[ n1 -eq n2 ] true if integer n1 = integer n2
[ n1 -ne n2 ] true if integer n1 <> n2
[ n1 -gt n2 ] true if n1 > n2
[ n1 -ge n2 ] true if n1 >= n2
[ n1 -lt n2 ] true if n1 < n2
[ n1 -le n2 ] true if n1 <= n2

2014年12月25日 星期四

[ubuntu] 常用指令

觀看記憶體 free -m

 硬碟空間 df -h

 mount -t tmpfs -o size=2G tmpfs /tmp/

 格式化硬碟 指令為 mkfs -t ext4 /dev/sdc1

看cpu
 cat /proc/cpuinfo|grep "model name"

更改系統時間
sudo date -s 2015/06/03
sudo date -s 14:00:00
sudo hwclock --systohc --utc

2014年10月15日 星期三

[ubuntu] VIM 用法

選取
v 小寫

選取後可用以下方式操作:
d 刪除選取區內容。
y 複製選取區內容。


/etc/vim/vimrc
插入space取代Tab
:set expandtab

Tab = 4 space
:set tabstop=4

程式縮排需要space的個數
:set shiftwidth=4

:w 令存新檔

[ubuntu] Byobu

F2 - Create a new window
F3 - Move to previous window
F4 - Move to next window
F6 - Detach from this session
F7 - Enter copy/scrollback mode
F8 - Re-title a window
F9 - Configuration Menu
F12 - Lock this terminal

alt + page up 往上捲動視窗
alt + page down 往下捲動視窗

Q: Putty 中使用Byobu F2~F4無效 
Ans: "Terminal" -> "Keyboard" -> "The Function keys and keypad" 選用 "Xterm R6" 便可。

2014年10月14日 星期二

[android] build android error

Case 1:
out/xxxxxx/host/linux-x86/bin/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
make: *** [out/xxxxxx/target/product/msm8226/obj/APPS/BackupRestoreConfirmation_intermediates/package.apk] Error 127
make: *** Deleting file `out/xxxxxx/target/product/msm8226/obj/APPS/BackupRestoreConfirmation_intermediates/package.apk'
out/xxxxxx/host/linux-x86/bin/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
make: *** Waiting for unfinished jobs....
make: *** [out/xxxxxx/target/product/msm8226/obj/APPS/CalendarProvider_intermediates/package.apk] Error 127
make: *** Deleting file `out/xxxxxx/target/product/msm8226/obj/APPS/CalendarProvider_intermedackage.apk] Error 127
make: *** Deleting file `out/xxxxxx/target/product/msm8226/obj/APPS/DefaultContainerService_intermediates/package.apk'
out/xxxxxx/host/linux-x86/bin/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
make: *** [out/xxxxxx/target/product/msm8226/obj/APPS/DownloadProvider_intermediates/package.apk] Error 127
make: *** Deleting file `out/xxxxxx/target/product/msm8226/obj/APPS/DownloadProvider_intermediates/package.apk'

******** Android build FAILED ********

error while loading shared libraries: libz.so.1: cannot open shared object file 安裝
$ sudo apt-get install lib32z1
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
下列【新】套件將會被安裝:
  lib32z1
升級 0 個,新安裝 1 個,移除 0 個,有 1 個未被升級。
需要下載 57.5 kB 的套件檔。
此操作完成之後,會多佔用 178 kB 的磁碟空間。
下載:1 http://tw.archive.ubuntu.com/ubuntu/ trusty/main lib32z1 amd64 1:1.2.8.dfsg-1ubuntu1 [57.5 kB]
取得 57.5 kB 用了 0s (176 kB/s)
選取了原先未選的套件 lib32z1。
(讀取資料庫 ... 目前共安裝了 214592 個檔案和目錄。)
Preparing to unpack .../lib32z1_1%3a1.2.8.dfsg-1ubuntu1_amd64.deb ...
Unpacking lib32z1 (1:1.2.8.dfsg-1ubuntu1) ...
設定 lib32z1 (1:1.2.8.dfsg-1ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.3) ...

Case 2:
host C++: aidl <= frameworks/base/tools/aidl/generate_java.cpp
host C++: aidl <= frameworks/base/tools/aidl/generate_java_binder.cpp
host C++: aidl <= frameworks/base/tools/aidl/generate_java_rpc.cpp
host C++: aidl <= out/xxxxxx/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp
out/xxxxxx/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp: In function 'int yyparse()':
out/xxxxxx/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1947:30: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
out/xxxxxx/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:2091:30: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
Export includes file: frameworks/base/tools/aidl/Android.mk -- out/xxxxxx/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/export_includes
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
Notice file: frameworks/base/tools/aidl/NOTICE -- out/xxxxxx/host/linux-x86/obj/NOTICE_FILES/src//bin/aidl.txt
/bin/bash: flex: command not found
make: *** [out/xxxxxx/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 127
make: *** Waiting for unfinished jobs....
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

******** Android build FAILED ********

安裝
sudo apt-get install flex

Case 3:

 sudo apt-get install libxml2-utils

[ubuntu] 安裝Java 6

安裝 JDK 6

下載網址
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html

$ chmod +x jdk-6u26-linux-x64.bin
$ ./jdk-6u32-linux-x64.bin
$ sudo mkdir -p /usr/lib/jvm
$ sudo mv jdk1.6.0_26 /usr/lib/jvm/

安裝
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_26/bin/javac 1
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_26/bin/java 1

設定使用版本
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java

檢查版本
$ java -version

2014年10月9日 星期四

[ubuntu] 安裝Samba

安裝samba
# sudo apt-get install samba
修改設定
#  vi /etc/samba/smb.conf 

[workspaces]
   comment = workspaces
   path = /home/aa/workspaces/
   browseable = yes
   read only = no
   create mask = 774
   valid users = aa
   admin users = aa

重啟
# sudo /etc/init.d/samba restart 
新增帳號
# sudo smbpasswd -a xxxx

[ubuntu] ssh 安裝

安裝ssh
# apt-get install ssh
# apt-get install openssh-server
修改設定
# vim /etc/ssh/sshd_config
Port 22
PasswordAuthentication yes
重啟
# /etc/init.d/ssh restart

[ubuntu] apt-get

設定proxy 
# /etc/apt/apt.conf 
    Acquire::http::Proxy "http://user:password@xxx.xxx.xxx.xxx:80"; 
source 清單 
# /etc/apt/sources.list 

[ubuntu] grep 用法

grep --help
用法: grep [選項]... 樣板 [檔案]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c

Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression (ERE)
  -F, --fixed-strings       PATTERN is a set of newline-separated fixed strings
  -G, --basic-regexp        PATTERN is a basic regular expression (BRE)
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -e, --regexp=PATTERN      use PATTERN for matching
  -f, --file=FILE           obtain PATTERN from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline

Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             print version information and exit
      --help                display this help and exit
      --mmap                ignored for backwards compatibility

Output control:
  -m, --max-count=NUM       stop after NUM matches
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line
  -H, --with-filename       print the filename for each match
  -h, --no-filename         suppress the prefixing filename on output
      --label=LABEL         print LABEL as filename for standard input
  -o, --only-matching       show only the part of a line matching PATTERN
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE;
                            TYPE is `binary', `text', or `without-match'
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories;
                            ACTION is `read', `recurse', or `skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                            ACTION is `read' or `skip'
  -R, -r, --recursive       equivalent to --directories=recurse
      --include=FILE_PATTERN  search only files that match FILE_PATTERN
      --exclude=FILE_PATTERN  skip files and directories matching FILE_PATTERN
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=PATTERN  directories that match PATTERN will be skipped.
  -L, --files-without-match  print only names of FILEs containing no match
  -l, --files-with-matches  print only names of FILEs containing matches
  -c, --count               print only a count of matching lines per FILE
  -T, --initial-tab         make tabs line up (if needed)
  -Z, --null                print 0 byte after FILE name

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is `always', `never', or `auto'
  -U, --binary              do not strip CR characters at EOL (MSDOS)
  -u, --unix-byte-offsets   report offsets as if CRs were not there (MSDOS)

`egrep' means `grep -E'.  `fgrep' means `grep -F'.
Direct invocation as either `egrep' or `fgrep' is deprecated.
With no FILE, or when FILE is -, read standard input.  If less than two FILEs
are given, assume -h.  Exit status is 0 if any line was selected, 1 otherwise;
if any error occurs and -q was not given, the exit status is 2.

Report bugs to: bug-grep@gnu.org
GNU Grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <http://www.gnu.org/gethelp/>

[ubuntu] find 指令

find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]   
    -name 檔名
        ex. find . -name "*.php"
    -i 不區分大小寫
        ex. find . -iname "*.php"
    -not
        ex. find . -not -name "*.php"
    -type
        f 檔案           
            ex. find -type f -iname "*gsm*"
        d 目錄
            ex. find -type d -iname "*gsm*"     

2013年12月18日 星期三

[android][ubuntu] build android 4.4 error

    build android 4.4  出現下面的error


    拜訪谷哥大神

     https://groups.google.com/forum/#!topic/android-building/8Z5bAN7M07w

     看來是java版本不合
    
     參考網友的經驗升級到 Java SE Development Kit 6u26

     怎麼升級 java 呢?

     參考網址
     https://help.ubuntu.com/community/Java#Oracle_.28Sun.29_Java_6

     $ sudo chmod u+x jdk-6u26-linux-x64.bin
     $ sudo ./jdk-6u26linux-x64.bin
     $ sudo mv jdk1.6.0_26 /usr/lib/jvm
     $ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_26/bin/java" 1
     $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_26/bin/javac" 1
     $ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.6.0_26/bin/javaws" 1
     $ sudo update-alternatives --config java
     $ sudo update-alternatives --config javac

      因為 \dev\android\build\envsetup.sh



      所以需要定義 JAVA_HOME

     export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_26

2012年12月14日 星期五

[ubuntu] 小技巧


  ==========================================================
echo $PATH
  ==========================================================
find

find /etc -iname 'Network'


find /etc -iname 'apache2' -type d

   –type 參數值

b      block (buffered) special

c      character (unbuffered) special

d      directory ( 一般目錄 )

p      named pipe (FIFO)

f      regular file ( 一般檔案 )

l      symbolic link

s      socket

D      door (Solaris)
  ==========================================================
vi

顯示行數 :set nu
恢復 u
  ==========================================================

改電腦名稱

vim /etc/hostname

  ==========================================================

crontab   定期執行

  ==========================================================

安裝SAMBA
sudo apt-get install samba4
hw@ubuntu:/etc/samba$ sudo vim smb.conf

[workspaces]
   comment = workspaces
   path = /home/hw/workspaces/
   browseable = yes
   read only = no
   create mask = 774
   valid users = hw
   admin users = hw

hw@ubuntu:/etc/init.d$ samba restart

hw@ubuntu:/etc/samba$ sudo smbpasswd -a hw
New SMB password:
Retype new SMB password:
hw@ubuntu:/etc/samba$
  ==========================================================

[ubuntu] 使用rsync備份

1.裝rsync
apt-get install rsync

2.修改/etc/default/rsync
RSYNC_ENABLE=false --> RSYNC_ENABLE=true

3.修改 rsync 設定檔
vim /etc/rsyncd.conf


log file=/var/log/rsyncd.log
[Home]
path = /backup/Document
auth users = hw
uid = tsry
gid = tsry
secrets file = /etc/rsyncd.secrets
read only = no
strict modes = false #非root 必加

4.設定hw的帳號密碼
vi /etc/rsyncd.secrets
hw:hw1

PS. 注意權限和擁有者

5.啟動rsync
/etc/init.d/rsync start

測試






6.設定要登入的密碼
vim /tsry/rsyncd.secrets
內容只需打密碼
hw1





權限要設為 600,否則無法備份成功!

開始備份
rsync -avHS --numeric-ids --delete --password-file=/tsry/rsyncd.secrets /tsry/Documents/MyDocuments hw@127.0.0.1::Home



2012年12月13日 星期四