bash 단축키 목록을 얻는 매뉴얼이 있습니까?


21

bash 명령 줄 과 상호 작용하는 동안 작업을보다 쉽고 빠르게하기 위해 사용하는 많은 단축키가 있습니다 .

처럼:

  • ctrl+ L: 화면을 지우려면
  • ctrl+ a/ ctrl+ e: 줄의 시작 / 끝을 이동
  • ctrl+ r: 문자를 거의 쓰지 않고 명령의 역사를 검색합니다.
  • ctrl+ u/ ctrl+ y: 줄을 잘라내거나 붙여 넣습니다.

그리고 더 많은 것을 알고 싶습니다. 배우고 싶은 것이 분명합니다.

우분투에서 이러한 단축키 목록을 어디서 얻을 수 있는지 알고 싶습니다. 이 단축키를 나열한 매뉴얼이 있습니까?

노트:

바로 가기 목록과 해당 작업을 한 곳에서 얻고 싶습니다. 짧은 시간 안에 많은 것을 배우는 것이 정말 도움이 될 것입니다. 우리가 이런 식으로 목록을 얻을 수있는 방법이 있습니까? 여기에 주어진 답변에 감사드립니다 ..

답변:


22

기본값은 man bash각 명령의 기능에 대한 세부 사항과 함께입니다. 키 바인딩을 변경 한 경우 BroSlow의 답변을 참조하십시오.

   Commands for Moving
       beginning-of-line (C-a)
              Move to the start of the current line.
       end-of-line (C-e)
              Move to the end of the line.
       forward-char (C-f)
              Move forward a character.
       backward-char (C-b)
              Move back a character.
       forward-word (M-f)
              Move forward to the end of the next word.  Words are composed of alphanumeric characters (letters and digits).
       backward-word (M-b)
              Move back to the start of the current or previous word.  Words are composed of alphanumeric characters (letters and digits).
       shell-forward-word
              Move forward to the end of the next word.  Words are delimited by non-quoted shell metacharacters.
       shell-backward-word
              Move back to the start of the current or previous word.  Words are delimited by non-quoted shell metacharacters.
       clear-screen (C-l)
              Clear the screen leaving the current line at the top of the screen.  With an argument, refresh the current line without clearing the screen.

