Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Open a terminal and Execute commands and Keep terminal open

gnome-terminal --tab -e "/bin/bash -c 'ls -al ; exec /bin/bash -i'"

Vi & Vim Tutorial

cite:
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html


:set wrap
:set nowrap

Replace all string in document



  • : %s / ______________ /\ ________________/ g

Set tab spaces

1. vim /etc/vim/vimrc
2. set ts=4


利用字串取代('^M' 要用 Ctrl+V 不要放開 Ctrl 再按 M 才能打出來喔!)
   :%s/^M/\r/g


Display the line number in vim



  1. vim /etc/vim/vimrc
  2. :set number


Foreground and Background Switch

1) Ctrl + z
2) fg ....
http://arjanvandergaag.nl/blog/foreground-and-background-processes.html

Set current line highlight

set cursorline
hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white

lightmagenta darkgray lightgrey darkgrey lightgreen lightgray darkmagenta gray white red grey darkred brown darkblue darkgreen lightblue yellow cyan

Folding codes in vim

1. visual select the codes (v) (ctrl+v)
2. zf
3. za

相關文件

Git

相關文件


使用 cscope + ctags + taglist 來閱讀sourcecode

ctags + taglist

1) Install ctags

$   sudo apt-get install exuberant-ctags

2)Download and install taglist
https://sourceforge.net/projects/ctags/files/
http://vim-taglist.sourceforge.net/

$   unzip taglist_45.zip
#it will generate plugin and doc

$   mv plugin/   ~/.vim
$   mv doc/   ~/.vim

3)turn on/off the taglist in vim

$   sudo vim /etc/vim/vimrc

Add the following line:

map <f9> :Tlist<CR>


4)check the target directory and create the tags

$   ctags -R *.c *.h

OR

$   find 'pwd' -type f -name "*.[ch]" -o -name "*.cc" -o -name "*.[sS]"  | sed -e 's/^/"/' -e 's/$/"/' | xargs /usr/bin/ctags -a

5)Open the vim and press F9
#The window will divide by two part, use the Ctrl-W-W to switch the window
#The left window: Jump to the correspond function or definition
#The right window:
   Ctrl+]:Jump to function implement position, the cursor should be the function name's front
   Ctrl+t:return to the original position

cite:http://stenlyho.blogspot.com/2008/11/ubuntuvim-plugin-ctagstaglist.html

Cscope




Call Graph
CCTree: http://www.vim.org/scripts/script.php?script_id=2368

make 命令 & makefile

makefile syntax

  • dependencies (相依性項目)
    • one target (目標項目)
    • some source code files
    • (target), (semicolon), (space or tab), ....., (source code files), (space or tab), .....
    • e.g. all: myapp myapp.l
  • rules (法則)
    • the rules illustrate how to generate a target
    • (tab)
    • the rules muse be on the same line
  • comment (註解)
    • (#)
  • macro (巨集)
    • define the macro => MACRONAME = value
    • access the macro => $(MACRONAME), ${MACRONAME}
  • -
    • make will ignore the error
    • e.g. -mkdir
    • e.g. -rm -r
  • @
    • make will not output the executed command on standard output
  • #這是makefile的格式(註解) 
    [target]: [dependency] [dependency] 
    [TAB][rule] 
    [TAB][rule] 
    [target]: [dependency] 
    [TAB][rule] 

make options


-k : 會讓make再遇到錯誤之時,仍然繼續執行而不會停在第一個問題點。可以利用這個選項找出發生問題的原始碼檔案。

-n : 告訴make只列出要進行的工作,而不會真正去執行它。

-f : tell the make to use the as a makefile. Otherwise, the make will use the makefile, Makefile (recommend).

-p : 要求 make 印出內建法則

-j3 : use the 3 cores 

Automatic Varaiables


$@ :  The name of the current target 

$% :  The filename element of an archive member specification

$<: first="" he="" name="" nbsp="" of="" p="" prerequisite="" the="">
$?:    The names of all prerequisites that are newer than the target, separated by spaces,代表須要重建(被修改)的相依性項目

$^:     The names of all prerequisites, separated by spaces. This is list has duplicated names removed.

$+:     Similar to $^, except $+ includes duplicateds.. This variable was created for specific situations such as arguments to linkers where duplicated values have meaning.

$*:    The stem of the target filename. A stem is typically a filename without its suffix. Current dependencies without the extension (副檔名)


  1. define the marcro : 1) make CC=c89    2) make "CC = c89"
  2. Use the all as the first target in makefile
  3. all (target)
  4. install (target)
  5. uninstall (target)
  6. clean (target)


GNU gcc

gcc -MM : generate a dependency list to make


Conventional Macros (common built in rules of makefiles)

typing "make −p" to print out the defaults
ARArchive−maintaining program; default is `ar'.
ASProgram for compiling assembly files; default is `as'.
CCProgram for compiling C programs; default is `cc'.
COProgram for checking out files from RCS; default is `co'.
CXXProgram for compiling C++ programs; default is `g++'.
CPPProgram for running the C preprocessor, with results to standard output; default is `$(CC) -E'.
ARFLAGSFlags to give the archive-maintaining program; default is `rv'.
ASFLAGSExtra flags to give to the assembler when explicitly invoked on a `.s' or `.S' file.
CFLAGSExtra flags to give to the C compiler.
CXXFLAGSExtra flags to give to the C compiler.
COFLAGSExtra flags to give to the RCS co program.
CPPFLAGSExtra flags to give to the C preprocessor and programs, which use it (such as C and Fortran compilers).

Conditional Directives

  • ifeq
  • ifneq
  • ifdef
  • ifndef
  • else
  • endif
e.g.
ifeq (arg1, arg2)
ifeq 'arg1' 'arg2'
ifeq "arg1" "arg2"
ifeq "arg1" 'arg2'
ifeq 'arg1' "arg2" 

相關文件


Introduce the Linux Directories


If you look at the Linux file hierarchy, you find the following :
  • /bin - common binaries
  • /sbin - Binaries used for system administration are placed here.
  • /boot - static files of the boot loader. Usually it contain the Linux kernel, Grub boot loader files and so on.
  • /dev - device files such as your CD drive, hard disk, and any other physical device. (In Linux/Unix, the common premise is that everything is a file).
  • /home - user home directories are found here. In unices like FreeBSD, the home directoriesare found in /usr/home. And in Solaris it is in /export. So quite a big difference here.
  • /lib - Essential shared libraries and kernel modules
  • /mnt - temporary mount point useful for when you insert your USB stick and it gets mounted under /mnt. Though in Ubuntu and the likes, it is usually mounted under /media.
  • /var - variable data, such as logs, news, mail spool files and so on which is constantly being modified by various programs running on your system.
  • /tmp - temporary files are placed here by default.
  • /usr - the secondary hierarchy which contain its own bin and sbin sub-directories.
  • /etc - Usually contain the configuration files for all the programs that run on your Linux/Unix system.
  • /opt - Third party application packages which does not conform to the standard Linux file hierarchy can be installed here.
  • /srv - Contains data for services provided by the system.