Benutzer-Werkzeuge

Webseiten-Werkzeuge


pc:bashtricks

Bash Eingabe Tricks

FIXME Erstmal nur zusammenkopiert1), muß noch übersetzt werden

Working With Processes

Use the following shortcuts to manage running processes.

  • Ctrl+C: Interrupt (kill) the current foreground process running in in the terminal. This sends the SIGINT signal to the process, which is technically just a request—most processes will honor it, but some may ignore it.
  • Ctrl+Z: Suspend the current foreground process running in bash. This sends the SIGTSTP signal to the process. To return the process to the foreground later, use the fg process_name command.
  • Ctrl+D: Close the bash shell. This sends an EOF (End-of-file) marker to bash, and bash exits when it receives this marker. This is similar to running the exit command.

Controlling the Screen

The following shortcuts allow you to control what appears on the screen.

  • Ctrl+L: Clear the screen. This is similar to running the “clear” command.
  • Ctrl+S: Stop all output to the screen. This is particularly useful when running commands with a lot of long, verbose output, but you don’t want to stop the command itself with Ctrl+C.
  • Ctrl+Q: Resume output to the screen after stopping it with Ctrl+S.

Moving the Cursor

Use the following shortcuts to quickly move the cursor around the current line while typing a command.

  • Ctrl+A or Home: Go to the beginning of the line.
  • Ctrl+E or End: Go to the end of the line.
  • Alt+B: Go left (back) one word.
  • Ctrl+B: Go left (back) one character.
  • Alt+F: Go right (forward) one word.
  • Ctrl+F: Go right (forward) one character.
  • Ctrl+XX: Move between the beginning of the line and the current position of the cursor. This allows you to press Ctrl+XX to return to the start of the line, change something, and then press Ctrl+XX to go back to your original cursor position. To use this shortcut, hold the Ctrl key and tap the X key twice.

Deleting Text

Use the following shortcuts to quickly delete characters:

  • Ctrl+D or Delete: Delete the character under the cursor.
  • Alt+D: Delete all characters after the cursor on the current line.
  • Ctrl+H or Backspace: Delete the character before the cursor.

Fixing Typos

These shortcuts allow you to fix typos and undo your key presses.

  • Alt+T: Swap the current word with the previous word.
  • Ctrl+T: Swap the last two characters before the cursor with each other. You can use this to quickly fix typos when you type two characters in the wrong order.
  • Ctrl+_: Undo your last key press. You can repeat this to undo multiple times.

Cutting and Pasting

Bash includes some basic cut-and-paste features.

  • Ctrl+W: Cut the word before the cursor, adding it to the clipboard.
  • Ctrl+K: Cut the part of the line after the cursor, adding it to the clipboard.
  • Ctrl+U: Cut the part of the line before the cursor, adding it to the clipboard.
  • Ctrl+Y: Paste the last thing you cut from the clipboard. The y here stands for “yank”.

Capitalizing Characters

The bash shell can quickly convert characters to upper or lower case:

  • Alt+U: Capitalize every character from the cursor to the end of the current word, converting the characters to upper case.
  • Alt+L: Uncapitalize every character from the cursor to the end of the current word, converting the characters to lower case.
  • Alt+C: Capitalize the character under the cursor. Your cursor will move to the end of the current word.

mit Strg+R wird die History Funktion aufgerufen.

Dann einfach den Befehl ausschreiben, der gesucht wird und je weiter geschrieben wird, um so genauer nähert mann sich der Befehlszeile, die gesucht wird.

Enter startet die Befehlszeile !

ESC schreibt die Befehlszeile in das Terminal, OHNE es auszuführen !

Einen Tick besser geht das noch, wenn der Befehl eingegeben wird und mit Cursor nach oben & Cursor nach unten, die History des Befehls durchsucht wird. Dies geschieht mit folgender Einstellung in der Datei .inputrc im /home Verzeichnis

(Entweder die Datei editieren oder neu anlegen mit nano ~/.inputrc)

folgende Zeilen einfügen
"\e[A": history-search-backward
"\e[B": history-search-forward

Event Designators, Word Designators und Modifier

Eingabe Funktion
!?abc das erste Kommando in der History suchen, das abc enthält
!abc das erste Kommando in der History suchen, das mit abc beginnt
!! zuletzt aufgerufener Befehl
!^ erster Parameter im vorherigen Befehl
!* alle Parameter im vorherigen Befehl
!$ letzter Parameter im vorherigen Befehl
!n Befehl an Position n in der History
!-n I-n Befehl, der an der n-ten Stelle von hinten in der History steht
:2 Nur der zweite Parameter des Befehls
:2-5 der zweite bis fünfte Parameter des Befehls
:2-$ der zweite und alle weiteren Parameter des Befehls
:* Sämtliche Parameter des Befehls
den Befehl nur ausgeben
:h in einer Pfadangabe das Ende abschneiden
:t das Ende einer Pfadangabe (zum Beispiel der Dateiname)
:r alles hinter dem letzten Punkt abschneiden (zum Beispiel die Dateiendung)
:e alles hinter dem letzten Punkt (zum Beispiel die Dateiendung)
:q den Text in Anführungsstriche setzen
pc/bashtricks.txt · Zuletzt geändert: 2020/12/28 12:52 von admin