반응형


집에서 사용하는 라우터에 usb 하드디스크를 물려 망내 쉐어디스크로 사용중이며 samba 로 연결하여, 편리한게 아이패드나, 아이폰 그리고 xbmc 에서 미디어 파일들을 접근하여 사용하고 있습니다.


요즘 유닉스/리눅스 공부한다고, 좀 사양 떨어진 넷북에 주분투를 설치하였고 메인 컴퓨터는 맥북이 있지요. 둘다 유닉스 계열 OS 라 많이 편하네요. 여하튼  양쪽 컴퓨터에서 미디어 파일들을 usb 하드디스크에 올리고 싶은데요.. 직접 분리해서 usb 로 연결하는게 가장 좋은 방법이긴 합니다만.. 그래도 라우터에 물려 있으니 일종의 공유폴더로 연결하여 넷북에서 네트워크를 이용한 파일 업/다운로드 를 하고 싶더라구요.

그래서 알아보니, 의외로 간단했습니다.


1. 홈디렉토리에 media/share 폴더를 만든다

2. etc/fstab 파일을 열어 아래 내용을 적어준다

3. 마운트 한다.



1. 홈디렉토리에 media/share 폴더를 만든다


mkdir /media/share


2. etc/fstab 파일을 열어 아래 내용을 적어준다


중요한 부분은 삼바 서버의 공유파일 경로입니다.

확인하려면 아래 명령어로 확인 할 수 있습니다.

서버이름 혹은 아이피를 사용하여도 되며, -U 뒤에 있는 admin 은 사용자 이름입니다.


sambaclient -L 192.168.1.1 -U admin


공유된 폴더가 usb0_1 인것을 확인 할 수 있습니다. 자 그럼 /etc/fstab 의 내용을 변경해 봅니다.

읽기 전용파일 이라서 관리자 모드로 sudo 를 넣어줘야 변경이 가능합니다.


명령어 내용은

