2

I have a CentOS 8 minimal install. There is no GUI. If I am on the console, say I have typed out a command, such as nice-command-with-switches-that-does-stuff that I am happy with. Now, I want to either to select all or part of this line that is on the console so that I can then vi script.sh and then to paste this information at a location that I want within the script.

Obviously, doing echo 'nice-command-with-switches-that-does-stuff' >> script.sh could work but only if I want the text at the end of the file (and that's not always the case).

Is there a generic way that I can selectively mark some text on the console where I am working and store it in a buffer/clipboard to use elsewhere (such as inside vim or nano or some other editor), and in the opposite direction, could I yank some text while inside vi that I could then keep until I am pluck outside of vi and then paste that onto the console?

2 Answers 2

2
  • You can select text on the screen and copy/paste it using mouse via the gpm service. I'm not sure if it's enabled by default, if it's not, dnf install gpm; systemctl enable gpm; systemctl start gpm.

  • Secondly you can use screen/tmux to copy any portion of the screen (including the scrollback history) and then paste anywhere you want.

Probably there are other methods but these two ones are the most obvious. Plain Linux text terminal is quite limited in terms of its abilities.

1

Plain Linux text terminal is quite limited in terms of its abilities.

Not true at all!

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 support for editing the cli is amazing if you bother to learn it. Good Luck!

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .