귀하의 결과가 일치하지 않는 당신의 명령을 사용하면 질문에 쓴 결과를 정말로 신뢰하지 않습니다. 특히/LOG /는 결과에서 제외됩니다.
sudo -i ls -ld /var/folx*
ls: /var/folx*: No such file or directory
AIX에는 sudo 명령이 없기 때문에 어떤 sudo를 사용하는지 알 수 없습니다. 하지만 제 맥에서 man 페이지를 사용하고 있습니다.
-i [command]
The -i (simulate initial login) option runs the shell
specified in the passwd(5) entry of the target user as a
login shell. This means that login-specific resource files
such as .profile or .login will be read by the shell. If a
command is specified, it is passed to the shell for
execution. Otherwise, an interactive shell is executed.
sudo attempts to change to that user's home directory
before running the shell. It also initializes the
environment, leaving DISPLAY and TERM unchanged, setting
HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as well as the
contents of /etc/environment on Linux and AIX systems. All
other environment variables are removed.
"해당 사용자의 홈 디렉토리로 변경"이라는 문구에 유의하십시오. 커맨드가 주어 지더라도 CD가 집에있는 것처럼 보입니다.
sudo pwd
/private/tmp
sudo -i pwd
/private/var/root
다음은 이러한 유형의 상황을 직접 디버깅하는 몇 가지 방법입니다. 먼저 명령을 env
으로 바꾸고 두 개의 개별 파일로 출력을 캡처 한 다음 비교해보십시오. 차이점이 문제의 근원인지 확인하십시오. 둘째, pwd
과 마찬가지로 sudo 컨텍스트에서 현재 작업 디렉토리가 변경되고 있음을 발견했습니다. 이 경우에는 적용되지 않지만 다른 경우에는을 명령으로 사용하는 세 번째 항목입니다. 이 경우에는 단서를 얻었지만 여전히 혼란 스러웠을 수도 있습니다.
다른 부분은 -i가 .profile과 .login을 빨아 들이고 있다는 것입니다. 많은 사용자가 다양한 것을 가정하여 .profile과 .login 파일을 작성합니다. 따라서 가끔 수행해야하는 다른 항목은 .profile의 맨 위에 set -x
을 넣으면 수행중인 작업을 확인할 수 있습니다. 이 경우에는 필요하지 않았습니다.