Spyke
lemmy.world

What the fuck!? How am I only learning this now, after years of linux as daily driver?!

57
ch00freply
lemmy.world

Shit is usually a pain in the ass. The challenge is divining how much of a pain in the ass something has to be that someone else might have made a solution for it.

I didn't know you could ctrl+shift+c to copy in the terminal until a month ago when my linux n00b wife said "there has to be a better way to do this. I've been right clicking to copy for 10 years.

42
Neverclearreply
lemmy.dbzer0.com

most DE's have a thing where you can paste highlighted text using the middle mouse button

26

It's also known as mouse 3 if you need to find it on your mouse or want to bind it to something else.

9
lemmy.world

I think that's just an x11 thing that might have been carried over to Wayland or at least works on Hyprland.

1
HorreCreply
lemmy.world

you can also just use ctrl + insert for copy and shift + insert for paste.

6
JackbyDevreply
programming.dev

I used to have shift insert in my muscle memory from Windows, but since my job has used a Mac since 2020 it's fallen out. I never knew Ctrl insert was copy, that's nifty! Another tool in the arsenal. It will be useful when copy in select isn't set and I don't know how to set it up lol.

3

I have always used ctrl/shift insert, I never got used to ctrl c/v. Glad you have new tools!

1
Anebreply
lemmy.world

Ctrl+c to copy, Ctrl+v to paste, Ctrl+z to undo last change (chain it multiple times to reverse time) hopes this helps, ctrl+tab also changes applications on macos and Linux to my knowledge. If you know anymore let's put them together

-6
ch00freply
lemmy.world

You're getting downvotes because Ctrl+C doesn't work in the terminal. That sends the kill command to the currently running application. You need the shift to tell the terminal program that you're trying to copy.

3
Anebreply
lemmy.world

I use cmd+c cmd+v in my terminal all they time, I do get ctlr+c is the shutdown command. I use a it frequently. I honestly had no clue I was being down voted but I don't care

0
grrgylereply
slrpnk.net

Congratulations! I remember where I was when I first learned it (in a noisy server room at the back of a machine shop).

Now pair it with FZF for fuzzy finding -- it's surprisingly easy to set up, just following any guide. It's insanely useful. I find myself even doing things like typing:

$ xinput --disable $(xinput --list | grep -i touchpad | grep 'id=[0-9]\+' -o | cut -d= -f2)  # Disable synaptic touchpad trackpad pointer

commands with these like comments on the ends as sort of "tags" so I can ctrl+r search for them later. Yes, I know I could just use a named function, but this is like the step just before that--before I know if I'll be issuing the same command all the time, or just for the next couple weeks. (This one was from when I was resting my notebook on my laptop.)

11

I like this; I have a lot of commands that I don't use often enough to justify an alias, but still need to rerun all the time. thanks!

5

As usual, that's documented (we can RTFM).

Before trying ctrl-s, you may want to disable software flow control: run stty -ixon & add it to your initialization files. Otherwise, you'll pause terminal output. ctrl-q resumes terminal output.

stty reveals terminal special characters

$ stty -a
⁝
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; …
⁝

