리눅스 명령어 (to be continued ..)
● ls (-t: 수정시간 기준, -h: juman readable, -a: 숨긴폴더까지 보여줌, -l: show a detailed directory listing, -s: size 표시)
○ du 명령어 사용시 우리가 생각하는 실제 전체 파일들의 크기를 합한 값
○ 그냥 -s 명령어만 사용하면 그 폴더, 즉 바구니의 값만을 계산하여 알려줌
● pwd
● rm
● cd
● man
● --help
● whatis
● mv
● cp
● rm (-r)
● stat
● file
● cat
● touch
● chmod
● mkdir (-p)
● tree
● ln (-s)
○ ex) ln -s hello.txt h.txt
→ ln 은 두 파일 사이에서 링크를 만드는 명령어, s는 symbolic을 의미, hello.txt.는 target file로 내가 링크하고 싶은 파일을 의미, h.txt 는 내가 만들 심볼릭링크 파일의 이름을 의미
● ldd: (특정 실행파일을 기준으로) 사용하는 라이브러리 파일들을 출력
● zip / unzip
● gzip / gunzip
○ 현재 경로에 압축 파일을 따로 만들고 압축을 해제
○ -c: option to keep the original file is to use the -c option, which tells gzip to write on standard output and redirect the output to a file (형태: gzip -c filename > filename.gz)
● tar
○ -zxvf: gzip, create, verbose, file=archive
○ z: Compress the archive using gzip
○ c: Create a new archive
○ v: Verbosely list files processed
○ f cache.tar.gz: Specify the name of the archive file to create
○ -zxvf: gunzip, extract(get)
○ z: Decompress the archive using gzip
○ x: Extract files from the archive
○ v: Verbosely list files being extracted
○ f cache.tar.gz: Specify the name of the archive file to extract
* ex)
tar 명령어로 /var/cache 폴더에 및에 있는 파일들을 cache.tar 파일로 뭉쳐준다
근데 파일 크기를 확인해보니 크기가 달라지지 않음. 즉 zip이 이루어지지 않았음
z 옵션 추가로 압축완료
그리고 마지막으로 cache.tar.gz 아카이브를 current directory에 extract 한다
● >: 덮어씀
● >>: 다음줄에 이어서 씀
● find
○ -name 옵션은 뒤에 / 안되는 듯
○ 2>/dev/null 을 사용함으로써 에러메시지를 생략한다 (2번에 write 하는거라서)
○ 프로세스 task_struct → open 하는 파일 관리 → fd[0]=stdin, fd[1]=stdout, fd[2]=stderr
○ meaning: find 명령어로 /usr 디렉터리 아래에 있는 이름에 python이 들어간 directory를 찾으시오
○ 다양한 옵션들
○ b: block (buffered) special
○ c: character (unbuffered) special
○ d: directory
○ p: named pipe (FIFO)
○ f: regular file
○ l: symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.
○ s: socket
○ D: door (Solaris)
● locate
○ find 명령어보다 속도는 빠르지만 세부기능이 적다
○ 그리고 에러메시지를 내지 않는다
//find와 locate 명령어를 사용해 파일을 찾는 실습
● grep
: 특정 키워드로 필터링하기 (print lines matching a pattern)
○ install 이라는 키워드로 텍스트 파일 확인
○ 만약 i를 생략하고 nstall로 검색시 대소문자로 구분하여 검색결과를 보여줌
○ ssh를 키워드로 해서 모든 로그파일 내용을 전부 확인함
○ -r (recursive): Read all files under each directory
○ /var/log ⇒ 실무에서는 시스템이 갑자기 꺼지거나 프로그램의 오류나 문제, db 외부접속시도 흔적
○ grep -i "err" -r /var/log → 에러를 찾아봄
○ -i // --ignore-case: ignore case distinctions, so that characters that differ only in case match each other
● head / tail
: 로그 파일의 앞/뒤 끝 부분만 출력함
○ ps -ef | sc -l is used to count the number of currently running provesses on a Unix-like operating system. Here's a breakdown of the components and what they do
1) ps -ef
○ ps: Displays information about currently running processes
○ e: Selectes all processes, This option is the same as using A
○ f: Stands for "full-format listing", which provides a more detailed output including UID(use id), PID (process id), PPID (parent process id), C (CPU utilization), STIME(start time), TTY(terminal), TIME(cumulative CPU time), and CMD(command)
2) |: pipe
○ The pip operator takes the output of the command on its left and uses it as the input for the command on its right
3) wc -l
○ wc: Stands for "word count"
○ -l: Counts the number of lines in the input
○ This part of the command counts the number of lines in the output from the ps -ef command
● akw: 문자출력결과 부분내용
○ ls -l 출력결과 중에서 두번째 요소만 출력하기
○ F fs // --field-separation fs
○ Use fs for the input field separator (the value of the FS pre-defined variable)
○ Sets the field separator to a space(" "), meaning awk will treat each space-separated word as a field
○ {print $2}
○ Tells awk to print the second field of each line
- meaning: 위에 캡쳐한 사진이랑 같은 의미인데 얘는 3번째 요소만 출력해주는 것이다
● ag
: also known as "The Silver Searcher", is a powerful and fast comman-line search tool designed to search codebases. It is similar to grep but optimized for speed and designed to search through large code repositories
○ 형식: ag [option] PATTERN [PATH]
○ PATTERN: The pattern or string you want to search for
○ [PATH]: The directory or file where you want to perform the search. If not specified, ag will search in the current directory
ex) ag main /home/user/projects : To search for the term "main" in the /home/user/projects
ag -i error : To search for the term "error" in a case-insensitive manner
○ 옵션들
○ i: Ignore case distinctions in the patter
○ w: Match the whole word
○ n: Show line numbers
○ -python: Restrict the search to Python files
○ -search-zip: Search within compressed files
○ C NUM: Show NUM lines of context around each match
○ c: Print the count of matches
● getfacl: get file access control lists
● chmod
ex) chmod u + x 파일명
○bash 파일명 → bash 를 같이 사용하면 권한이 없어도 실행이 가능하다 ..
위의 두 캡쳐본은 같은거