반응형


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




반응형
반응형

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


반응형
반응형


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


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


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)

반응형

+ Recent posts