These special characters/keys often perform special functions. To illustrate

  • ctrl-d on empty input typically exits/logs out of interactive terminal applications (including shells)
  • ctrl-u discards input (useful for inputs like password prompts that don't echo input back)
  • ctrl-v inputs next character literally (such as tab)
8
Davereply
lemmy.nz

Just checking, because I learnt to type before I worked this out, and because surely someone reading doesn't know: press tab. Bash will fill in file names from your current directory.

E.g. say you have files fred1file, fred2file, jim.

Type f then press tab, it will fill to "fred". Then press 2 and press tab again and it will fill the full "fred2file".

Have a play, it works in heaps of situations.

6

Bash will also do autocomplete for cli programs that have autocomplete functionality. Try typing:

git r<tab><tab>

you'll see options for all the git commands that start with r. Often cli commands will have autocompletion for long (double dash) options.

If you want to see all the commands that have auto complete available, look in:

/usr/share/bash-completion/completions/

There's a few other locations they can live, notably:

/etc/bash_completion.d/ ~/.bash_completion ~/.local/share/bash-completion/completions/

I don't know if there are more or if there is any variation per distro.

You can also write your own bash completions. They can get pretty smart and context sensitive.

Pretty good beginning tutorial:

https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial

edit - I should've mentioned that this isn't native to bash, it requires installation of bash-completion. But bash-completion is installed by default in many distros.

2
Cenzorrllreply
lemmy.world

I'm not going to say how long I used linux before learning this. It isn't "this many days old", but it may as well be.

I have 7 headless linux boxes running.

12
Damagereply
feddit.it

Even quicker with zsh or atuin: write the first few letters then arrow up to cycle through all matches

8
Epherareply
lemmy.ml

Even quicker with fish: Write the first few letters then it auto-suggests the last-run command matching that prefix (and then you can still arrow up to cycle through all matches).

(There is also a zsh plugin for that, called zsh-autosuggestions.)

8
Cethinreply
lemmy.zip

A lot of stuff assumes Bash, so occasionally when the syntax differs its slightly annoying; sometimes you have to modify a few lines of a file or something (or run it as in Bash manually). Fish is so nice though. It really should replace Bash for almost everyone. If you really need Bash you can still use it.

2
Epherareply
lemmy.ml

With script files, you can (and should regardless of Fish usage) put a shebang at the top, like #!/bin/sh or #!/bin/bash. Then it will run with Bash as you'd expect.

I also recommend not setting Fish as your system-wide default shell (since then a missing shebang will cause it to run in Fish), but rather just have your terminal emulator start fish by default.

And yeah, outside of scripting, if I notice a command requires Bash syntax (which you can often tell from Fish's syntax highlighting turning red), then I just run bash, execute the Bash command in there and then exit back out of there.

Having said all that, I'm not trying to take away from your point. If I wasn't just joking around, I would caveat a Fish recommendation just as much.

5

Yeah, it's just some scripts that come with programs sometimes not including that is the issue. Like I said, it isn't a big issue, just occasionally requires small edits if you try to run the script in Fish, or, like you said, running them with Bash.

2
bdonvrreply
thelemmy.club

I main ZSH and I've been CTRL+R'ing for years damn here I am a fool

2
Jankatarchreply
lemmy.world

I like to imagine someone added it in for their own personal use and told nobody because surely they are the only one.

3

I'm shocked how far I had to scroll down before it was mentioned, I was getting scared I would have to say it lol

1
NotNotMikereply
programming.dev

I love this one but is the gif moving at 0.5 frames a second or is it just me

4

For me, it looks normal (about 8 frames a second, probably).

8

Normal for me. Thanks for pointing out it was a gif. I never realize they're gifs because I have to "open in external" for them to actually move.

3
thelemmy.club

I used to be like this but people seriously. CTRL+R

Do it. Don't make this one of those things you've heard about and just never got around to trying. Open your terminal right now and CTRL+R and type any part of the command you did before. If the command you want is not showing first just hit CTRL+R again to go to the next one back.

DO IT.

Edit: I did learn from this thread today though that ZSH has it set to where you can just type part of what you're looking for then hit up to do the same thing. Neat!

72

You can empower Ctrl+r event more by using fzf. After I started using it, I can't imagine going back to without it.

19

WHAT THE FUCJ IS THIS SORCERY BRO I'VE BEEN USING LINUX FOR AGES AND NEVER KNEW THIS BROOOOOOOOOO

19

Holy shit. I just tried it. ctrl+r is a revelation! How the fuck did I not know about this?

19

Edit: I did learn from this thread today though that ZSH has it set to where you can just type part of what you’re looking for then hit up to do the same thing. Neat!

Fish too, it's fantastic.

8

This changed my life when I discovered it. Also using ag as alternative to ack.

FZF Vim plugin is also gold!

1
mercreply
sh.itjust.works

The worst is when you remember doing something before, but don't remember enough details to be able to effectively search for it.

Although, even then, I'm not going to just mindlessly hit "up". Last time it happened I fed my command history through grep and removed all the things that I knew the command wasn't. Just removing "ls" and "cd" from your history cuts the number of commands down by 80% or something.

1
Korthrunreply
lemmy.sdf.org

Check out the fzf shell bindings. Reverse history search with fuzzy matching is one of the features.

4

That doesn't help when you remember what effect the command had but nothing about what the command itself looked like.

1
lemmy.ca

Ctrl + R and start typing the command, it'll come up, press enter. Im just more lazy because I know there are still faster ways.

Edit: instead of hitting enter, keep pressing ctrl + R to cycle through history commands that contain what you typed in

28

Note: if the above isn’t working, you may need to first set your shell to accept emacs commands:

set -o emacs
4

Pretty much, yeah.

Rather than jot down in a text file the various ffmpeg commands I use frequently...

Raktajino@laptop:~/Downloads$ history | grep ffmpeg
   12  sudo apt install audacity gimp ffmpeg mplayer
  184  history | grep ffmpeg
  215  ffmpeg -i source.mkv -ss 629 -t 7 out.mkv
  217  ffmpeg -i out.mkv -s 0.5 -vf scale=1280:720 out.mp4
  218  ffmpeg -i out.mkv -ss 0.5 -vf scale=1280:720 out.mp4
  231  ffmpeg -i out.mp4 -vf "subtitles=out.srt" final.mp4
  503  ffmpeg -i toofat.wav toofat.mp3
  ...
  682  history | grep ffmpeg
  684  ffmpeg -i 1.gif -i 2.gif -filter_complex "[1:0] [2:0] concat=n=2" out.gif
  685  ffmpeg -i 1.gif -i 2.gif -filter_complex "[1:0] [2:0] concat=n=2:v=1" out.gif
  686  ffmpeg -i 1.gif -i 2.gif -filter_complex "[1:0] [2:0] concat=n=2:v=1" -map '[v]' out.gif
  687  history | grep ffmpeg
  688  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] 12:0] concat=n=2:v=1" -map '[v]' out.gif
  689  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] 1:0] concat=n=2:v=1" -map '[v]' out.gif
  690  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] [1:0] concat=n=2:v=1" -map '[v]' out.gif
  691  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] [1:0] concat=n=2"  out.gif
  694  history | grep ffmpeg
