Email or username:

Password:

Forgot your password?
12 comments
Anthropy :verified_dragon:

@b0rk_reruns how did I not know about using space to avoid getting a command in .bash_history :blobcatgooglyholdingitsheadinitshands:

Theodor RenΓ© Carlsen

@b0rk_reruns a rare shortcut I see people rarely use which I personally use a lot is Alt+.

It adds the last argument from your previous command to your current command.

AsheπŸˆβ€β¬›πŸ³οΈβ€πŸŒˆ

@b0rk_reruns ooooo these are super useful!

Another bash history shortcut I use all the time is !:s/PATTERN/SUBSTITUTION/, which lets you do sed-style regex substitutions on your last run command. You can also use ^PATTERN^SUBSTITUTION as a shorthand, or add the first few characters of the command you're looking for after the ! if you want to search for the most recent use of a specific command (i.e. !cat:s/PATTERN/SUB/)

There are a whole bunch of useful history shortcuts I didn't know existed until recently; definitely recommend looking up an exhaustive list if you're curious. This is the first time I've seen the ctrl+r one though, definitely gonna be using that frequently

@b0rk_reruns ooooo these are super useful!

Another bash history shortcut I use all the time is !:s/PATTERN/SUBSTITUTION/, which lets you do sed-style regex substitutions on your last run command. You can also use ^PATTERN^SUBSTITUTION as a shorthand, or add the first few characters of the command you're looking for after the ! if you want to search for the most recent use of a specific command (i.e. !cat:s/PATTERN/SUB/)

domi

@b0rk_reruns do NOT do loops like this! this is DANGEROUS

1. iterating over a list of files is fine. and if you know that your filenames don’t contain spaces, your approach will work. otherwise, you will iterate over a part of the filename, not the full one. Best case, your script doesn’t do anything. worst case, it spews garbage in your $PWD and you need to manually clean it up

correct way to do it:

IFS=$'\n'
for i in *.png; do
   convert -- "$i" "${i/.png/.jpg}"
done

IFS (inner-field separator) is a special variable which tells bash when to split stuff. By default, it’s a space; We set it to newline, because it’s a safe assumption that a file won’t have one.

1. try to prefix your file parameters with a double dash (--). this is a somewhat-standard way of terminating named arguments and specifying that everything after this point is raw data.

Terminating arguments is important if you use a variables that you don’t necessarily control. Take this for example:

a="-nastyFilename.jpg"
convert "$a" output.png

This will fail, because imagick will try to interpret the first arg as a switch. This can wreck havoc on your system, don’t ask how i know.

1.

always quote your variables, unless you truly want them to expand! if you don’t, they may get passed as separate args to a command you’re executing.


2.

if your directory is HUGE (over 30k files), don’t use for; this is because for every command there’s an argument amount limit, and * expands to one arg per file. instead, do this:

while read i; do
    echo "$i"
done <<< $(ls)

another, even better way is to use find with its -exec option:

find . -maxdepth 1 -exec echo {} \;

anyways, sorry for the rant. i know a little bit too much bash, and i wish this curse upon everyone else >:3

@b0rk_reruns do NOT do loops like this! this is DANGEROUS

1. iterating over a list of files is fine. and if you know that your filenames don’t contain spaces, your approach will work. otherwise, you will iterate over a part of the filename, not the full one. Best case, your script doesn’t do anything. worst case, it spews garbage in your $PWD and you need to manually clean it up

Blobster

@b0rk_reruns Thanks for your great zines.

For those who don't know yet, passwords should never be written in commands anyway, since command arguments are visible to local users via the process table, using e.g. ps -eo pid,cmd (of course, this risk is only effective if at least one local account is controlled or compromized by someone who shouldn't be able to see the passwords in question).

Mr. Bruno :verified:

@b0rk_reruns I didn't know about the "commands that start with a space..." tip! I'm going to have to remember that!

Steven Pigeon

@b0rk_reruns for the loop example, I'd use ${i//.png/.jpg} to replace extension or ${i%%.*} to remove extension.

odefey

@b0rk_reruns ctrl-u deletes backward until beginning of line,

πšŸπš˜πš’πš *

@b0rk_reruns I also use `Ctrl+U` a lot to clear the current input.

It works great, specially if you misstype a password field and want to start over, which happens to me quite often.

πšŸπš˜πš’πš *

@b0rk_reruns Also, having these:

## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward

In your `~/.inputrc` file makes it very easy to use history search on the current input and it's very intuitive. I will write `git` and hit the up and down arrows to navigate the git command history, for instance.

askubuntu.com/questions/59846/

@b0rk_reruns Also, having these:

## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward

In your `~/.inputrc` file makes it very easy to use history search on the current input and it's very intuitive. I will write `git` and hit the up and down arrows to navigate the git command history, for instance.

Go Up