@cypnk if you like Vim (who doesn't?) You can get all of the Vi hotkeys with this command:

set -o vi

Put it at the end of your .bashrc file for super convenience!

@eladhen Julia has a few Zines that are well worth checking out jvns.ca/zines/

She's also @ b0rk on Twitter

@cypnk Knowing which of these come from where is useful.

'help' will list the set of shell built-ins. These are commands that exist _in the shell_, and are _not_ run from disk.

Note: some DUPLICATE disk commands, e.g., "time" and "echo".

Editing commands come from GNU Readline. See 3readline. Also extensive docs in the bash manpage.

Brace expansion and history substitution are in the bash manpage.

'set -o' will show your shell settings.

There's also prompts, $PROMT_COMMAND, and more...

@cypnk I've used bash (or precursors) for over 30 years now, and there are *still* many things I don't know or am unfamiliar with. Every so often I discover some set of features and another penny drops.

On the one hand: daunting. On the other: this is what makes the Unix (Linux / MacOS, and increasingly, Windows) shell so goddamned powerful. You can do a tremendous amount with a few keystrokes.

@xenofem I got around this by renaming all .png.jpg or similar files to ---png.jpg first. While dashes appear in filenames, triple dashes are rare enough that I've been able to get away with it

@xenofem @cypnk you can also use the bash variable string manipulation tools to avoid sed, eg.:

for i in *.png; do convert -i "$i" "${i%.png}.jpg"; done

The bash string tools are less powerful鹿 than sed/awk/grep and will tend to be slower on large data sets虏 but because they don't fork a subprocess they can be faster than hundreds of individual invocations!

鹿: equivalently powerful, mathematically, but less convenient

虏: I think when I checked the crossover point was BIG

@gnomon @xenofem @cypnk But, never use shell for loops unless you know precisely what files are in there, or spaces will screw you over.

find . -type f |while read -r f; do echo "$f"; done

is massively safer. And then you can use basename or shell replacement or whatever to convert filenames.

@xenofem I sometimes have to preserve the filename as-is, especially if it's an uploaded file directly linked by lots of places. Can't suddenly start serving 404s because I fixed the extension

I tend to use:
rename 's/png.jpg/---png.jpg/g' *

Once I do what I need to do, I switch them back
rename 's/---png.jpg/png.jpg/g' *

@cypnk ^R is actually readline, not bash. This means it works with everything that supports readline!

@anahata @cypnk yeah Ctrl+a and so are too.
Reading about Readline (lol) is one of the best things I ever made.

@anahata @cypnk readline is a pretty neat library, it's really easy to add it to stuff to make your programs really feel polished.

@cypnk the "Emacs" commands mentioned in first image's last panel are "deadline" commends, if anyone wants to Google for more of them (e.g. ctrl-d is del if the line isn't empty). Also I think they're correct in celling them emacs commands because iirc that's where they came from, but readline is available in many places and easy to Google for

@cypnk oops autocorrect, deadline should be "readline"

@cypnk I use some of these so much I take them for granted, but I would have loved to know all of this when I started using Linux!

Another tip I learned recently: the watch command.

It will take whatever command you run after it, display its output, and refresh the display every couple of seconds by running the command again.

Example: watch df -h is useful to monitor disk usage when you're doing something that drastically increases or decreases it

@cypnk Somewhere I've got a good handout she made for strace. Her talk was great.

@cypnk

I need more monitors so I can set all the cheatsheets I need as backgrounds...

@cypnk

that's like the exact opposite of a productivity machine for me, i'd just spend all day staring down waiting for new toots on the left and emails on the right...

@cypnk My favorite is $(( math stuff! freely mix hex and shifts and base 10 )).

@cypnk These are great. I had no idea I could use CTRL+R instead of pressing up 100 times.

@cypnk

#1 - thank you for introducing me to 'fc'

#2 - I wish it also captured things cancelled with Ctrl+C, I always wind up typing some really long command, finding a mistake, Ctrl+C-ing it, and then re-typing it as punishment...

@cypnk
CTRL+Z susends the current process. To let it run in background (while input stays available), call `bg`. After that, pull it back to front using `fg`.

@cypnk be careful looping with wildcards:

for something in *.png; do echo $something; done

spaces in filenames can be messy and super dangerous if they start with a dash

dwheeler.com/essays/filenames-

Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 馃悩 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!