23
discuss.tchncs.de

If you have a fzf or other plugin installed, great. the vanilla Ctrl R is kinda mid in most shells IMO

1

You're gonna love once you start

  1. tagging your ffmpeg commands like do a thing # dothingname

  2. Just !?dothingname later to recall it and run it.

Its a little easier to NOT accidentally !?alt and discover halt is matched first.

1

You can also create aliases for frequently used commands. You can even put a function in an alias so it can accept arguments, but it would probably be better to just write a shell script at that point.

1

⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️

CTL+C

history

history | less

⬆️⬆️⬆️

Pg-up

...

Pg-up

...

q

! 2648

2

Ha... That as if I would ever remember the part of the tool instead of the fact what it did 🤣

8
acargitzreply
lemmy.ca

with grep I see all the alternatives, Ctl+R just shows me one

5

For me ctrl-r is faster most of the time, history | grep [command] is better if I can't easily pattern match (don't remember it exactly, using several flag variations, etc.). they're both good tools.

6
lemmy.world

Ppsshh. Not lazy enough. Create that in a script and call it "hgrep" and drop it into path.

6
lemmy.world

i was doing cat ~/.bash_history | grep thing which is stupid so i started doing grep "thing" ~/.bash_history

now you're telling me i should do history | grep thing

i can't win

5
qjkxbmwvzreply
startrek.website

Some would call the former command cat abuse.

In short, unless you want the contents of a file printed to stdout (or multiple files concatenated), the command can probably be written without cat, instead using the filename as an argument (grep pattern file) or IO redirection (cmd < file).

Stylistics and readability are another thing though.

