본문 바로가기

IT 엔지니어/Linux server

리눅스 서버 sort

[root@localhost dir1]#  fallocate

944 fallocate -l 10M file10 945 fallocate -l 100M file100 946 fallocate -l 1G file11g

 

[root@localhost dir1]# sort passwd // passwd라는 파일 내용을 기본 알파벳 정렬

[root@localhost dir1]# sort file | nl // file 이라는 파일을 넘버링 한다

[root@localhost dir1]# sort -k 1 file // -k : 필드로 분류 하겠다 [1] : 첫번째 필드

a d b

b a d 

c c a

d b c

 

세로 첫번째 열만 정렬된다

기본값이 빈칸으로 되어 분류된다

 

sort -t [,] : 구분자 표시 명령어

[root@localhost dir1]# sort -t, -k 2 file /// 두번 째 필드만 정렬된다

쉼표를 구분자로 필드 구분되어진다.

 

[root@localhost dir1]# rm -rf [d-f]* /// [d-f] : d에서 f 까지의 범위의  디렉,파일 상관없이 삭제 가능

[root@localhost dir1]# rm -rf [abcd]* // 해당 문자 삭제 가능

[root@localhost dir1]# ls

e f g h i j k l m

[root@localhost dir1]# rm -rf [^ace]* [!ace]*// ace 해당 문자 제외 후 삭제

[root@localhost dir1]# ls

a c e

[root@localhost dir1]# rm -rf [^1-3] /// 1, 3만 제외 후 모두 삭제

 

 

> 파일명 변경

rename [바꿀 범위] [변경 파일명] [원본 파일명]

rename [file] [ f ] [ f * ] /// [ file ]이라는 문자를 가진 파일명을 [ f ] 로  수정할건데,  f로 시작하는 파일 모두 변경해줘.

rename [file] [ f ] [ file1 ] //// [변경희망문자인 file]이며, file1이라는 파일만 f 로 변경

rename [변경 문자] [변경 희망 파일명] [원본 파일명] /// [! file ] : file 제외 [ 1-5 ] : 1-5 범위

 

> pipe //  추가 명령 가능 

rm -f ` ls * | grep -v file1.txt ` /// 숫자1 옆 ` ~ //// file1.txt 파일을 보이지 않은 상태로 모든 목록 보여준 상태에서 모두 지워줘

file1 제외한 리스트 목록 중 나머지 삭제

 

> find 후 -exec로 추가 명령 가능

[root@localhost dir1]# find /home/dir1 -name "*.txt"-exec rm -rf {} \; // - exec ls -l {} \;

{} : find 후 적합 대상

 

 

> 파일찾기

find [경로] [옵션] [설정값]

[root@localhost dir1]# find / -name [passwd ]-type [d] or[ f] /// passwd라는 이름을 가진 디렉터리 (d) 유형 의 파일 찾아줘

[root@localhost dir1]# find /home/dir1 -type f -size -100k // 파일 (f) 유형의 /home/dir1에 있는 사이즈 100k미만의 파일 찾아줘

 

-type : 유형

-name : 파일명

-size:+/- 100K 범위 설정 시 -size +100k -size - 1M

-exec : (외부) 명령어 실행

 

 

> stat 파일 정보 확인 명령어

 

[root@localhost dir1]# stat PASSwd

 

Access: 2025-01-30 15:41:24.685987920 +0900

Modify: 2025-01-30 15:41:20.869935658 +0900

Change: 2025-01-30 15:51:25.589217761 +0900

 

[root@localhost dir1]# touch -t 2501170000 PASSwd

 

Access: 2025-01-17 00:00:00.000000000 +0900

Modify: 2025-01-17 00:00:00.000000000 +0900 /// 시간 변경

Change: 2025-01-30 15:58:37.891139522 +0900

 

[root@localhost dir1]# find /home -atime +1 /home/dir1/PASSwd

 /home/dir1/PASSwd  / 해당 시간 파일 확인 가능

 

[root@localhost dir1]# find /home -mtime -1 /home/dir1/PASSwd

 - 수정시간 변경으로 -목록 확인 불가

 

-atime :접근시간(*24)

-mtime:수정시간(*24)

-ctime: 모드변경시간(*24)

 

그제- 어제 - 오늘

     +1  / - 1 

-1 = 해당 명령 실행한 해당 날짜로부터 24시간 이전

+1 = 어제로부터 24시간 이전의 모든 과거

 

시스템에게 미래는 없다

 

오늘 기준으로 1월 30일

-atime -1 /// 30일 기준 24시간 이전까지 생성한 시간

즉 29일 22시부터 30일 22시까지 생성한 파일 확인 가능

-atime +1 // 27일 기준 24시간 넘은 기간

즉, 29일 22시 이전(21:59분이후의 과거)부터 모든 과거까지 생성한 파일 확인 가능

 

 

bash

 

/etc/shells

[root@localhost dir1]# chsh -l /bin/sh /bin/bash

 

[root@localhost etc]# chsh Changing shell for root. New shell [/bin/sh]: /bin/bash Shell changed.

 

[root@localhost etc]# head -5 passwd root:x:0:0:root:/root:/bin/bash

 

 

 

  1. chsh [옵션]
  2. -ㅣ: 정의된 셸 목록 확인

 

  1. 셸 횐경 설정 파일~/.bashrc →환경 설정 파일에서 설정 하면 영구 설정
  2. vi /etc/bashrc /// vi 편집기 진입 후 43번째 \d \t 작성
    1. \d 날짜
    2. \t 24시 \T 12시 \@ 오전 오후
    3. \w 절대경로 \W 최종 경로
  3. 프롬프트 환경변경
  4. alias = 1 ‘ls -l’
  5. alias - 내부 명령어\
  6. /etc/bashrc → 전체 사용자 환경설정

 

'IT 엔지니어 > Linux server' 카테고리의 다른 글

리눅스 서버  (1) 2025.02.03
리눅스 서버 디스크 관리  (0) 2025.02.02
리눅스 서버 프로세스 관리  (0) 2025.02.01
Linux 기본 명령어  (1) 2025.01.29
Linux 서버 설치 방법  (0) 2025.01.27