카테고리 없음

데이터 엔지니어(여섯번째 이야기)

CleanCoder 2021. 10. 7. 18:41

Introduction to Shell

 

pwd 명령어

 

ls 명령어

-R 옵션

-F 옵션

 

ls 절대경로

ls 상대경로

 

cd . 현재 디렉터리 (영향을 미치지 않음)

cd .. 한 단계 위 디렉터리로 이동

cd ~ 홈디렉터리 이동

 

cp 명령어

 

mv 명령어

 

rm 명령어

 

mkdir 명령어

 

cat 명령어

 

less 명령어

:n

:p

 

head 명령어

옵션 -n 5    5번째줄까지

 

tail 명령어

 

man tail +3

 

tail -n +7 seasonal/spring.csv

 

cut -f 2-5, 8 -d , value.csv

-f : fields

-d : delimiter

 

붙여서 사용해도 가능하다.

cut -d, -f1 value.csv

 

cut -d : -f 2-4

first:second:third: => second:third:

 

ex) !head, !cut

느낌표 뒤에 !head 또는 !cut과 같은 명령 이름을 입력하여 명령을 다시 실행할 수 있다.

이 명령의 가장 최근에 사용한 항목을 다시 실행할 수 있습니다.

 

history

최근에 사용했던 명령어 리스트를 보여줌

 

!head

grep 명령어

text에 포함된 단어들을 찾는다.

옵션

  • -c: print a count of matching lines rather than the lines themselves
  • -h: do not print the names of files when searching multiple files
  • -i: ignore case (e.g., treat "Regression" and "regression" as matches)
  • -l: print the names of files that contain matches, not the matches
  • -n: print line numbers for matching lines
  • -v: invert the match, i.e., only show lines that don't match

 

 

 > 로 winter.csv의 마지막 5개의 줄을 last.csv로 복사

 

| 파이프라인으로 명령어 조합 사용

 

두개의 파이프라인으로 세개의 명령어 조합 실행

 

wc 명령어

 

* 표현

 

sort 명령어

default 오름차순

-r 내림차순

 

uniq 명령어

유일한 값들만 추출

-> 매우 크고 중복된 값이 많은 파일에 적합

 

 

 

 

shell 변수 선언

출력 예제

 

for 문을 shell 내에서 사용

하나 더 해보기

 

변수 앞에 $를 빼먹으면 shell은 인식하지 못한다.

 

 

세미콜론의 차이에 따른 결과값의 변화

nano 명령어

  • Ctrl + K: delete a line.
  • Ctrl + U: un-delete a line.
  • Ctrl + O: save the file ('O' stands for 'output'). You will also need to press Enter to confirm the filename!
  • Ctrl + X: exit the editor.

bash 명령으로 program을 부를 수 있다.

 

특수 표현식 $@

"스크립트에 제공된 모든 명령줄 매개 변수"를 의미

 

$1 $2 와같이 숫자형식으로도 참조 가능

 

nano로 for문 shell 명령문 작성 (bash 이용하여 실행 가능)