7

Exactly! Now copy paste it into Joplin where you'll never see it ever again.

1
Lebernashireply
lemmy.world

Every time you hit the up arrow, it shows the previous command you used in the terminal.

So hitting the arrow once gives your last used, hitting it twice gives your second to last command, and so on.

9
lemmy.ca

Yup and that is me. I could just history grep the command I want but I SWEAR it was just 2 commands ago, or 15 up arrows. lol.

3
Jarixreply
lemmy.world

Ohhh! I can absolutely relate to this as well! Using a zmud client to play games on. which is probably not much different, looking, than a terminal anyways

2
zzxreply
lemmy.world

Multi user dungeon? What do you play?

2

Did. It's long gone

Was a modified circlemud. Mostly fantasy. Was a mish mash of popular fantasy worlds. Feist, Tolkien, various DnD settings, letter on they tried to go away from fandom content.

Had any 29 classes, could "remort" keeping 15% of your skills. And had other benefits such as lowering some level requirements here and there.

Was riftsmud.net:4000 originally but they ended up having to move a could times.

About 40 players at peak times, maybe 100 players altogether that played any amount

1

zsh-history-substring-search

I lazily type part of the thing I want like "sys" and then ctrl+⬆️/⬇️ and sudo systemctl start libvirtd etc. appear like magic.

12
lemmy.zip

You're in vim, you forgot to sudo, the file is read only and you have loads of changed you don't feel like saving off to /tmp and playing the copy file shell game.

[esc]:w !sudo tee %

it shoves the current buffer through tee (termina adapter) with sudo privs vim will warn you that the file changed, just [esc]:q! and don't let it save, you already saved it.

11

I offered one for !ssh, then noticed people were giving other obscure tips so i offered this one.

1

Atuin is so good, especially with multiple machines. I just would love more comp. time options to disable the dot dotfiles feature etc.

4
lemmy.zip

!ssh

run the last command that started with ssh

11

It's as amazing as it is dangerous :) use with care!

6
lemmy.ca

I see everyone posting about Ctrl+R, here's a couple more useful CLI shortcuts you might enjoy:

cd - (change directory to $OLDPWD usually the previous directory)

git checkout - (similarly checkout the previous branch)

Ctrl+A (return caret to beginning of command, great when you forgot a positional argument and you were almost done typing the command)

Ctrl+E (similar to Ctrl+A but move to the end of the command)

9

Ctrl+A, Ctrl+E

Many more basic Emacs keybindings work, actually! Including C-f, C-b, C-p and C-n (if you prefer them over arrow keys) as well as M-f and M-b to move by words, C-k, M-d and C-y for killing/yanking (but not M-w) and C-SPC, C-w, C-x C-x for region manipulation (tested in Bash and ZSH)

5
BCsvenreply
lemmy.ca

Ctrl+L to clear the terminal screen, instead of typing clear

1
lemmy.nz

Everyone sharing their Ctrl+R tips, here's my Control+R question:

How does scope work? Some command history only seems to exist in certain tabs.

Also sometimes I Ctrl+R in a tab then the command is there but I forget I need a different one first, so I ctrl+c but the next time I search for that original command somehow it doesn't exist anymore.

I'm using the default terminal on Nobara (fedora based).

8
Trailreply
lemmy.world

As far as I remember, there is a bash setting that controls whether the command history is written immediately after execution (in which case it is immediately available on all tabs/windows of the console) or after closing the session (in which case it will be available next time/potentially lost if the window is forcibly closed etc).

The default is the second one as far as I remember.

That said, I had changed to a more powerful one in zsh years ago, so it's been a while...

12

Thanks, I worked it out. Not a setting as such, but you can use PROMPT_COMMAND to run an action to insert into history each time a prompt is run, as described here.

Though I have started down a rabbit hole of looking at other options for the shell.

1
discuss.tchncs.de

This actually doesn't depend on your terminal but on the shell running inside it. Bash is the default on most distros. I have also frequently had this issue. There might be config to fix it.