[//경로/공유폴더] [내컴퓨터마운드폴더] [파일타입] [사용자,패드워드] [0,0]


파일타입은 오래된 자료의 경우 smbfs 파일타입을 사용하라고 하는데요, 이미 사용하지 않는 오래된 타입이라서 cifs 를 사용해야 하더군요. 패키지가 없으면 다운받을 수 있습니다. 


sudo apt-get install cifs-utils


파일을 열어 서버공유폴더 내용을 작성 해 줍니다. 참고로 fstab 은 시스템 컨픽 파일로, 유닉스/리눅스 시스템에서 볼 수있습니다. uilt-linux 패키지중 하나며, 사용가능한 디스크 현황 그리고 파티션 현황 그리고 이 디스크와 파티션들이 시스템에서 어떻게 사용되는지의 정보를 가지고 있는 파일입니다.


sudo vim /etc/fstab

//192.168.1.1/usb0_1 media/share cifs user=admin,passwd=admin 0 0



내용을 저장하고 나옵니다. :qw


3. 마운트 한다.

smb 서버 공유폴더를 마운트 해줍니다. 마운트 하면 폴더 형태로 보이게 됩니다.


sudo mount media/share



짜쟌~

이렇게 파일 메니저에서 손쉽게 samba/공유 폴더 에 접근 가능케 되었습니다. 다운로드는 물론 업로드도 가능합니다. 하지만 제 라우터의 경우엔 너무 느리네요. usb 로 직접 꽂아서 파일 옮기는게 10000배 정도 빠른듯 합니다.



반응형
반응형


cat hello.txt : hello.txt 파일 내용을 보여줍니다.
more hello.txt : hello.txt 내용을 spacebar 를 이용하여 화면에 한페이지씩 보여줍니다. more page
less hello.txt : hello.txt 내용을 한줄 한줄 읽어 내려갈 수 있으며 spacebar 한페이지씩 보여줍니다. move a line by line
wc hello.txt : hello.txt 단어, 라인, word count
wc -l hello.txt : hello.txt 라인 카운트를 보여줍니다. no. of line
wc -c hello.txt : hello.txt 파일 크기를 보여줍니다. (byte)
wc -m hello.txt : hello.txt 글씨 카운트를 해줍니다. (character)
head -3 hello.txt : hello.txt 내용 중 첫 3 줄을 보여줍니다.
tail -3 hello.txt : hello.txt 내용 중 마지막 3줄을 보여줍니다.


history : 현재까지 실행했던 모든 명령어들을 보여줍니다.


Redirection

출력의 경로수정


cal : 달력을 출력합니다.


     August 2014   
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31


cal > output.txt : 달력을 출력한 뒤 내용을 outpu.txt 파일에 담습니다.

cat output.txt : output.txt 파일 내용을 화면에 출력합니다.


     August 2014   
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31


Pipeline

여러개의 명령어를 순차적으로 실행하여 결과값을 출력합니다.


cat /etc/passwd | tail -3


vmplayer:x:502:503:vmplayer:/images/vmplayer:/usr/bin/feit-windows-A2013.sh
oprofile:x:16:16:Special user account to be used by OProfile:/home/oprofile:/sbin/nologin
vmuser:x:503:504:vmuser:/var/lib/vmuser:/bin/bash

bash-4.1$ who
11776352 tty3         2014-08-13 12:06 (:0)
11776352 pts/0        2014-08-13 12:10 (:0.0)


bash-4.1$ who | head -1
11776352 tty3         2014-08-13 12:06 (:0)


bash-4.1$ who | grep 11776352
11776352 tty3         2014-08-13 12:06 (:0)
11776352 pts/0        2014-08-13 12:10 (:0.0)

bash-4.1$ cat /etc/passwd | cut -d: -f1,5


bash-4.1$ who
11776352 tty3         2014-08-13 12:06 (:0)
11776352 pts/0        2014-08-13 12:10 (:0.0)


bash-4.1$ who | cut -d' ' -f1
11776352
11776352
bash-4.1$ who | cut -d' ' -f1 | sort
11776352
11776352
bash-4.1$ who | cut -d' ' -f1 | sort | uniq
11776352
bash-4.1$ who | cut -d' ' -f1 | sort | uniq >username.txt

bash-4.1$ who | awk '{ print $3}'
2014-08-13
2014-08-13


bash-4.1$ who | awk '{ print $1, $3}'
11776352 2014-08-13
11776352 2014-08-13

bash-4.1$ ls /bin | wc -l
131


bash-4.1$ ls /bin | head -1
alsaunmute


bash-4.1$ ls /bin | head -10
alsaunmute
arch
awk
basename
bash
cat
cgclassify
cgcreate
cgdelete
cgexec


bash-4.1$ ls /bin | head -79 | tail -1
netstat


계산식
x=$((2+2))
echo x is $x //prints out the result




반응형
반응형



아직 포스팅할 내용들이 많지만..

db 연결 방법이 궁금해서 아주 간단한 mysql 연결 shell script 를 찾았습니다.


음.. 일단 mysql 서비스가 실행 한다는 가정하에.. dbtest.sh 라는 파일을 만듭니다.


vim dbtest.sh

 + dbtest.sh                                                                      

  1 #!/bin/bash

  2 mysql -u root redCat<<EOFMYSQL

  3 select * from MenuItem;

  4 EOFMYSQL


스크립트를 작성 후, 내용을 저장 한 뒤 권한을 바꿔줍니다. 

좀더 편리하게 만들 예정입니다만, 일단 가장 간단한 스크립드를 먼저 공유합니다.


chmod 700 dbtest.sh


제 맥에서 돌고 있는 mysql 서비스엔 redCat 이라는 데이터베이스가 있습니다. redCat 데이터 베이스 안에 있는 MenuItem 테이블의 내용을 모두 성공적으로 화면에 보여주었네요.


이상입니다. 

반응형
반응형


Vim 사용하시는 분들은 아마도 여러 세팅을 하여 config 을 저장할 수 있도록 한 뒤 사용중이라고 하네요. 이번에 간단하게 줄 번호 보여주는 세팅 과 인덴트 를 자동으로 해주는 세팅을 만들어봤습니다.


기본적으로 .vimrc 파일이 없어서 저는 만들어야 했습니다. 만들기 전에 확인 필수 입니다.


vim .vimrc



이렇게 만들고 나면 vim 실행하니 제 화면이 아래와 같이 변하였습니다.

그외에 더 많은 세팅을 원하시면 다음 링크가 유명한 Ultimate VIM configuration 입니다.


여하튼 vim 세팅은 이정도로 하고, 쉘 스크립트의 if-else 예문을 소개합니다.

shell script 의 if-else 는 간단합니다. 주의해야 할 점은 비교 변수와 "[" 그리고 시작의 "if" 사이에 모두 공백이 필요합니다.



간단하게 echo 로 이름을 묻고, name 변수에 read 해줍니다. 같은 방법으로 나이를 물은 뒤 age 변수에 read 하지요.


if 문의 기본 문법은 if [ 변수 test 대상 ] then 실행문 else 실행문 fi

이렇게 됩니다. if 로 시작하여 if 의 반대인 fi 로 끝을 내 줍니다. 비교 test 는 -lt (less than 보다 작다) 를 사용했는데요, 그외 다른 어떤 비교 test 들이 있는지는 확인 가능합니다.


여기서는 간단하게 18 세 이상이면 맥주를.. 이하면 안된다.. 라고 간단하게 출력합니다.


man test

혹은

man [


메뉴얼 내에 많은 내용이 있는데요 그중 몇개만 추려봤습니다.


       STRING1 = STRING2
              the strings are equal

       STRING1 != STRING2
              the strings are not equal

       INTEGER1 -eq INTEGER2
              INTEGER1 is equal to INTEGER2

       INTEGER1 -ge INTEGER2
              INTEGER1 is greater than or equal to INTEGER2

       INTEGER1 -gt INTEGER2
              INTEGER1 is greater than INTEGER2

       INTEGER1 -le INTEGER2
              INTEGER1 is less than or equal to INTEGER2

       INTEGER1 -lt INTEGER2
              INTEGER1 is less than INTEGER2

       INTEGER1 -ne INTEGER2
              INTEGER1 is not equal to INTEGER2


자.. 이렇게 만들어진 스크립트 테스트를 하면 결과는 다음과 같습니다.

항상 실행 전에 파일 접근 권한을 700 으로 사용자에게 읽기 쓰기 실행 권한을 부여합니다.




간단한 쉘 스크립트 내 if-else 사용법을 알아봤습니다. 


다음은 if-elif-else 예문입니다. 최간단 계산기.


1) 2개 의 argument 를 받습니다.

2) 계산법을 받습니다.

