디스크 공간을 확인해 보겠습니다.du -s
[root@iz2ze9wve43n2nyuvmsfx5z /]# du -s /* | sort -k 1|sed "/du/d"
du: cannot access ‘/proc/31265/task/31265/fd/4’: No such file or directory
du: cannot access ‘/proc/31265/task/31265/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/31265/fd/4’: No such file or directory
du: cannot access ‘/proc/31265/fdinfo/4’: No such file or directory
0 /bin
0 /dev
0 /lib
0 /lib64
0 /proc
0 /sbin
0 /sys
158784 /boot
16 /lost+found
2458148 /usr
37500 /etc
496 /run
4 /home
4 /media
4 /mnt
4 /opt
4 /srv
534680 /root
568 /tmp
935544 /var
그래서 나는 다음을 포함하는 줄을 제거하기 시작했습니다.du
1. sed "/du/d"
[root@iz2ze9wve43n2nyuvmsfx5z /]# du -s /* | sort |sed "/du/d" | head -n 6
du: cannot access ‘/proc/31563/task/31563/fd/4’: No such file or directory
du: cannot access ‘/proc/31563/task/31563/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/31563/fd/4’: No such file or directory
du: cannot access ‘/proc/31563/fdinfo/4’: No such file or directory
0 /bin
0 /dev
0 /lib
0 /lib64
0 /proc
0 /sbin
2. 숫자로 시작하지 않는 줄 삭제sed "/[^\d]*/d"
[root@iz2ze9wve43n2nyuvmsfx5z /]# du -s /* | sort -k 1|sed "/[^\d]*/d" | head -n 6
du: cannot access ‘/proc/31612/task/31612/fd/4’: No such file or directory
du: cannot access ‘/proc/31612/task/31612/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/31612/fd/4’: No such file or directory
du: cannot access ‘/proc/31612/fdinfo/4’: No such file or directory
but return the lines I want to delete
3. sed "/\d*/d"
[root@iz2ze9wve43n2nyuvmsfx5z /]# du -s /* | sort -k 1|sed "/\d*/d" | head -n 6
du: cannot access ‘/proc/31703/task/31703/fd/4’: No such file or directory
du: cannot access ‘/proc/31703/task/31703/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/31703/fd/4’: No such file or directory
du: cannot access ‘/proc/31703/fdinfo/4’: No such file or directory
"du"가 포함된 줄을 삭제하는 방법은 무엇입니까?
답변1
du: cannot access ...
Steeldriver가 언급했듯이 시작하고 끝나는 줄은 :No such file or directory
du의 오류 메시지입니다. /proc에 이러한 디렉터리를 열거하지만 "디스크" 공간을 합산하기 전에 해당 프로세스가 du
종료됩니다. 지금은 존재하지 않습니다.
다행히 du
이러한 오류는 stderr로 전송되므로 다음을 사용하여 오류를 차단하고 삭제할 수 있습니다.
du -s /* 2>/dev/null | sort -n
sort
또한 끝에 가장 큰 크기를 사용하여 숫자순으로 정렬한다고 가정하도록 명령을 변경했습니다 .