I switched to fish instead of bash, and now I use fzf and the https://github.com/PatrickF1/fzf.fish plugin and it works GREAT. There might be a similar thing for bash, I don't know.

9

That looks awesome! Thanks for the rabbit hole 😅

3

Report post

Report reason: ⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️"There it is" I'm in this picture and I don't like it

8
CeeBee_Ehreply
lemmy.world

I'm familiar with fish shell, but what specifically makes you like it?

1

fellow fish user, I just like its autocomplete and how I can just type 'help' and an interactive HTML page opens up where I can look stuff, and fish_config does the same except with settings and themes

2
programming.dev

Ah crap how did I set my battery charge interval again?

history | grep battery

history | grep bios

history | grep sudo smbios

Ah! There you are you little shit!

edit to add: Actually, I think the last time I did this I remembered some numbers I set it to before. So it worked well with something like "history | grep 75" even though there were a bunch of results.

8
lemmy.world

Is there a good way to do this when you use a lot of terminal tabs and aren't sure which tab you used for the command you're looking for?

1

if you close all the terminal tabs and do ctrl+r on a new one it will search all of the ones you closed

2

Someone else said that some comments up.

The reply was "use ctrl+r." And I just tested it.

Game changer. I learned today and so now I pass it on.

2

.. And waste an opportunity to type on my ludicrously expensive mechanical keyboard?

FRIG no

5
lemmy.world

I type the first few letters and use up arrow, or !start of command name

5
lemmy.ca

Doesn't work on half the machines I use,and I am too lazy to find the setting/plugin to make it work.

2
$ cat .inputrc
$include /etc/inputrc

"\e[A": history-search-backward
"\e[B": history-search-forward
2

I don't think it is...? You sure your distro doesn't add some customizations? Neither of the features you mention work on two different distros I just tried it on (openSUSE and NixOS).

3

And its not enabled by default on half my devices, so I am too lazy to figure out enabling it.

I really should do so though, its incredibly helpful when it does work.

1

This is why I use fish, it's weird and not posix compliant, but its autocomplete and history stuff saves so much time it's worth it

4

Nah just save all your commands in a text file on the desktop then make an alias to open it in nano so you just have to type "com". Works for dumb ol me

4
CeeBee_Ehreply
lemmy.world

Why not just make the alias command cat the file instead?

Edit: I wrote grep instead of cat

1

Me, playing indie games on Apple and doing the same with xattr -d com.apple.quarantine ~filepath

  • yes
4
lemmy.world

I see so many people loving on atuin in the comments but I just tried it and don't get it. It seems so much worse than the built in search. I guess it's not for me.

3

I've been using it for a few months, and so far it's not as good as just regular old command history. I think any benefit might be for really, really old commands, or commands happening in a specific location. So, I'm going to keep using it to see if it helps then. But, so far it's a massive downgrade.

4
ian
feddit.uk

I thought command line users like typing things. I avoid typing where possible, and dont use the command line on Linux.

3
hansoloreply
lemmy.today

For a while I was using a VPN where the connections we all via command line. I loved it, because once you type it, it's just up up up to find that location again and swap around.

Now I have to use the mouse and click like a damn fool!

7
Logicalreply
lemmy.world

I work as a software developer. My team mate once said he was a "mouse and click kinda guy" when asked why he didn't use the terminal for git.

3
Frezikreply
lemmy.blahaj.zone

Part of the reason for a command line is being able to reproduce commands exactly. Going back through the command history is an important part of that.

5
ianreply
feddit.uk

A GUI with good usability can let you repeat commands exactly if required. They use last used values as default. If people in needed that often we'd see more of it in GUI apps. There is often more useful functionality that get prioritised though.

1
Frezikreply
lemmy.blahaj.zone

It is done, but it comes in specifically packaged form for each use case.

Postman is essentially a GUI app for reproducible curl commands. There's nothing in Postman that couldn't be done by a good shell script, and it will spurt out a curl command if you want. To get this in a shell environment, you need to have the knowledge to put together tools that are sitting right there. To get it in a GUI environment, you need a team of people who probably know how to do it in a CLI, but then create a complex memory hog GUI to do it otherwise. None of that development effort is directly transferable to any other problem space.