3) 계산을 출력합니다.


vim calc.sh



받을 argument 들은 $1, $2 로 받습니다.

$(($1+$2)) 로 계산 합니다.



결과입니다. 실행 시, argument 를 2개 넣어줍니다. 예에서는 8 과 9 로 실행하였습니다.

반응형
반응형

Shell Script 의 기본


bash-4.1$ x=3
bash-4.1$ echo $x
3


bash-4.1$ echo "hello     there"
hello     there

bash-4.1$ echo 'hello     there'
hello     there
bash-4.1$ echo hello      there
hello there


bash-4.1$ echo "the value of x:     $x"
the value of x:     3
bash-4.1$ echo 'the value of x:     $x'
the value of x:     $x
bash-4.1$ echo 'I have $10000'
I have $10000


bash-4.1$ echo Today is `date`
Today is Wed Aug 6 12:50:46 EST 2014
bash-4.1$ echo "Today is `date`"
Today is Wed Aug  6 12:51:00 EST 2014




permission

bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

bash-4.1$ chmod 600 a.txt
bash-4.1$ ls -l
total 2
-rw-------+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

bash-4.1$ chmod 644 a.txt
bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

first --- user (u)
second --- group (g)
third --- other (o)

0 000
1 001 * execute = 1
2 010 * write = 2
3 011
4 100 * read = 4
5 101
6 110
7 111

readable, writable, executable = 4+2+1 = 7 (rwx)

chmod 755 myfile
chmog o+x myfile
chmog o-x myfile



Script 실행


bash-4.1$ hello.sh
bash: hello.sh: command not found
bash-4.1$ pwd
/home/11776352/usp/2
bash-4.1$ /home/11776352/usp/2/hello.sh
hello world
bash-4.1$ cd ..
bash-4.1$ 2/hello.sh
hello world
bash-4.1$ cd 2/
bash-4.1$ ls
a.txt  c.txt  hello.sh    hello.txt
bash-4.1$ ../2/hello.sh
hello world
bash-4.1$ ./hello.sh
hello world


 Script 응용




반응형
반응형




vi - 엔하위키 미러 링크 합니다. vim 이 무엇인지 궁금하신 분들이나 역사 등을 원하시면 읽어보시면 좋습니다.


