소개
이 프로젝트에서는 /etc 디렉토리에서 내용에 문자열 "labex"를 포함하는 파일을 검색하고, 출력을 특정 형식으로 정리하는 방법을 배우게 됩니다.
👀 미리보기
/etc/group
/etc/gshadow
/etc/passwd
/etc/security/limits.conf
/etc/shadow
/etc/subgid
/etc/subuid
/etc/supervisor/conf.d/vnc.conf
/etc/supervisor/conf.d/webide.conf
/etc/supervisor/conf.d/ttyd.conf
/etc/supervisor/supervisord.conf
/etc/shiyanlou/sbin/init.sh
/etc/shiyanlou/services/ttyd.conf
/etc/shiyanlou/services/vncserver.conf
/etc/shiyanlou/services/webide.conf
/etc/group-
/etc/gshadow-
/etc/passwd-
/etc/shadow-
/etc/sudoers.d/labex
/etc/labex_source/init.sh
/etc/labex_source/novnc/dist/main.bundle.js
/etc/labex_source/supervisord.conf
/etc/labex_source/tmux.conf
/etc/labex_source/ttyd.conf
/etc/labex_source/vnc.conf
/etc/labex_source/webide.conf
🎯 과제
이 프로젝트에서 다음을 배우게 됩니다:
grep명령어를 사용하여 파일에서 특정 문자열을 검색하는 방법- 검색 출력에서 중복 항목을 제거하는 방법
- 출력을 깔끔하고 읽기 쉬운 형식으로 정리하는 방법
🏆 성과
이 프로젝트를 완료하면 다음을 수행할 수 있습니다:
- 내용에 따라 파일을 효율적으로 검색
- 검색 출력을 조작하고 정리
- 이러한 기술을 다양한 파일 검색 및 정리 작업에 적용
labex 를 포함하는 파일 검색
이 단계에서는 /etc 디렉토리에서 내용에 문자열 "labex"를 포함하는 모든 파일을 검색하고 각 파일의 전체 경로를 출력하는 방법을 배우게 됩니다.
- 터미널을 열고
/home/labex/project디렉토리로 이동합니다:
cd /home/labex/project
grep명령어를 사용하여/etc디렉토리 내의 모든 파일에서 문자열 "labex"를 검색하고 각 일치하는 파일의 전체 경로를 출력합니다:
sudo grep -rsl "labex" /etc > output
설명:
sudo: 슈퍼유저 (root) 권한으로 명령을 실행합니다./etc디렉토리에 접근하는 데 필요합니다.grep: 텍스트 파일에서 패턴을 검색하는 데 사용되는 명령어입니다.-r: 지정된 경로의 모든 하위 디렉토리를 재귀적으로 검색합니다.-s: 오류 메시지를 억제하고 파일 이름만 출력합니다.-l: 일치하는 줄이 아닌 파일 이름만 출력합니다."labex": 파일 내용에서 검색할 문자열입니다./etc: 검색할 디렉토리입니다.> output: 출력을 현재 디렉토리의output파일로 리디렉션합니다.
output파일의 내용을 확인합니다:
cat /home/labex/project/output
이렇게 하면 /etc 디렉토리에서 내용에 문자열 "labex"를 포함하는 모든 파일의 전체 경로가 표시됩니다.
/etc/group
/etc/gshadow
/etc/passwd
/etc/security/limits.conf
/etc/shadow
/etc/subgid
/etc/subuid
/etc/supervisor/conf.d/vnc.conf
/etc/supervisor/conf.d/webide.conf
/etc/supervisor/conf.d/ttyd.conf
/etc/supervisor/supervisord.conf
/etc/shiyanlou/sbin/init.sh
/etc/shiyanlou/services/ttyd.conf
/etc/shiyanlou/services/vncserver.conf
/etc/shiyanlou/services/webide.conf
/etc/group-
/etc/gshadow-
/etc/passwd-
/etc/shadow-
/etc/sudoers.d/labex
/etc/labex_source/init.sh
/etc/labex_source/novnc/dist/main.bundle.js
/etc/labex_source/supervisord.conf
/etc/labex_source/tmux.conf
/etc/labex_source/ttyd.conf
/etc/labex_source/vnc.conf
/etc/labex_source/webide.conf
출력 결과 확인
이 마지막 단계에서는 output 파일이 올바르게 생성되었고 예상되는 파일 경로를 포함하는지 확인합니다.
/home/labex/project/output파일을 열고 내용을 검토합니다. 다음을 확인하십시오:- 각 줄은 고유한 파일 경로를 나타냅니다.
- 모든 파일 경로는
/etc디렉토리 내에 있으며 내용에 문자열 "labex"를 포함합니다.
출력이 올바르게 보이면 프로젝트를 성공적으로 완료한 것입니다!
축하합니다. 내용에 따라 특정 파일을 검색하고 원하는 형식으로 출력을 정리하는 방법을 배웠습니다.
요약
축하합니다! 이 프로젝트를 완료했습니다. LabEx 에서 더 많은 랩을 연습하여 기술을 향상시킬 수 있습니다.



