728x90
우분투에서 bash 자동 완성 사용하는 방법
기본적으로 Ubuntu에는 bash 자동 완성이 설치되어 있지만, 사용자 정의 자동 완성 스크립트를 추가하여 기능을 확장할 수 있습니다.
bash-completion 패키지 설치
bash-completion은 Bash 셸에서 자동 완성 기능을 제공하는 패키지입니다.
$ apt info bash-completion
Package: bash-completion
Version: 1:2.11-5ubuntu1
Priority: standard
Section: shells
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Gabriel F. T. Gomes <gabriel@inconstante.net.br>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1,499 kB
Provides: dh-sequence-bash-completion
Homepage: https://github.com/scop/bash-completion
Task: standard
Download-Size: 180 kB
APT-Manual-Installed: no
APT-Sources: https://mirror.kakao.com/ubuntu jammy/main amd64 Packages
Description: programmable completion for the bash shell
bash completion extends bash's standard completion behavior to achieve
complex command lines with just a few keystrokes. This project was
conceived to produce programmable completion routines for the most
common Linux/UNIX commands, reducing the amount of typing sysadmins
and programmers need to do on a daily basis.
sudo apt-get -y update
sudo apt-get install -y bash-completion
활성화
일반적으로 bash-completion은 설치될 때 자동으로 활성화됩니다.
활성화되지 않은 경우 /etc/bash_completion 파일을 소스 또는 .bashrc 파일에서 소스하면 됩니다.
source /usr/share/bash-completion/bash_completion
이제 Bash에서 명령어, 옵션, 파일 및 디렉토리 이름 등을 자동으로 완성할 수 있습니다.
예를 들어
1. .bashrc 파일에 다음 줄을 추가하여 활성화할 수 있습니다.
vim ~/.bashrc
[[ -r /etc/bash_completion ]] && . /etc/bash_completion
(또는)
echo 'source <(source /etc/profile.d/bash_completion.sh)' >> ~/.bashrc
2. cd 명령어 뒤에 디렉토리 이름을 입력하고 키를 누르면 가능한 모든 디렉토리 이름이 자동으로 완성됩니다.
자동 완성 기능이 작동하지 않는 경우, 시스템 설정 파일이 제대로 구성되어 있는지 확인하고 bash-completion 패키지를 최신 버전으로 업데이트했는지 확인합니다.
참고URL
- CentOS 7에서 bash 자동 완성 사용하기 : https://sangchul.kr/78
728x90
'리눅스' 카테고리의 다른 글
우분투에서 텔레포트(teleport)를 설치하는 방법(2) (0) | 2023.04.25 |
---|---|
[리눅스] git branch 명령어 (0) | 2023.04.24 |
[리눅스] Ansible을 초기 구성하는 방법 (0) | 2023.04.21 |
[리눅스] 우분투에서 Ansible을 설치하는 방법 (0) | 2023.04.21 |
2TB 이상의 디스크를 사용하기 위한 방법(GPT 파티션을 설정하는 방법) (0) | 2023.04.21 |