일단 초보자들이 vi를 처음 보고 가장 당황하는 것은 실행을 시켰는데 키보드가 먹히질 않는다는 점이다. 당황해서 막 누르다보면 또 어느 순간 입력이 되기 시작한 다. vi에는 일반 모드, 입력 모드, 명령 모드의 세 가지 모드가 존재하기 때문인데, 그걸 모르고 초심자가 vi로 뭔가 하려고 손댔다가 입력은 안 되지, 삭제도 안 되지, 갑자기 모드가 바뀌어서 입력이 되지, esc 눌러도 종료는 안 되지... 하는 상황 때문에 봉변을 당하는 경우가 많다. -- vi - 엔하위키 내용 중에서


vim editor..
/vim hello.txt

F11- full screen


vim 에디터는 대기모드, 입력모드, 명령어 모드 총 3가지 모드가 있습니다. 대기 모드는 말 그대로 대기모드이며, 대기모드에서 명령어 키 들을 입력하여 줄을 지운다던지, 단어를 지우거나, 입력모드 혹은 명령어 모드로 들어갑니다.


입력모드 활성화는 영문 키 i 를 눌러 시작합니다.

대기모드는 어떤 모드에서든지 esc 키를 눌러 활성화 시킵니다.

명령어 모드는 : 를 누른 뒤 원하는 명령어를 입력합니다.


i - input string (입력모드)
o - open a new line
a - append string
esc - normal mode (대기모드)

. - repeat previous command
u - undo

j - move down
k - move up
l - move right
h - move left
w - move to the next words
b - move back to the previous words

dd - deletes a whole line
5d - deletes 5 lines
p - put deleted lines.
yy - copy a whole line

dw - deletes a word
/ - activates command line
/current - searchs word "current"
shift -g : end of the file


: (명령어 모드)
:w - write a file
:q - to quit
:q!-  to quit without saving
:wq - to write and quit
:x - to write and quit
:qa - to quit all

멀티태스킹 ㅡ,.ㅡ;
ctrl-z - stopps the vim
jobs -  shows running application
fg - back to vim


반응형
반응형




제 기가바이트 넷북에 설치한 ubuntu 14.04 는 우분투 내 발전된 사용자 인터페이스로 인해 넷북에 설치된 비디오카드와 메모리 용량으로 소화하기 힘든 상태였습니다. 여러가지 설정을 바꿔가며 에니메이션도 줄이고, 비침효과도 없애보고 해보았지만 워낙 오래된 기가바이트 넷북이여서 그런지 여전히 버벅되더군요. 그래서 결정한게 Xubuntu 의 설치입니다. 아래 스크린샷 처럼 간단하면서 클래식한 인터페이스.. 참 좋아 보였습니다.

우분투 터미널에서 바로 설치하는 명령어 입니다.

1. Xubuntu install

sudo apt-get install xubuntu-desktop gksu leafpad synaptic


다운 받은 뒤 설치가 끝나면 바로 재시작을 하여 Xubuntu 로 들어갑니다. Xubuntu 데스크탑에서 좌상단 파란색 버튼 -> 악세사리 -> 터미널 에뮬레이터 를 실행하여 아래 명령어를 실행해 줍니다. 여러가지 쓸데 없는 내용들을 삭제 해주며 특히 unity 부분을 삭제 하는게 맘에 드네요 ㅋㅋ


2. clean up

sudo apt-get remove nautilus gnome-power-manager gnome-screensaver gnome-termina* gnome-pane* gnome-applet* gnome-bluetooth gnome-desktop* gnome-sessio* gnome-user* gnome-shell-common compiz compiz* unity unity* hud zeitgeist zeitgeist* python-zeitgeist libzeitgeist* activity-log-manager-common gnome-control-center gnome-screenshot overlay-scrollba* && sudo apt-get install xubuntu-community-wallpapers && sudo apt-get autoremove


이렇게 ubuntu 14.04 에서 Xubuntu 14.04 로 탈바꿈 되었습니다.

정말 가버워진 느낌이며 한정된 리소스의 사용이 잘 활용되는 느낌입니다.

원하는 작업을 하는데 속도 저하는 없네요. 인터넷 브라우징 과 구글독스 에서 문서 작업이 느리지 않아 무척 좋습니다.

반응형
반응형


유닉스 혹은 리눅스 기본 명령어 모음입니다. 모두 기본적인 파일 구조 명령어 들이라서 디렉토리(폴더) 만들어서 디렉토리 간 파일 이동, 삭제 등을 다룹니다.