2
ianreply
feddit.uk

That's not necessarily so. There are all sorts of legacy reasons people give for making poor software. From lazy monopolies to programmers with little understanding of usability. To people without the big picture. It will change.

1
Frezikreply
lemmy.blahaj.zone

Why would it suddenly change now, decades after the first GUI operating systems were available to average people?

1

Sadly, big business, techies without imagination and community FOSS without enough capacity are the ones that control what is available. Nothing will suddenly change. Usability is way down the priority list.

1
lemmy.world

In my first professional programming job writing custom software for clients in 1995, one of our standard sales pitches to clients was the idea that a GUI-based application would do away with the need for command prompts. This was always met with applause and great rejoicing. It's kind of remarkable that command prompts are still going strong thirty years later. I'm sure nobody would appreciate having this phenomenon compared to the Amish so I won't do it. But I think it's pretty cool that the Amish are still around doing their thing.

4
Homesnatchreply
lemmy.world

GUI is great, unless you want to automate something.. Then you either want a CLI or API

4

Nah, companies found solution to that long ago.

...

...HOW'S IT GOING JOHNY, GOT THAT LIST PARSED YET?

2

People do not just point and nod. Using words and not just guestures makes life easier in many, but not all situations.

2

A GUI makes sense if you want things to be approachable. A CLI makes sense, if you want things to be well customizable.

E.g. compare LaTeX script with setting formatting in an office program. Yes i see directly how the formatting is. And if a good Formatting standard is set, it can be used quite well nowadays. But if just want to put one Paragraph differently in order to fit a picture or table or something then things quickly get messy.

1

Your readline config sucks because the default sucks.

Add this to your .inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward
3
ozymandiasreply
lemmy.dbzer0.com

type part of the command, then press up and it’ll complete it from your history….
also i suggest Oh-My-Zsh for nice colors in the terminal
the first time you do it you’ll get angry at all the time wasted in bash… also with oh my zsh it’ll show you what branch you’re in in a git repository… it’s great.

2
Tjareply
programming.dev

Thanks! I have zsh on some of my machines, and installed zpresto on some but never got the advantages... probably due to bash muscle memory.

You also can get the git branch in bash, and a bunch of other $PS1 customizations are also possible (Tmux, ssh, time, background processes, etc).

I'll try the up completion later :)

2

yeah you can do anything in bash….
zsh is really just an extension of bash, imo…
but the completion alone makes it worth it for me.
also colors in the terminal

2
Danitosreply
reddthat.com

No es común ver hispanohablantes en Lemmy, ¿de qué país eres?

3
HorreCreply
lemmy.world

you really should just ctrl + r and type and then ctrl + r to goto the next one back.

6

Huh. I didn't know that one. It's much more practical. Thanks for teaching me something today.

4
lemmy.world

You know the one command I hate? CTL vs CTRL. There is no damned consistency I can see. Is it systemctl reboot or systemctrl reboot?

2

i've literally never seen 'systemctrl'? it's always ctl for the command-line utilities

10
lemmy.world

If I haven't ran it in a while or I don't know it by heart then I 'nano /home/mehblah/.bash_history'

1

I forget that exist. One problem with being really old school on linux is you don't adopt new ways unless there is a reason to do so.

2
Siegfriedreply
lemmy.world

Que paso que hay tanto comentario en Castellano? Pensé que eramos pocos los hispanohablantes

1
NeilBrüreply
lemmy.world

Hermano, nací en Estados Unidos. A pesar de que se dice que los estadounidenses solo sabemos inglés (y mis padres son de la India), saber hablar un poco de español es bastante útil.

Además, el OP publicó en castellano. Por lo tanto, me pareció pertinente y cortés comentar al respecto.

1

No lo decía por este post en particular, sino en general estoy viendo posts y comentarios en español y me llamó la atención.

1