仅控制台环境中 CentOS 缓冲区/剪贴板的使用

仅控制台环境中 CentOS 缓冲区/剪贴板的使用

我有 CentOS 8 最小安装。没有图形用户界面。如果我在控制台上,假设我已经输入了一条命令,例如nice-command-with-switches-that-does-stuff我满意的命令。现在,我想选择控制台上的该行的全部或部分,以便我可以vi script.sh将此信息粘贴到脚本中我想要的位置。

显然,做echo 'nice-command-with-switches-that-does-stuff' >> script.sh可以工作,但前提是我想要文件末尾的文本(但情况并非总是如此)。

有没有一种通用的方法可以让我有选择地在我正在工作的控制台上标记一些文本并将其存储在缓冲区/剪贴板中以在其他地方使用(例如在内部vimnano其他编辑器中),并且在相反的方向上,我可以猛拉vi 内部的一些文本,然后我可以保留这些文本,直到我在 vi 外部提取然后将其粘贴到控制台上?

答案1

  • 您可以选择屏幕上的文本,然后通过 gpm 服务使用鼠标复制/粘贴它。我不确定它是否默认启用,如果不是,dnf install gpm; systemctl enable gpm; systemctl start gpm.

  • 其次,您可以使用screen/tmux复制屏幕的任何部分(包括回滚历史记录),然后粘贴到您想要的任何位置。

可能还有其他方法,但这两种方法是最明显的。纯 Linux 文本终端的功能非常有限。

答案2

纯 Linux 文本终端的功能非常有限。

根本不是真的!

Linux Bash Terminal Keyboard Shortcuts
Shortcut            Action

Bash Navigation
Ctrl + A            Move to the start of the command line
Ctrl + E            Move to the end of the command line
Ctrl + F            Move one character forward
Ctrl + B            Move one character backward
Ctrl + XX           Switch cursor position between start of the command
                    line and the current position
Ctrl + ] + x        Moves the cursor forward to next occurrence of x
Alt + F             Moves the cursor one word forward
Alt + B             Moves the cursor one word backward
Alt + Ctrl + ] + x  Moves cursor to the previous occurrence of x

Bash Control/Process
Ctrl + L    Similar to clear command, clears the terminal screen
Ctrl + S    Stops command output to the screen
Ctrl + Z    Suspends current command execution and moves it to the background
Ctrl + Q    Resumes suspended command
Ctrl + C    Sends SIGI signal and kills currently executing command
Ctrl + D    Closes the current terminal

Bash History
Ctrl + R    Incremental reverse search of bash history
Alt + P     Non-incremental reverse search of bash history
Ctrl + J    Ends history search at current command
Ctrl + _    Undo previous command
Ctrl + P    Moves to previous command
Ctrl + N    Moves to next command
Ctrl + S    Gets the next most recent command
Ctrl + O    Runs and re-enters the command found via Ctrl + S and Ctrl + R
Ctrl + G    Exits history search mode
!!          Runs last command
!*          Runs previous command except its first word
!*:p        Displays what !* substitutes
!x          Runs recent command in the bash history that begins with x
!x:p        Displays the x command and adds it as the recent command in
            history
!$          Same as OPTION+., brings forth last argument of the previous
            command
!^          Substitutes first argument of last command in the current
            command
!$:p        Displays the word that !$ substitutes
^123^abc    Replaces 123 with abc
!n:m        Repeats argument within a range (i.e, m 2-3)
!fi         Repeats latest command in history that begins with fi
!n          Run nth command from the bash history
!n:p        Prints the command !n executes
!n:$        Repeat arguments from the last command (i.e, from argument 
            n to $)

Bash Editing
Ctrl + U        Deletes before the cursor until the start of the command
Ctrl + K        Deletes after the cursor until the end of the command
Ctrl + W        Removes the command/argument before the cursor
Ctrl + D        Removes the character under the cursor
Ctrl + H        Removes character before the cursor
Alt + D         Removes from the character until the end of the word
Alt + Backspace Removes from the character until the start of the word
Alt + .         Uses last argument of previous command
Alt + <         Moves to the first line of the bash history
Alt + >         Moves to the last line of the bash history
Esc + T         Switch between last two words before cursor
Alt + T         Switches current word with the previous

Bash Information
TAB         Autocompletes the command or file/directory name
~TAB TAB    List all Linux users
Ctrl + I    Completes the command like TAB
Alt + ?     Display files/folders in the current path for help
Alt + *     Display files/folders in the current path as parameter

如果您愿意学习的话,Linux 对编辑 cli 的支持是令人惊奇的。祝你好运!

相关内容