유닉스나 리눅스에서는 프롬프트가 따로 친절히 경로를 표시해 주지 않아 마지막 부분에 프롬프트 변경 방식도 다뤄볼 예정입니다.


unix_tutorial_01.txt 파일의 내용은 아래와 같습니다.

Name: Ryan Heise
Email: ryan@ryanheise.com


터미널에서 명령어 연습을 한 로그를 모두 긁어 모은 형태 이므로 블록 글자들이 명령어고 바로 아래 내용들이 결과물입니다.


bash-4.1$ date
Wed Jul 30 12:25:57 EST 2014

bash-4.1$ echo hello
hello

bash-4.1$ cat /home/yobine/semester\ 2/Unix_tutorial/unix_tutorial_01.txt
Name: Ryan Heise
Email: rian@riunheise.com

bash-4.1$ cat /home/yobine/semester\ 2/Unix_tutorial/unix_tutorial_01.txt /home/yobine/semester\ 2/Unix_tutorial/unix_tutorial_01.txt
Name: Rian Heise
Email: rian@riunheise.com

Name: Rian Heise
Email: rian@riunheise.com

bash-4.1$ cd /home/yobine/semester\ 2/Unix_tutorial/
bash-4.1$ ls
unix_tutorial_01.txt

bash-4.1$ pwd
/home/yobine/semester 2/Unix_tutorial
bash-4.1$ cd
bash-4.1$ pwd
/home/yobine
bash-4.1$ cd ..
bash-4.1$ ls
yobine
bash-4.1$ pwd
/home
bash-4.1$ cd /
bash-4.1$ pwd
/

bash-4.1$ ls
bin   cgroup  etc   images  lib64    media  mnt  opt   pub    sbin     srv  tmp  var
boot  dev     home  lib     lost+found    misc   net  proc  root    selinux  sys  usr

bash-4.1$ whoami
yobine


bash-4.1$ cd /home/Heise
bash-4.1$ ls
ls: cannot open directory .: Permission denied

bash-4.1$ pwd
/home/Heise


bash-4.1$ cd /
bash-4.1$ ls
bin   cgroup  etc   images  lib64    media  mnt  opt   pub    sbin     srv  tmp  var
boot  dev     home  lib     lost+found    misc   net  proc  root    selinux  sys  usr
bash-4.1$ pwd
/
bash-4.1$ cd
bash-4.1$ pwd
/home/yobine
bash-4.1$ cd semester\ 2/Unix_tutorial/
bash-4.1$ ls
a.txt  b.txt  unix_tutorial_01.txt  unix_tutorial_01.txt~

bash-4.1$ groups
Students

bash-4.1$ ls -l
total 5
-rw-r--r--+ 1 yobine Students  44 Jul 30 12:13 a.txt
-rw-r--r--+ 1 yobine Students  44 Jul 30 12:13 b.txt
-rw-r--r--+ 1 yobine Students 918 Jul 30 12:40 unix_tutorial_01.txt
-rw-r--r--+ 1 yobine Students  44 Jul 30 12:13 unix_tutorial_01.txt~


bash-4.1$ ls -l /
total 108
dr-xr-xr-x.   2 root root  4096 Jun 23 12:39 bin
dr-xr-xr-x.   4 root root  4096 Feb 12 06:24 boot
drwxr-xr-x    2 root root  4096 Dec  3  2013 cgroup
drwxr-xr-x   19 root root  3860 Jul 30 10:17 dev
drwxr-xr-x. 131 root root 12288 Jul 30 12:41 etc
drwxr-xr-x    4 root root     0 Jul 30 12:41 home
drwxr-xr-x.  15 root root  4096 Jul 30 12:01 images
dr-xr-xr-x.  13 root root  4096 Jun 23 12:38 lib
dr-xr-xr-x.  10 root root 12288 Jun 23 12:38 lib64
drwx------.   2 root root 16384 Feb  6  2013 lost+found
drwxr-xr-x.   2 root root  4096 Jun  5 16:00 media
drwxr-xr-x    2 root root     0 Jul 30 10:17 misc
drwxr-xr-x.   2 root root  4096 Jun 29  2011 mnt
drwxr-xr-x    2 root root     0 Jul 30 10:17 net
drwxr-xr-x.  23 root root  4096 Jul 29 12:38 opt
dr-xr-xr-x  243 root root     0 Jul 30  2014 proc
drwxr-xr-x    2 root root     0 Jul 30 10:17 pub
drwx------.  10 root root  4096 Jul 16 12:06 root
dr-xr-xr-x.   2 root root 12288 Jun 23 12:38 sbin
drwxr-xr-x.   2 root root  4096 Feb  6  2013 selinux
drwxr-xr-x.   2 root root  4096 Jun 29  2011 srv
drwxr-xr-x   13 root root     0 Jul 30  2014 sys
drwxrwxrwt.  26 root root  4096 Jul 30 12:47 tmp
drwxr-xr-x.  16 root root  4096 Jul 22  2013 usr
drwxr-xr-x.  23 root root  4096 Jul 18 07:10 var