...

       reverse-search-history (C-r)
              Search backward starting at the current line and moving `up' through the history as necessary.  This is an incremental search.

...

       unix-line-discard (C-u)
              Kill backward from point to the beginning of the line.  The killed text is saved on the kill-ring.

...

       yank (C-y)
          Yank the top of the kill ring into the buffer at point.

편집하다

이 명령은 모두 매뉴얼의 연속 섹션에 있으므로에서 찾아 볼 수 있습니다 Commands for Moving. 또는이 전체 섹션을 텍스트 파일로 저장할 수 있습니다.

man bash | awk '/^   Commands for Moving$/{print_this=1} /^   Programmable Completion$/{print_this=0} print_this==1{sub(/^   /,""); print}' > bash_commands.txt

(NB는 기본 키보드 단축키가없는 명령을 포함하여 전체 섹션을 인쇄합니다.)

Awk 코드 설명

  • 의 (만) 발생 Commands for Moving에서 변수 print_this를 1로 설정하십시오 .
  • Programmable Completion다음 섹션 인 (만) 발생 에서 변수를 0으로 설정하십시오.
  • 변수가 1이면 선행 공백 (세 공백)을 제거하고 행을 인쇄하십시오.

1
이것들은 기본 단축키이며, 반드시 OP의 실제 시스템의 단축키는 아닙니다. bind -P더 정확할 것입니다.

@BroSlow 좋은 의견. 그래도 명령에 대한 자세한 정보가 있기 때문에 여전히 대답에 장점이 있다고 생각합니다. 답으로 쓰면 +1하겠습니다.
— Sparhawk

@Sparhawk : 답을 +1하십시오. 한 곳에서 바로 가기 목록을 찾고 있습니다. bash 매뉴얼이 모든 지름길에 대해 말해 줄 수 있다면 , 여기에 대답 한 것처럼 어떻게 그것을 얻을 수 있습니까! 이 목록을 어떻게 얻었습니까? 동작을 사용하여 바로 가기를 구문 분석하고 다른 파일로 저장하는 방법이 있습니까? 답장을 기다리겠습니다.
— Saurav Kumar

bash 매뉴얼을 검색하면 Readline Command Names이 섹션에 모든 명령이 표시됩니다. 짧은 스크립트를 작성하여 텍스트 파일로 추출하지만 지금은 할 수 없습니다 (몇 시간 안에 시간이 걸릴 것입니다).
— Sparhawk

@Sparhawk : 당신의 대답은 간단한 grep 필터 명령을 작성하는 데 도움이되었습니다. 당신이 그것을 바랍니다 희망 여기를 확인하십시오 . 당신의 도움을 주셔서 감사합니다. 나는 당신의 대본을 기다리고 있지만 .. :)
— Saurav Kumar

20

당신은 bash는 내장 호출하여 현재 bash 쉘의 모든 바로 가기를 나열 할 수 있습니다 bind과 -P옵션을 선택합니다.

예 :

bind -P | grep clear
clear-screen can be found on "\C-l".

그것들을 바꾸려면 다음과 같은 일을 할 수 있습니다

 bind '\C-p:clear-screen'

그리고 그것을 영구 파일로 만들기 위해 init 파일에 넣으십시오 (한 번에 한 가지에만 키 조합을 바인딩 할 수 있으므로 이전에는 바인딩이 손실됩니다).


이름으로 검색하여 바로 가기 키를 얻는 것은 나에게는 드문 일이며 오랜 과정입니다. 한 곳에서 바로 가기 목록을 얻는 간단한 방법이 있습니까? 이해하시기 바랍니다. 이 접근 방식을 위해 +1 ..
— Saurav Kumar

2
@SauravKumar bind -P는 모든 단축키를 제공해야합니다. 바인드 / bind -P | grep -v "not bound"

7

다음 명령은 사용법과 단축키를 보여주는 멋진 열 출력을 제공합니다.

bind -P | grep "can be found" | sort | awk '{printf "%-40s", $1} {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}'

이것은 다음과 같은 출력을 제공합니다.

abort                                   "\C-g", "\C-x\C-g", "\e\C-g". 
accept-line                             "\C-j", "\C-m". 
backward-char                           "\C-b", "\eOD", "\e[D". 
backward-delete-char                    "\C-h", "\C-?". 
backward-kill-line                      "\C-x\C-?". 
backward-kill-word                      "\e\C-h", "\e\C-?". 
backward-word                           "\e\e[D", "\e[1;5D", "\e[5D", "\eb". 
beginning-of-history                    "\e<". 
beginning-of-line                       "\C-a", "\eOH", "\e[1~", "\e[H". 
call-last-kbd-macro                     "\C-xe". 
capitalize-word                         "\ec". 
character-search-backward               "\e\C-]". 
character-search                        "\C-]". 
clear-screen                            "\C-l". 
complete                                "\C-i", "\e\e". 
...

다음 명령을 사용하여이 출력을 텍스트 파일로 가져옵니다.

bind -P|grep "can be found"|sort | awk '{printf "%-40s", $1} {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}' > ~/shortcuts

파일은 $ HOME 디렉토리에 작성됩니다.

설명

  • 모든 지름길을 얻습니다.

    bind -P
  • 할당되지 않은 모든 단축키를 제거합니다

    grep "can be found"
  • 출력을 정렬합니다

    sort
  • 첫 번째 열 (예 : 함수)을 인쇄하고 텍스트를 정렬합니다

    awk '{printf "%-40s", $1}
  • 이것은 이전 명령의 일부입니다. 열 6+ (즉, 바로 가기)를 인쇄합니다.

    {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}'
  • 출력을 바로 가기 라는 홈 디렉토리의 멋진 텍스트 파일에 넣습니다.

    > shortcuts

다음 명령을 실행하여 명령의 작동 방식에 대한 아이디어를 얻을 수 있습니다.

bind -P
bind -P | grep "can be found"
bind -P | grep "can be found" | sort

@SauravKumar 답에 추가 할 내용이 있습니까?
— 등록 된 사용자

2
당신의 대답 +1과 좀 더 의미있게합니다 .. :) 내가 놓친 로 그리고 문장의 전체 의미를 변경) 아니 당신이 어떤 일을 추가 할 필요가 없습니다. 당신은 최선을 다했습니다 ..
— Saurav Kumar

+1 멋진 명령! 설정되지 않은 바로 가기를 포함하도록 확장했습니다.bind -P | tail -n +2 | sort | awk '{printf "%-40s", $1} {if ($6 == "any") {printf"\n"} else {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}}'
— wjandrea

1

bash manual 을 필터링하여 바로 가기 목록을 얻는 방법이 있습니다 . 또한 각 바로 가기가 정확히 무엇을 수행하는지에 대한 설명도 제공합니다. 덕분에 Sparhawk 해결책을 찾기 위해 저를 계몽. 내가 여전히 좋지는 않지만 정규 표현식 의 사용법을 배우는 것이 필요 했습니다. :)

한 줄 명령은 다음과 같습니다.

man bash | grep "(.-.*)$" -A1

다음은 출력의 작은 추출입니다.

   beginning-of-line (C-a)
          Move to the start of the current line.
   end-of-line (C-e)
          Move to the end of the line.
   forward-char (C-f)
          Move forward a character.
   backward-char (C-b)
          Move back a character.
   forward-word (M-f)
          Move forward to the end of the next word.  Words are composed of alphanumeric characters (letters and digits).
   backward-word (M-b)
          Move back to the start of the current or previous word.  Words are composed of alphanumeric characters (letters and digits).
   clear-screen (C-l)
          Clear the screen leaving the current line at the top of the screen.  With an argument, refresh the current line without clearing the
   previous-history (C-p)
          Fetch the previous command from the history list, moving back in the list.
   next-history (C-n)
          Fetch the next command from the history list, moving forward in the list.
   beginning-of-history (M-<)
          Move to the first line in the history.
   end-of-history (M->)
          Move to the end of the input history, i.e., the line currently being entered.
   reverse-search-history (C-r)
          Search backward starting at the current line and moving `up' through the history as necessary.  This is an incremental search.
   forward-search-history (C-s)
          Search forward starting at the current line and moving `down' through the history as necessary.  This is an incremental search.

이제 바로 가기를 파일에 저장하려면

man bash | grep "(.-.*)$" -A1 > bash_shortcuts

그게 내가 필요한 전부 야 방금 배쉬에 할당 된 바로 가기 키를 알고 싶었고 BroSlow로 키를 재구성하지 않았습니다. 요청한 .

그들의 모든 기여에 다시 한번 감사드립니다.

노트 :

누군가가 이것을 향상시키고 싶다면 가장 환영받습니다. 일부 키로 지정된 단축키를 나열하는 방법에 대해서만 언급했습니다. 따라서 누군가이 방법으로 설명이 할당되지 않은 작업을 나열하는 방법을 알고 있다면 가장 환영합니다. :)


아주 좋아요 그러나 유일한 문제는 여러 줄로 된 설명의 첫 번째 줄만 인쇄한다는 것입니다. 또한 기본 키 입력 (예 :)없이 헤더와 명령을 건너 뜁니다 dump-macros.
— Sparhawk

1

이 명령을 부적절하게 만드는 방법으로 bash 매뉴얼을 수정하지 않는 한 다음 명령은에 대한 모든 기본 단축키를 표시합니다 bash.

man bash | grep -A294 'Commands for Moving'

이것은 다음과 같은 출력을 제공합니다.

 Commands for Moving
   beginning-of-line (C-a)
          Move to the start of the current line.
   end-of-line (C-e)
          Move to the end of the line.
   forward-char (C-f)
          Move forward a character.
   backward-char (C-b)
          Move back a character.
   forward-word (M-f)
          Move forward to the end of the next word.  Words are composed of alphanumeric characters (letters and digits).
   backward-word (M-b)
          Move back to the start of the current or previous word.  Words are composed of alphanumeric characters (letters  and
          digits).
   shell-forward-word
          Move forward to the end of the next word.  Words are delimited by non-quoted shell metacharacters.
   shell-backward-word
          Move back to the start of the current or previous word.  Words are delimited by non-quoted shell metacharacters.
   clear-screen (C-l)
          Clear  the  screen  leaving  the  current line at the top of the screen.  With an argument, refresh the current line
          without clearing the screen.
   redraw-current-line
          Refresh the current line.

Commands for Manipulating the History
   accept-line (Newline, Return)
          Accept the line regardless of where the cursor is.  If this line is non-empty, add it to the history list  according
          to  the state of the HISTCONTROL variable.  If the line is a modified history line, then restore the history line to
          its original state.
   previous-history (C-p)
          Fetch the previous command from the history list, moving back in the list.
   next-history (C-n)
...

bash 매뉴얼을 수정하면이 명령을 필요에 맞게 쉽게 변경할 수 있습니다.


잘 했어 Patil !! 왜 이런 식으로 생각하지 않았다 .. :)
— Saurav Kumar

@Patil 줄 수를 하드 코딩하는 것에 대해서도 생각했지만 bash 매뉴얼의 섹션 순서가 변경되지 않고 명령 섹션의 줄 수가 변경되었을 가능성이 더 큽니다. 나는 아마 그럴 것 같지 않다는 것에 동의한다.
— Sparhawk
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.