- 행, 단어 , 문자 수 확인
- [root@localhost home]# wc test //1 7 36 test
- [root@localhost home]# wc -l test ///1
- test [root@localhost home]# wc -w test ///7
- test [root@localhost home]# wc -c test
연속된 문자= 한 단어로 인식
[root@localhost home]# ps -aux | wc -l 257 /// 현재 진행 중 프로세스
cat f* > file7
[root@localhost dir1]# cp -b file2 file3 // 백업 후 CP
- rw-r--r--. 1 root root 5 1월 16 09:10 file3
- -rw-r--r--. 1 root root 2 1월 16 09:09 file3~
[root@localhost dir1]# cp -b -S .bak file2 file3
- rw-r--r--. 1 root root 5 1월 16 09:10 file3.bak
- 파일 내용 비교
- diff1c1,4 /// 행열 그리고 네 글자
- 1,2c1 /// 첫번째 행 두번째 단어
- diff [파일 1] [파일 2] // 비교 후 차이점 출력
- comm
- comm [파일1] [파일2] /// 들여쓰기로 차이 출력
- cmp [파일1] [파일2]
- [root@localhost dir1]# cmp file2 file22 cmp: EOF on file2 after byte 5, line 1
- 파일 분할
-
- split [옵션] [파일명]-ㅣ : 헹 수로 분할[root@localhost dir1]# split -l 10 -d passwd [생성 파일명][root@localhost dir1]# rm -rf .0-a : 확장자 자릿수 지정
- [root@localhost dir1]# split -l 4 -d -a 4 --additional-suffix=.txt passwd /// 확장자 지정
- [root@localhost dir1]# split -l 10 -d -a 4 passwd /// 4→ 0001.0002.0003.0004
- -d : 숫자로 파일명 생성
- -C: 바이트 수로 분할
- [root@localhost dir1]# split -l 10 passwd /// 10줄로 4개 파일 생성 36줄 파일
-
- 문자열 추출
- grep [옵션] [문자열] [파일명] ///
- i : 대소문자 무시
- [root@localhost dir1]# systemctl restart httpd
- [root@localhost ~]# grep -n -v [login] passwd//// 해당 단어 제외 출력
- [root@localhost ~]# grep -n [root]$ passwd // root로 끝나는 단어 출력
- [root@localhost dir1]# cat passwd | grep -E "root$|bash$" //// 끝나는 단어
- [root@localhost dir1]# cat passwd | e grep "^root|^bash"
- [root@localhost dir1]# cat passwd | grep -E "^root|^bash" // 시작하는 단어
- [root@localhost dir1]# cat passwd | grep -E "root|user|login” //// 3개 모두 포함된 행 출력
- [root@localhost ~]# grep -n ^[root] passwd /// 문장 자체가 root로 시작하는 단어 출력
- [root@localhost ~]# grep -n -w [login] passwd /// 해당 언어만 출력 가능 다른 단어 접합 시 출력 불가
- [root@localhost dir1]# dnf -y install httpd
- [root@localhost dir1]# grep -n -i 'root' passwd // root 행수까지 확인 가능
- grep [옵션] [문자열] [파일명] ///
- 문자추출
- cut [옵션] [설정값] [ 파일명]
- [root@localhost dir1]# cut -c 1 passwd // passwd파일의 모든 행의 첫글자만 출력
- [root@localhost dir1]# cut -c 1-3 1,3 passwd // 모든 행의 첫글자,세번째 글자 출력
- [root@localhost dir1]# cut -f passwd // tab으로 필드 구분
- [root@localhost dir1]# cut -f 1 -d : or , passwd /// -d 구분자를 두면 구분 가능
- [root@localhost dir1]# cut -f 1 file
- linux,windows,unix
- linux
- linux
- CUT
- [root@localhost dir1]# cut -f 1 -d, file
- -d , /// 쉼표가 구분자로 구분자 해당 단어 제외 출력
- -d d///
- 구분자 제외한 해당 필드 문자 출력
- 구분자는 모든 문자 가능하나 단일 문자
- [root@localhost dir1]# touch .file7 // 숨김 파일 // 삭제 불가 // 지정 삭제만 가능
- [root@localhost dir1]# ls -al // 출력
- [root@localhost dir1]# ls -lS // 크기순
- [root@localhost dir1]# ls -ld // 디렉토리 정보 출력 drwxr-xr-x. 7 root root 166 1월 16 12:07 .
- [root@localhost dir1]# ls -Fl // 실행파일 별표 출력 , 디렉토리 심볼릭 링크 표시
- [root@localhost dir1]# ls -R // 디렉토리 내 하위 디렉 정보 출력
- [root@localhost dir1]# ls -lh // 휴먼 옵션
- [root@localhost dir1]# ls -Al // dir . .. 미출력
- AWK
- awk [옵션] [설정값] [파일명]
- [root@localhost dir1]# awk -F : '{print $1}' passwd
- [root@localhost dir1]# awk -F i '{print $1,$2}' file /// -F 구분자 ‘{print 필드 }’ [파일명]
- [root@localhost dir1]# cat filee
- linux,windows,unix
- linux,windows,unix
- [root@localhost dir1]# awk -F , '{print $1 }' filee /// -F 구분자 : , (쉼표)
- linux
- linux
'IT 엔지니어 > Linux server' 카테고리의 다른 글
리눅스 그룹 사용자 (0) | 2025.02.09 |
---|---|
리눅스 quota (1) | 2025.02.08 |
리눅스 서버 디스크 관리 (0) | 2025.02.02 |
리눅스 서버 프로세스 관리 (0) | 2025.02.01 |
리눅스 서버 sort (0) | 2025.01.30 |