bash-4.1$ ls -l /home/yobine/semester\ 2/
total 2
drwxr-xr-x+ 2 yobine Students 6 Jul 30 12:45 Unix_tutorial

bash-4.1$ mkdir usp
bash-4.1$ ls
cnsql.sh  nasa2.sql~  newls.sh~   semester 2  usp       workspace
Desktop   new file~   semester 1  sql.sh~     vpworkspace

bash-4.1$ cd usp
bash-4.1$ ls
bash-4.1$ mkdir 1
bash-4.1$ mkdir 2 3 4 5 6 7
bash-4.1$ ls
1  2  3  4  5  6  7

bash-4.1$ pwd
/home/yobine/usp

bash-4.1$ cd 1
bash-4.1$ touch hello.txt
bash-4.1$ ls
hello.txt
bash-4.1$ touch a.txt b.txt c.txt

bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 a.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 b.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 c.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:54 hello.txt

bash-4.1$ touch hello.txt //creates file but also changes the modification date (update dates)

bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 a.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 b.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 c.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 hello.txt

bash-4.1$ cp a.txt mycopy.txt
bash-4.1$ ls -l
total 3
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 a.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 b.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 c.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 hello.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:59 mycopy.txt

//move files to other directories, but in the same directory, it changes the name of the file.
bash-4.1$ mv b.txt newname.txt
bash-4.1$ ls -l
total 3
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 a.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 c.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 hello.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:59 mycopy.txt
-rw-r--r--+ 1 yobine Students 0 Jul 30 12:56 newname.txt

bash-4.1$ mv newname.txt /home/yobine/newname.txt
bash-4.1$ mv newname.txt ../../newname.txt

bash-4.1$ cd ..
bash-4.1$ pwd
/home/yobine/usp


bash-4.1$ cd 1/../2/../../usp/1
bash-4.1$ pwd
/home/yobine/usp/1
bash-4.1$ ls
a.txt  c.txt  hello.txt  mycopy.txt  newname.txt

bash-4.1$ cp a.txt c.txt ../2
bash-4.1$ ls
a.txt  c.txt  hello.txt  mycopy.txt  newname.txt

bash-4.1$ ls ../2
a.txt  c.txt

bash-4.1$ cd ../2
bash-4.1$ pwd
/home/yobine/usp/2
bash-4.1$ ls
a.txt  c.txt

//to change the root prompt with a view,
//try man bash and search for PROMPTING (/PROMPTING)

반응형
반응형



참고 싸이트 (https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04)


우분투 14.04 에서 LAMP 를 설치해 봅니다.


1. 아파치 설치하기


sudo apt-get update
sudo apt-get install apache2


정상적으로 아파치가 설치되면 브라우저에서 확인 해봅니다.

http://your_server_IP_address
예)http://192.168.1.111

Ubuntu 14.04 Apache default


확인 하고나서 정상적으로 위의 페이지가 보인다면 아파치 설치는 성공입니다.

외부 아이피 설정이의나, 확인 방법은 다음에 다루기로 하고, 다음 단계로 진행합니다.


2. MySQL 설치하기


sudo apt-get install mysql-server php5-mysql


위의 명령어 실행 후 root user 암호 설정이 중간에 나옵니다. 설정해 주시면 됩니다.

설치가 완료 되면, 어디에 데이터를 넣어야 할지 알려줘야 합니다. 디렉토리 스트럭처 설치 명령어 입니다.


sudo mysql_install_db


이후, 보안 설치를 해줍니다.


sudo mysql_secure_installation


처음엔 NO 를 하여 root-user 암호 설정을 피합니다. 그 뒤론 엔터를 눌러 자동 설정을 진행합니다.


3. PHP 설치


sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt


