레이블이 linux인 게시물을 표시합니다. 모든 게시물 표시
레이블이 linux인 게시물을 표시합니다. 모든 게시물 표시

2015년 6월 10일 수요일

Extract even or odd line of text files 텍스트 파일에서 홀수나 짝수 줄만 뽑아내기

먼저 ouput file에서 특정 이름을 찾아서 line number, column3 column4 를 출력하는 예

grep 'EHn3lo(Q^4)' out_file | awk '{print NR" "$3"  "$4}'


출력 결과에서 짝수번째 결과만 뽑고 싶은 경우 

awk 'NR%2==0 {print $1}' infile


예를 들어 out_He6_idx02 라는 file에서 binding energy (MeV) 가 나오는
줄을 모두 찾은 뒤 그 중 짝수번재 라인에서 4번재와 5번째 Column 의
내용만 보고 싶을 때,

grep 'binding energy (MeV)' out_He6_idx02 | awk 'NR%2==0 {print NR" "$4"  "$5}'

2015년 5월 20일 수요일

Intel Math Kernel Library (MKL) and FFTW3 링크하기

먼저 MKL library의 위치를 찾을 것. 
MKL library에 FFTW가 포함되어 있다고 하지만 FFTW의 위치도 알아둘 것.

MKL libary를 사용하는 방법은 두가지가 있다.

(1) -mkl 옵션을 사용하는 방법
(2) 모든 옵션을 일일이 지정해 주는 방법
-mkl 옵션의 경우 default 설정이 무엇인가에  따라 달라지게 된다.일반적인 경우라면,

ifort test.f90 -mkl -o test_f
icc test.c -mkl -o test_c

만으로 충분하고 FFTW를 사용하는 경우에는 

icc test.c -w -DMKL_DOUBLE -I/opt/intel/Compiler/11.1/069/mkl/include/fftw -mkl -o test_c

ifort -I/opt/intel/Compiler/11.1/069/mkl/include/fftw test.f90 -mkl -o test_f

icc test.c -I/opt/intel/Compiler/11.1/069/mkl/include/fftw -mkl -o test_c

ifort test.f90 -I/opt/intel/Compiler/11.1/069/mkl/include/fftw -mkl -o test_f

와 같이 include path를 지정해 주는 것이 좋다고 한다. 

-mkl 옵션을 쓰지 않으면 아래와 같이 일일이 써 주어야한다. 

icc test.c -I/opt/intel/Compiler/11.1/069/mkl/include -I/opt/intel/Compiler/11.1/069/mkl/include/fftw
-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm 
-L/opt/intel/Compiler/11.1/069/mkl/lib/em64t -o c_test 

ifort test.f90 -I/opt/intel/Compiler/11.1/069/mkl/include -I/opt/intel/Compiler/11.1/069/mkl/include/fftw 
-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm 
-L/opt/intel/Compiler/11.1/069/mkl/lib/em64t -o f_test


(주의1) -lmkl_intel_lp64 는 64bit cpu 용 libary를 사용한다는 뜻이고,  
-lmkl_intel_ilp64 는 64bit cpu 용 libary를 사용하되 
정수도 64bit인 libary를 사용한다는 뜻으로 compile 할 때 -i8 option을 추가해 주어야 한다.   
ilp64를 사용할 경우 FFTW와 integer type이 다를 수 있으므로 주의해야 한다.

(주의2) FFTW2 를 사용할 경우는 option을 다르게 주어야한다.
icc test2.c -o test2_c -I/opt/intel/Compiler/11.1/069/mkl/include/fftw 
-L/opt/intel/Compiler/11.1/069/mkl/lib/em64t -lfftw2xc_intel -mkl 

ifort test2.f -o test2_f -I/opt/intel/Compiler/11.1/069/mkl/include/fftw 
-L/opt/intel/Compiler/11.1/069/mkl/lib/em64t -lfftw2xf_intel -mkl

만약 외부 FFTW library를 사용하는 경우에는 아래와 같이 사용한다.
ifort -O3 -o fftw_example.exe fftw_example.f -I/u/username/fftw/include -L/u/username/fftw/lib -lfftw3

참고:

http://geco.mines.edu/software/mkl/fftw/

http://www.nas.nasa.gov/hecc/support/kb/MKL-FFTW-Interface_204.html



