How to repeat the first half of a command in terminal?

I am downloading multiple videos, the problem is that the clipboard has the link to the videos, because of this I can not Ctrl+C & Ctrl+V the command because I will lose the link.
Is there a way for the terminal to “save a command” and then “recall” that command (much like calculator memory keys) everytime I need to paste a new link in without the need of typing in an entire command nor pressing the up/down keys

Make an alias? Example for bash in your ~/.bashrc file you simply add alias xxx="commands here" so when you simply type xxx url in terminal it executes commands here url

3 Likes

I use yt-dlp for this… but I’m lazy to type that, so I abbreviated that as dl

So I can work in terminal if I like - if I’m in BBC Sounds, I’ll open a terminal and enter my Audio folder, mkdir (Program name) and then type ‘dl’ and middle click to paste the url. yt-dlp will grab an entire playlist… good for multipart dramas not available as podcasts:

The first time I used this was to get an entire walkthrough guide from the URL (Previously I’d do it one by one with ClipGrab).

Copy link, open terminal (F4 in dolphin works well) type ‘dl’ and click mousewheel.

Normal terminal edit .zshrc or .bashrc do 'alias yg=you-get ' or 'alias dl=yt-dlp '

Fish terminal abbr dl 'yt-dlp' and abbr yg 'you-get'

Another method.
Arrow up / down key lets you cycle through your last commands at the console. By that you can type once your command half in, press enter, then bring it back all time again with the up/down arrow key near the num block.

For me, pasting lines into the console only works with the mouse but not with ctrl+v.

1 Like

If using bash, there is a history file in your $HOME directory, .bash_history.

To search the history: ctrl- r and start typing the command.

The up-arrow and down-arrow will move through the history on the command line.

In bash (actually readline), the keyboard commands depend on whether you are using emacs or vi. emacs is the default mode.

To see which is set: set -o | grep -E '^(emacs|vi)'

ctrl-e will take you to the end of the command line.
ctrl-a will take you to the beginning of the command line.

ctrl-x ctrl-e is kind of neat. It invokes the editor in the environmental variable $EDITOR with the current command line, and when you exit, the command is executed. It is called, edit-and-execute-command (it’s last in the section).

To learn more

1 Like

Shift_Ctrl_V to paste in terminal… or middle mouse click.

2 Likes

If you like history, check out fish too… This for ‘yt’ to find my previous download commands:

Guys, besides your off topics about your methods to do things he never asked, he also specified he didn’t want to do that.

It was a four lines thread, come on.

Quite right.
Actually there’s another one that I forgot…
And it is strangely relevant… and works great if you’re using KDE - but can be adapted.

Step 1: Have a useful clipboard (I like CopyQ).
Step 2: F6 brings up shortcuts, select Show main window under mouse cursor and set a shortcut. I use Ctrl+Alt+C
Step 3: Hit menu, custom shortcuts>Edit>New>MouseGesture>SendKeyboardInput

Select ‘Action’ and paste Ctrl+Alt+C
Select ‘Trigger’ and draw a letter ‘C’ with the mouse.

Now, you can copy your URL from Youtube, or BBC, or whatever. It’s in the clipboard.

Copy a few if you like… They don’t get replaced, they’re all in the history.
Open your terminal, type dl and then grab your mouse and draw a C

I love the way drawing a C for clips will bring my clipboard history up next to my cursor…
Perfick!

I don’t understand your Reply. :confused:

I do not believe I was off-topic.

Sometimes different methods work for someone, but they have to first know they exist.

“save a command” and “recall” the command are functions of readline on the command line, and certainly command line history. I felt I could add “additional details” to this “solved” thread. Okay, OP mentioned up/down arrows, but in context I didn’t read it as applying to the history.

imho, why clutter up .bashrc when there are command line alternatives available. Maybe because I have been doing this for so long, that I’m always thinking about future maintenance and the value of time.

I hope @Juan64 found value in all the helpful replies they received. They all appeared on-topic to me.

Yeah knowledge :raised_hands:

To be honest, everyone really failed to read this…
So the best solution to this sentence would be…

Using a gesture or shortcut to pull up the clipboard history, not searching terminal history.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.