위의 명령어를 실행하여 php 를 설치합니다. 그리고 나서 아래 아파치 설정 파일을 열어 줍니다.


sudo nano /etc/apache2/mods-enabled/dir.conf


<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>


열어보면 php 파일이 뒤에 있을텐데, 그 파일 이름을 맨 앞에 지정해 줍니다.


<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>


그리고 저장 하면 됩니다. Ctrl-X

저장 후 아파치 재시작 해줍니다.


sudo service apache2 restart


4. PHP 테스트 하기


설치가 완료 된 후 php 설치가 잘 되었는지 확인해 봅니다.


sudo nano /var/www/html/info.php


명령어를 치면 빈 파일이 만들어집니다. 이름은 info.php 파일입니다. 빈파일 안에 아래 php 명령어를 넣어 줍니다.


<?php
phpinfo();
?>


그런 뒤 브라우저에서 확인해 봅니다.


http://your_server_IP_address/info.php


화면이 잘 나오면 성공입니다.


Ubuntu 14.04 default PHP info


성공적으로 우분투 14.04 에서 LAMP 설정을 해봤습니다.


반응형
반응형


UIWebview 를 사용하여 iOS 앱 화면에 모바일웹 화면을 띄우는 방법은 간단합니다.

스토리 보드를 이용한 방법이 아래 링크에 잘 나와있습니다. 소스 코드만 봐도 간단하지요?

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    [self goToURL:@"https://mobile.twitter.com/waterstreetjr"];

}


// displays the URL

-(void)goToURL:(NSString*) fullURL{

    NSURL *url = [NSURL URLWithString:fullURL];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [_webView loadRequest:requestObj];

}


이렇게 UIWebview 를 만들고 나서...


1. 화면이 나오면 로딩이 끝날 때까지 흰색화면으로 남게 되는데요, 음.. 아래 그림처럼 로딩 이미지가 떠주면 어떨까 싶어서 추가해봤습니다.



#import <UIKit/UIKit.h>


@interface HomeViewController : UIViewController<UIWebViewDelegate>

{

     UIActivityIndicatorView* loadingIndicator;

}

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@property (strong, nonatomic) UIActivityIndicatorView *loadingIndicator;


-(void)goToURL:(NSString*) fullURL;

@end


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    [_webView setDelegate:self];

    [self addLoadingIndicatorToView];

    [self goToURL:@"https://mobile.twitter.com/waterstreetjr"];

}


// add loading indicator

-(void)addLoadingIndicatorToView{

    loadingIndicator= [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

    [loadingIndicator setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];

    [self.view addSubview:loadingIndicator];


}


// displays the URL

-(void)goToURL:(NSString*) fullURL{

    NSURL *url = [NSURL URLWithString:fullURL];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [_webView loadRequest:requestObj];

}


- (void)webViewDidStartLoad:(UIWebView *)webView{

    NSLog(@"webViewDidStartLoad");

    [loadingIndicator startAnimating];

}


- (void)webViewDidFinishLoad:(UIWebView *)webView{

    NSLog(@"webViewDidFinishLoad");

    [loadingIndicator stopAnimating];

}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{

    NSLog(@"didFailLoadWithError");

}


동작이 잘 되는 부분은 확인 해 봤습니다. 


2) 로딩 화면이 보이지 않고, 로딩이 끝난 후에 보여지면 어떨까 생각해봤습니다. 예를 들면 테이블 뷰가 나오고 그 중에서 다음 화면이 웹뷰인 셀이 있습니다. 눌렀을 시 UIwebview 로 넘어갈 때 로딩이 끝난뒤 넘어가게 할 수도 있습니다.



넘어가기 전 테이블 뷰에서 다음 화면인 웹 뷰로 가는 셀을 터치 했을 경우, pushViewController 를 부르기 전에, 웹뷰 를 미리 로딩을 할 수 있도록 합니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // check indexPath... myWebView = [[MyWebViewController alloc] init]; myWebView.delegate = self; [myWebView preLoadView]; }

웹뷰가 로딩이 끝나면 다음 화면으로 뷰가 넘어가게 됩니다.

- (void)webViewDidFinishLoad:(UIWebView *)webView { [self.navigationController pushViewController:myWebView animated:YES]; [myWebView release]; }

아직 테스트 된 코드는 아니지만, 실제 코드 적용 과 함께 테스트 후 영상을 올리도록 하겠습니다. 

반응형

+ Recent posts