본문 바로가기

IT 개발 프로그래밍/Linux

The Linux Command Line ch1~ch10 명령어 정리, 실행



The Linux Command Line 책의 ch1~ch10 까지의 명령어를 정리, 실행해 보았다. 




ch1 Shell

date, cal, df, free, exit





date 


입력한 때의 날짜와 시간을 나타내는 명령어




 




cal 


달력 보여줌



  



df 


디스크의 사용가능한 공간 얼마나 있는지 알려줌








Free 



메모리 사용 가능 한 부분 알려줌


 





exit 


서버를 빠져나가는 명령어







ch2&3 Navigation & Exploring

pwd, cd, ls, file, less






pwd 


현재 디렉토리 보여줌






cd 


위치를 옮기는 명령어



 루트 로 옮겨감






ls 


현재 위치에 어떤 파일들이 있는지 보여줌





 



file 


지정된 file의 file type을 확인함.

file [OPTION...] [FILE...]







less

less는 more처럼 파일이나 표준 인쇄를 조절하는 유틸리티다. 하지만 more와 다르게 위쪽으로 스크롤 할 수 있고, 화면에 표시하기 전에 파일의 내용을 모두 읽어들이지 않는다. vi 스타일의 갖가지 명령을 가진 강력한 텍스트 제어 도구다.

-i   파일을 열어 문자열을 검색할 때 영문 대소문자를      구분하지 않는다.

-s   빈 줄이 여러 줄이면 하나로 줄여서 표시한다



여기서 q누르면 나가짐.




ch4 file&directories and ch5 Manipulating And Directories.

cp, mv, mkdir, rm, ln





cp


copy files and directories




cp -r dir1/ dir2/

디렉토리 전체를 복사하기 위해서는 -r 옵션을 사용한다. (recursive)

첫 번째 인자의 자리에 파일명을 여러 개 지정할 수 있다. 이 때 두 번째 인자는 반드시 디렉터리여야만 한다. 이 경우에선 마지막에 지정한 디렉터리로 앞서 지정한 파일들이 모두 복사된다.

예를 들어

cp a.dat b.dat c.dat temp[enter]

여기서는 a,b,c는 파일이고 temp[enter]는 디렉토리이다.






mv


move의 약자로서 파일을 이동시키거나 이름을 바꿀 때 쓴다.







mkdir


폴더를 만들 때 사용






rm 


파일 삭제할 때 사용






ln [op] <sourcename> [destname]

링크를 만드는 명령어

링크에는 symbolic link 와 hard link가 있음

symbolic link는 윈도우의 바로가기 같은 거, hard link는 원래 파일의 데이터에 대한 또다른 접근

default 로 hard link를 만들고 symbolic link를 만들기 위해서는 optional 명령어로서 -s를 써줘야함


1.) symbolic link 만들기

ln -s hello kello

hello 의 바로가기 kello를 만들어줌



ls -al로 확인



2.) hard link 만들기



ln star1.c ktar1.c 해도됨


http://www.myservlab.com/64


https://m.blog.naver.com/PostView.nhn?blogId=bbaroo27&logNo=100183904833&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F


참고





ch6 Working With Commands.

type, which, man, apropos, info, whatis, allias




type


지정된 명령어가 쉘에 내장된 명령어인지, 외부명령어인지, alias 명령어인지 등을 확인하는 명령어이다







which


which는 특정명령어의 위치를 찾아주는 명령어이다.




man


--help 와 마찬가지로d 각종 명령어, 프로그램의 사용법을 확인할 수 있는 명령어.




apropos


관련된 명령어 찾기




info


명령어에 대한 정보, 사용법을 알려줌



whatis


The whatis program displays the name and a one line description of a man page matching a specified keyword







alias


command를 직접 만들 수 있는 명령어



cd .. 이후에 ls -al 을 하는 명령어 foo를 만들었다.





7 Redirection.

cat, sort, uniq, grep, wc, head, tail, tee




리다이렉션은 표준 스트림(standard stream)의 흐름을 바꿔줍니다. > < 기호를 사용한다.


basically, command로 실행되는 process는 standard input stream, standard output stream, standard error stream을 가지고 있다. 그러므로 총 하나의 입력스트림과 두 개의 출력 스트림을 가지고 있는 것이다. 이 모든 스트림은 일반적인 문자열로 console에출력하게 되어 있다.




ls의 출력 결과를 ls.txt에 생성했고 /home/u21400507 디렉토리에 ls.txt파일이 생성되었다.


ls.txt를 출력한 결과



cat


Concatenate





sort


Write sorted concatenation of all FILE(s) to standard output.





uniq


Filter adjacent matching lines from INPUT (or standard input),

writing to OUTPUT (or standard output).






grep


Search for PATTERN in each FILE or standard input.

PATTERN is, by default, a basic regular expression (BRE).

Example: grep pattern [file...]




wc


The wc (word count) command is used to display the number of lines, words, and bytes contained in files. 






head


The head command prints the first ten lines of a file and the tail command prints the last ten lines. By default, both commands print ten lines of text, but this can be adjusted with the “-n” option:






tail


Usage: tail [OPTION]... [FILE]...

Print the last 10 lines of each FILE to standard output.

With more than one FILE, precede each with a header giving the file name.





tee


표준출력(stdout)을 화면과 파일로 동시에 출력하는 명령어


파이프로 ls -al 내용을 df파일 인자로 보냄

그리고 df라는 파일이 만들어지고 ls -al 내용이 df에 담김




ch8 Seeing The World As The Shell Sees It.

echo


echo

echo는 주어진 문자열을, 문자열 사이에 포함된 공백과 줄 마지막에 개행문자를 포함하여 표즌 출력으로 출력하는 명령어이다


사용법

echo [옵션]... [문자열]...






ch 9 advanced keyboard tricks

clear history




clear

clear the screen




history

display the contents of the history list



tee로 history가 출력하는 내용을 history.txt에 넣은다음 grep으로 git 명령어만 출력해냈다.





ch10 Permission


id, chmod, umask, su, sudo, chown chgrp passwd




id

Display user identity





chmod

Change a file's mode





umask

Set the default file permissions


POSIX 환경에서 사용할 수 있는 명령어이자 함수로서 현재 프로세스가 생성할 파일과 디렉토리의 퍼미션을 정한다. 이 값은 자식 프로세스에게도 계승된다.


이 명령어에서는 퍼미션과 마찬가지로 8진수를 사용합니다. 파일일 경우 666, 디렉토리일 경우 777에서 umask를 뺀 값이 현재 프로세스가 생성하는 파일과 디렉토리의 퍼미션이 됩니다. 예를 들어 파일을 생성할 때 기본으로 적용되는 퍼미션을 664(rw-rw-r--)으로 하고 싶다면 umask 명령어의 인자로 002를 사용해야 합니다.




참고

http://www.myservlab.com/171




su (switch user)


Run a shell as another user

현재 계정을 로그아웃을 하지 않고 다른 계정으로 전환하는 명령어


실행하기 전 root 사용자의 암호를 물어봄





sudo


Execute a command as another user


한시적으로 개별 사용자가 root 계정 자체가 아니라 관리자 권한을 얻을 수 있게 함

현재 계정에서 root 권한을 이용하여 명령어를 실행할 때 사용

실행하기 전 현재 사용자의 비밀번호를 물어봄




chown

Change a file's owner






chgrp (change group ownership)

파일의 사용자 그룹을 변경




passwd


Changing password