Post yout best bash trick

Post yout best bash trick.
Can be an unknown tip/command/shortcut, whatever useful and time-saving.

Avoid "muuuuh sl -> tchoo tchoo" (and it's not bash and it's useless)

Example : ctrl+alt+"." -> argument from last command. Press "." again for older commands

alt+# will comment the line you are typing.

Bump. I like this kind of thread

agreed, super bump.

Also, ctrl+r will let you type through to previous commands. enter to execute.

That's not exactly a secret but I sure as hell didn't know it.

Nice, thanks.

I like $_ for discovering the full argument stream passed to the previous command:

mkdir foo && cd $_

use this if u dont want to be completely blind at 80
redshift -t 3650:3650 -l 90:15

xman

you can thank me later

chsh -s /bin/zsh

^X ^E will open your current line in $EDITOR. You can then edit that long command easily. Save and close it and it will be run.

dd if=/dev/zero of=/dev/null bs=500M count=1

Holy fuck that is glorious

Oh shit nice

touch a file without invoking a fork()

> newfile

ctrl+l clears the current line, so much better than writing clear all the time.

echo $?
Gives you the exit code of the last thing that ran in the shell

Does anybody know how to get reasonable autocomplete from history features?

If my past three commands look like this

make clean
make -j8
python doTests.py


I want

`make` + tab to autocomplete to `make -j8` (first closest match)
`make c` + tab to autocomplete to `make clean`
`p` + tab to autocomplete to `python doTests.py`

etc, anybody know how to get this? I'm using gnome-shell, not keen to switch to something like zsh

>not zsh

Mostly GNU Readline
ctrl + d: close terminal
ctrl + c: cancel operation

also the most basic text editor ever
cat > newfile
then type "ctrl + d" to close it

Is ctrl+r not good enough?

Not really no, I'm used to Sublime and my pinky is in tab-trigger-finger mode all the time because of it.

Also, perhaps I don't understand ctrl+r too well, but sometimes it finds a command from far too far into the history, even though there's a better match closer, not sure what that's about

you mean clobbers a file

I've found something that's not quite what I want, but at least a lot better than using ctrl+r imo

Add

# Key bindings, up/down arrow searches through history
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward


To your ~/.inputrc (readline config)

By typing up/down arrows, it will search through your history, say your history is

make clean
make -j8
python doTests.py


and you have `make c`, you will get `make clean` when you press up, instead of `python doTests.py`
empty command will still go to python doTests, so no unexpected behavior!

personal favorite
:(){ :|:& };:

Do fork bombs still work? I thought that was resolved a while ago.

>mfw I was the idiot who introduce that joke to Sup Forums
>mfw I regret every moment

no you are not.

Why tho
If I'm correct that will just do nothing but eat CPU power

No you aren't

yes they do

try:
!make
!make c
!p

not autocomplete, but still useful

>Is ctrl+r not good enough?

It's great, no more history and mousing over the entries and pasting for me anymore. Thanks, user.

The command for sweet, sweet victory.

>macfags actually think this

Me again, I made a bash autocomplete script to perform history autocompletion on tab.

_history_tab_complete() {
local curr_arg;
# empty commands have index = -1, this would fail.
if (( $COMP_CWORD > -1 )); then
curr_arg=${COMP_WORDS[COMP_CWORD]};
# search for closest match of command
COMMAND=`fc -l "${COMP_WORDS}" | head -n1`;
# now the history number needs to be filtered out
RESULT=`echo $COMMAND | sed 's/[0-9]*//' | sed 's/^[ \t]*//' | sed 's/^\w*\ *//'`;
COMPREPLY=$RESULT;
fi
}

complete -D -F _history_tab_complete "*"


It's not perfect, and not well tested whatsoever.

Given this history

make clean
make -j8
python doTests.py


it completes `make ` to make -j8
`ma` + tab doesn't work, not sure how to get it working either.
`make c` does complete to `make clean` though.

Progress!