(Details on the -mkl option )


-mkl[=]
          link to the Intel(R) Math Kernel Library (Intel(R) MKL) and
          bring in the associated headers
            parallel   - link using the threaded Intel(R) MKL libraries.
                         This is the default when -mkl is specified
            sequential - link using the non-threaded Intel(R) MKL libraries
            cluster    - link using the Intel(R) MKL Cluster libraries plus
                         the sequential Intel(R) MKL libraries
The libraries that are linked in for:
    * -mkl=parallel

          --start-group \
          -lmkl_solver_lp64 \
          -lmkl_intel_lp64 \
          -lmkl_intel_thread \
          -lmkl_core \
          -liomp5 \
          --end-group \

    * -mkl=sequential

          --start-group \
          -lmkl_solver_lp64_sequential \
          -lmkl_intel_lp64 \
          -lmkl_sequential \
          -lmkl_core \
          --end-group \

    * -mkl=cluster

          --start-group \
          -lmkl_solver_lp64 \
          -lmkl_intel_lp64 \
          -lmkl_cdft_core \
          -lmkl_scalapack_lp64 \
          -lmkl_blacs_lp64 \
          -lmkl_sequential \
          -lmkl_core \
          -liomp5 \
          --end-group \

2014년 10월 18일 토요일

ssh 로 특정 폴더/디렉토리로 바로 접속하기 및 설정


ssh -t [id@][xxx.xxx.xxx.xxx] "cd [destination] ;exec \$SHELL -l"

# 오래된 서버에 접속하려니 ssh-rsa 나 ssh-dss 를 사용하라고 할 경우

(1) 설정파일 만들기 "~/.ssh/config" file에 아래 내용 추가 
HOST [hostname]
     HostName [address]
     User [user_id]
     HostKeyAlgorithms=+ssh-dss
(2) 이제 ssh [hostname] 으로 접속할 수 있다. 
    

2014년 7월 22일 화요일

black screen after login screen 로긴 화면 다음에 검은 화면이 나오는 문제

display problem after update/upgrade ubuntu

우분투를 사용하면서 무심코 업데이트를 시켰는데,
리부팅후 로그인 후 갑자기 화면이 검게 변하면서 아무런 반응을 보이지 않는 현상이 생겼다.
인터넷을 찾아보니 다음과 같은 방법으로 해결할 수 있었다. 하지만, 여전히 문제가 완전히 해결된 것인지는 확실하지 않다.

증상: 로그인 화면까지는 정상적으로 나타난다. 하지만, 로그인을 하고 나면 black screen으로 변한다.
2014/12/11: Nvidia driver 를 update 한 뒤 비슷한 문제가 다시 생겼다.

해결책: 확실하지는 않지만, 일단 다음과 같은 방법으로 로그인후 정상적인 화면이 나타나도록 되었다.

(1) 로그인 화면에서 CTRL+ALT+F1 을 누른다. 그러면 terminal과 비슷한 text 화면이 나타난다. (Emergency text/command terminal)
(2) 로그인 후, 다음 명령으로 xserver-xorg를 제거한다.

    sudo apt-get remove --purge xserver-xorg

2014/12/11: Nvidia driver 를 제거했다. 
    sudo apt-get remove --purge nvidia-*

