내 작업 중에 bashrc에 지속적으로 별칭 명령을 추가해야하며 이러한 명령의 대부분은 다른 사용자가 실행해야합니다. 외부 소스에서 bashrc에 별칭 명령을 추가 할 수있는 방법이 있습니까?
내 작업 중에 bashrc에 지속적으로 별칭 명령을 추가해야하며 이러한 명령의 대부분은 다른 사용자가 실행해야합니다. 외부 소스에서 bashrc에 별칭 명령을 추가 할 수있는 방법이 있습니까?
답변:
사용자 홈 디렉토리에있는 많은 설정 파일은 사용자 홈에있는 /etc김프 설정이있는 시스템 설정 보다 파일을 덮어 쓰거나 ~/.gimp-2.*추가합니다 /etc/gimp/2.0.
따라서 ~/.bashrc시스템 전체 구성 파일 /etc/bash.bashrc (기능 / 별칭 ) 또는 /etc/profile (환경 관련 사항)을 편집 할 수 있습니다 man bash.
FILES
/bin/bash
The bash executable
/etc/profile
The systemwide initialization file, executed for login shells
/etc/bash.bash_logout
The systemwide login shell cleanup file, executed when a login shell exits
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
Individual readline initialization file
이 경고는 파일의 일부 Linux 시스템에 대해 제공됩니다.
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
따라서 해당 파일을 편집 할 수 있으며 먼저 백업 ( cp /etc/bash.bashrc /etc/bash.bashrc-backup예 :)하거나 셸 스크립트를 /etc/profile.d생성 할 수 있습니다. 예를 들어 sudo / root를 사용하여 다음 명령으로 파일을 생성 할 수 있습니다.
touch /etc/profile.d/custom.sh
chmod +x /etc/profile.d/custom.sh
그런 다음 nano /etc/profile.d/custom.sh
#!/bin/sh
alias ls='ls -lah'
그리고 출력에 나타나는지 확인하여 작동하는지 확인하십시오 alias-변경 사항을 보려면 로그 아웃 / 로그인 또는 재부팅해야 할 수도 있습니다 (원치 않는 경우 source /etc/profile변경 후 작동 할 수 있음)
[편집 :이 데드 링크 제거] www.thelinuxdaily.com/2010/08/setup-a-universal-user-profile-with-etcprofile-dcustom-sh/]
~/.bash_logout및 /etc/bash.bash_logout작동하지 않습니다. :(
/etc/profile.d/것 없는 하위 프로세스를 오른쪽으로 뽑힐? 따라서 별칭은 Bash가 로그인 쉘인 경우에만 사용할 수 있습니까?
로 이동 /etc/bash.bashrc
vim /etc/bash.bashrc
거기에 별명을 만드십시오.
마지막 줄에 별칭을 추가하십시오.
alias abc = "무엇이든"
이 별칭은 모든 사용자에게 전역이됩니다.
그러나 보안상의 이유로 권장하지 않습니다.
이 profile.d사용자 환경 파일이 들어있는 디렉토리
가다
cd /etc/profile.d/
vim 별칭
여기에 별명을 추가하십시오.
시스템 파일에 영향을 미치지 않습니다. 환경 파일로 작업하는 것이 안전하고 올바른 방법입니다.
여기에는 이미 받아 들여진 대답이 있지만 /etc/profile.d 등의 파일을 엉망으로 만드는 것이 아니라 시스템 전체의 사용자 환경 구성을 처리하기 위해 일부 형태의 환경 모듈을 사용하는 것을 고려할 수 있습니다. 많은 쉘에서이 컨트롤을 한 곳에서 관리합니다. Lmod (매우 활발한 개발 중), C / TCL 모듈 (클래식 솔루션) 또는 Cmod (경량).
저는 Linux operativ 시스템을 처음 접했지만 시스템 파일 /etc/.bashrc 파일이 아닌 모든 사용자 .bashrc 파일을 수정하는 bash 스크립트를 스케치했습니다.
#!/bin/bash
X=$( cat etc/passwd | cut -f1 -d: ) #All-users
For X in /home/*/.bashrc ; do
echo "alias ls='ls -al'" >> $X
2>/dev/null
done
source $X
exit 0
좋아, 나는 그 스크립트가 작동한다는 것을 알고 있지만, 결함이 없다면 :) 주문을 받아서 만드는.
.bashrc파일을 가지고 있어야하며 행이 이미 파일에 있는지 여부에 관계없이 항상 추가됩니다.
/etc/skel/.bashrc의 내용을 변경하기 위해 편집 할 수 있습니다~/.bashrc.