아래 처럼 문자와 숫자가 섞여 있는 파일에 대해서 정렬이 제대로 되지 않을 때
When sorting is not done properly for files with mixed letters and numbers as shown below
[codehexa@codehexa test]$ ls -l
total 0
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t1
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t10
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t2
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t3
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t4
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t5
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t6
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t7
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t8
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t9
다음 sort 명령의 옵션을 통해 해결이 가능하다.
This can be resolved through the options of the following sort command.
[codehexa@codehexa test]$ ls -l | sort -V
total 0
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t1
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t2
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t3
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t4
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t5
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t6
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t7
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t8
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t9
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t10
역방향은 정렬은 r옵션을 추가하면 된다.
For the reverse direction, add the r option to sort.
[codehexa@codehexa test]$ ls -l | sort -Vr
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t10
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t9
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t8
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t7
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t6
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t5
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t4
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t3
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t2
-rw-rw-r-- 1 codehexa codehexa 0 Jun 28 14:34 t1
total 0