(3) CTRL+ALT+DEL 을 눌러 리부팅한다.
(4) 리부팅 후 다시 CTRL+ALT+F1으로 prompt 상태로 바꾸어 로그인한다. (원래 설명에서는 UBUNTU logo 와 그 밑의 다섯개 점이 움직이는 동안에 해야만 하고, 로그인 스크린이 나오기 전에 해야만 한다고 하는데, 나의 경우에는 상관이 없었다.
(5) 로그인후 다음 명령으로 xserver-xorg를 다시 install 한다.

sudo apt-get install xserver-xorg

(6) xorg 설정을 다시 한다.

sudo dpkg-reconfigure xserver-xorg

(7) 리부팅 후 로그인하면, 문제가 해결되었다. (원래 설명에서는 startx 를 사용하여 GUI 로 바꾸라고 되어 있는데, 상관 없는 듯 하다.)


2014년 7월 6일 일요일

Linux 에서 Path 지정하기 (Original page http://www.cyberciti.biz/faq/unix-linux-adding-path/)

UNIX / Linux: Set your PATH Variable Using set or export Command


Finding out your current path

 
echo "$PATH"
 
OR
 
printf "%s\n" "$PATH"
 
How do I modify my path?
Bash, Sh, Ksh shell syntax to modify $PATH
If you are using bash, sh, or ksh, at the shell prompt, type:
## please note 'PATH' is CASE sensitivity and must be in UPPERCASE ##
export PATH=$PATH:/path/to/dir1
export PATH=$PATH:/path/to/dir1:/path/to/dir2
 
OR
## please note 'PATH' is CASE sensitivity and must be in UPPERCASE ##
PATH=$PATH:/path/to/dir1; export PATH
 
Tcsh or csh shell syntax to modify $PATH
If you are using tcsh or csh, shell enter:
 ## please note 'path' is case sensitivity and must be in lowercase ##
set path = ($path /path/to/dir1)
set path = ($path /path/to/dir1 /path/to/dir2)
 
OR
## please note 'PATH' is CASE sensitivity and must be in UPPERCASE ##
setenv PATH $PATH:/path/to/dir1
setenv PATH $PATH:/path/to/dir1:/path/to/dir2
 
To make these changes permanent, add the commands described above to the end of your~/.profile file for sh and ksh shell, or ~/.bash_profile file for bash shell:
## BASH SHELL ##
echo 'export PATH=$PATH:/usr/local/bin'  >> ~/.bash_profile
 
KSH/sh shell user try:
## KSH / SH SHELL ##
echo 'export PATH=$PATH:/usr/local/bin'  >> ~/.profile
 
In this final example add /usr/local/bin/ and /scripts/admin/ to your path under csh / tcsh shell, enter:
 
set path = ($path /usr/local/bin /scripts/admin)
 
OR
 
setenv PATH $PATH:/usr/local/bin:/scripts/admin
 
To make these changes permanent, add the commands described above to the end of your~/.cshrc file:
 
echo 'set path = ($path /usr/local/bin /scripts/admin)'  >> ~/.cshrc
 
OR
 
echo 'setenv PATH $PATH:/usr/local/bin:/scripts/admin'  >> ~/.cshrc
 
To verify new path settings, enter:
$ echo $PATH

2014년 6월 12일 목요일

Linux Library 사용하기

Linux 에서 사용하는 library는 크게 두가지로 나뉜다.


  • Static library
  • Shared library(or Dynamical library)


Ubuntu software center 에서 library 를 찾아보면 static 인 경우도 있고 shared 인 경우도 있다. 초보자의 입장에서는 별로 상관이 없고, 사용법만 알 면 될 것 같은데,
문제는 경우에 따라 다운 받은 library를 사용하는 데 compiler 가 library를 못찾는 경우가 있다.

저장되는 library는 3가지 중에 하나의 이름을 가진다.

  • linker 가 사용하는 이름: 'lib' 로 시작하고 '.a' 나 '.so' 로 끝나는 이름. '.a' 는 static library 인 경우이고 '.so'는 shared object library인 경우이다. (예: libpthread.so) 이것은 Dynamic library 라고 불린다. 
  • Fully qualified name or soname: linker 가 사용하는 이름과 같지만, 마지막에 버전 넘버가 붙는다. (예: libpthread.so.1) 
  • Real name : 버전 넘버 뒤에 마이너 버전 넘버가 붙는 경우.(예: libpthread.so.1.1 )


library를 다운 받으면 보통 다음 3개 directory 중 하나에 저장된다고 한다.

  • /lib   : 처음 linux start up 에서 사용되거나 root file system이 사용하는 library들이 위치한다.
  • /usr/lib : 대부분의 user 가 사용하거나 system 이 internally 사용하는 library들이 위치한다. 
  • /usr/local/lib : standard libary가 아닌 대부분의 library가 위치한다.

이러한 표준 directory에 저장된 경우 특별한 위치 지정이 없어도 library를 컴파일러가 알아서 찾지만, 그 이외의 특별한 위치에 저장되면 그 위치를 알려 주어야만 library를 사용할 수 있다.  

보통 지정해 주어야하는 directory는 linker 가 사용하는 이름인 *.a 나 *.so 가 있는 곳이다.

gcc -L/usr/lib -llapack -lmathlib

gcc 에서 -L 은 디렉토리 위치를 추가하기 위한 것이고, -l 은 library를 불러오기 위한 것이다.
여기서 -l 뒤에 library의 이름을 붙이는데 library 이름 중 lib 는 뺀다. (예를 들어 원래 library 이름이 liblapack.a 일 때 lapack 만 사용한다.)

2014년 6월 11일 수요일

Ubuntu Setting Up

내가 항상 vmware 로 새로운 우분투를 깔 때마다 새로 설정해야하는 사항들을 모아보자.

1. 우분투 설치하기 및 update

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install build-essentials

2. Tweak : scroll bar 설정, launcher 의 icon size변경, work space 사용하기 등등...

  • make a shortcut of terminal to task bar
  • Repository and package manager (In System> software and update)
        enable the Canonical Partners’ Repository.
        sudo apt install synaptic
        sudo apt install gdebi

  • Additional Drivers (In System> software and update)
  • enable Workspace( System Settings >>> Appearance >>> Behavior)
  • Fix app menu problem(System Settings >>> Appearance >>> Behavior tab >> ‘Show the Menus for a Window’ . always displayed)




3. install Java: sudo apt-get install default-jre

4. Nautilus configuration:
  • open terminal command in nautilus: sudo apt-get install nautilus-open-terminal 
(From 16.04, it seems not need to install nautilus-open-terminal. Also, new terminal opens a new tab by 'control-shift-T' )
  • nautilus action configure tool to make customization of right click in nautilus :
  • sudo apt-get install nautilus-actions-configuration (From 16.04, I could not find the package)        
  • Bookmark the network server I use
  • install meld nautilus-compare
5. classic menu indicator

6. dropbox 설치
    sudo apt install nautilus-dropbox

7. secpanel

8. Texworks and latex
    : for tex, install texlive, texlive-extras, texlive-publishers (for revtex)

9. Numerical libraries:
  • gfortran 
  • LAPACK, SCALAPACK: liblapack, libscalapack 을 검색해서 install 
    (여러 패키지중에서 dev 가 붙어 있고 static 이라고 쓰여 있는 것. liblapack.a 파일이 있는지 확인할 것.)
  • MATHLIB: install libmathlib2-dev   or install cernlib
  • MPICH: 
      sudo apt install gfortran
      sudo apt install libmpich-dev
  • LAPACK, scalapack: 
      sudo apt install liblapack-dev
      sudo apt install libscalapack-mpi-dev
  • openmpi: 
      sudo apt install openmpi-bin openmpi-dev

  • FFTW3:  sudo apt-get install  fftw3-dev 

10. build-essential package

     sudo apt install build-essential
     sudo apt install gfortran

11. vim and change its color scheme : vimrc file 복사하기, encryption method change
     ( default vi editor is not good to use.) 

     sudo apt install vim vim-gtk

.vimrc  example
--------------------
" When searching try to be smart about cases
set smartcase
" Makes search act like search in modern browsers
set incsearch
" Show matching brackets when text indicator is over them
set showmatch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:syntax enable
set background=dark
:colo desert

" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8

" Use Unix as the standard file type
set ffs=unix,dos,mac

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>

" Shortcuts using <leader>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm

" Set encryption method to blowfish
set cm=blowfish
     


---------------------

12. gftp or filezilla

13. variety : wallpaper changer

14. python and ipython, matplotlib, scitools, scipy , pip

     # add alias to .bashrc_aliases file
        alias python=python3  

      sudo apt-get install ipython
      sudo apt-get install python-pip python-tk
      python -m pip install --upgrade pip
pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
# Consider adding this at the end of your ~/.bashrc file
    export PATH="$PATH:/home/[your_user]/.local/bin"
15. Make /bin and /lib directory for personal usage.
    # add path in .basrc
    export PATH=$PATH:/home/yhsong/bin:/home/yhsong/lib

16. gnuplot
    FRESCO

    sudo apt install gnuplot-qt

and more ...


Ubuntu 18.04 : click-action setting.
                One can choose click-action for the dock :
                 'minimize', 'minimize-or-overview', 'previews','cycle-windows'

gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'


10-or-20-things-to-do-after-installing-ubuntu-14-04-trusty-tahr

http://scienceblogs.com/gregladen/2014/04/24/10-or-20-things-to-do-after-installing-ubuntu-14-04-trusty-tahr/

2014년 6월 10일 화요일

Remove/Uninstall Copy.com from Ubuntu

THESE are copied from other site and here for easy reference.



Follow these steps to completely remove Copy from your system:
  1. Disable autostart for each user, if necessary. (You don't need to use sudo if no other user accounts on your system are using Copy)...
    sudo rm -rf /home/<user>/.config/autostart/CopyAgent.desktop
    
  2. Log out and log back in. This will shut down the running copy process so it does not re-create the files you are about to delete in step 3. (You can also just kill the "CopyAgent" process using System Monitor if you don't want to log out.)
  3. Execute the following for each user, if necessary. (You don't need to use sudo if no other user accounts on your system are using Copy).
    sudo rm -rf /home/<user>/<path_to_users_copy_folder>/.copy.cache/
    sudo rm -rf /home/<user>/<path_to_users_copy_folder>/.user_info
    sudo rm -rf /home/<user>/.copy
    sudo rm -rf /home/<user>/.icons
    
  4. If you had manually installed the Nautilus overlay icons, uninstall them...
    sudo <installation_location>/<architecture>/CopyCmd Overlay remove
    
  5. Uninstall Copy software...
    sudo rm -rf /root/.copy
    
  6. If you had manually added a launcher shortcut, remove it. Assuming you called the launcher "copy.desktop" do the following.
    For all users...
    sudo rm  /usr/share/applications/copy.desktop
    
    Or, for each user...
    sudo rm  /home/<user>/.local/share/applications/copy.desktop
    
Note, in the above steps...
  • Replace <user> with the user on your system that is using Copy.
  • Replace <path_to_users_copy_folder> with the user's local "Copy" folder (for example, Documents/Copy).
  • Replace <installation_location> with the location where you installed Copy (for example /usr/share/copy).
  • Replace <architecture> with "x86" (if you have a 32bit computer) or with "x86_64" (if you have a 64bit computer).

2014년 5월 19일 월요일

Linux tips

1. VI, VIM tips

(1)Case Insensitive search in vi

 If you want to ignore case for one specific pattern, you can do this by
prepending the "\c" string. Using "\C" will make the pattern to match case.

(2) Change characters into all lower or upper capitals.

 ":%s/[A-Z]/\L&/g" or  ":%s/[a-z]/\U&/g" 


(3)Copy/Paste to/from clipboard.

: Check 'vim --version' if it has '+clipboard' .  If it is not, one may install vim-gnome or vim+gtk.
  One can copy to clipboard after selecting in visual mode by "+y 
  (With shift key, press " and press + , then release shift key and press y ). 


(4) Enable/Diable Auto indent
:  use ":set ai" or "set si" for autoindent or smart indent. 

 2. SED tips


(1) search strings with special character :  put \ in front of any special character
(2) wild character : use .* instead *
   Ex:    sed ‘s/\[.*\]/xxx/’    replaces string ‘[......]’ to ‘xxx’


 Removing ^M from file: 



 1. To remove the ^M character, in ViM, write the following in the command mode and press :w to save the changes:

 :set fileformat=unix

 2. Or, type this script in ViM, in the command mode and type :w to save the changes:
   ^V^M gives ^M character in the screen
:1,$s/^V^M//g

 3. With sed:

 $ sed 's/^M//g' filename > newfilename

 4. With Dos2Unix:

 $ dos2unix filename newfilename

 5. With col:

 $ cat filename | col -b > newfilename

 use Internet Explorer (IE) as an FTP client.
ftp://[id]@[ftpaddress]:{port} or ftp://[ftpaddress]:{port}


 change multiple file names


rename "s/ *//g" *.mp3


 column editing:


Notepad++, Visual Studio, and some others: Alt + drag.
vim: Ctrl + v 
Netbeans 7.1 can select columns (Rectangular Selection) with Ctrl + shift + R 
Since Eclipse 3.5, you just need to type Alt+Shift+A
In Kate toggle Ctrl + shift + B


 Delete many files except several:


        [wild cards][Control+shift+x, *]   (즉 ^X*) 
        shows all visible files match. Then remove those from the list to keep.


VIM editor encryption:

1. edit .vimrc file and add 'set cm=blowfish'. This gives better encryption.
2. Set encrption password by ':X'
3. make change and save file. Now the file is encrypted.
4. To remove ecncryption, set blank key by 'set key=' .