The first thing I do on any bash terminal is `set -o vi`. This changes the default keybindings from emacs-like to vi-like. I find it to be a huge booster to my speed in navigating the command line.
edit: Actually, something cool I learned recently is that if you put the line "set editing-mode vi" in your ~/.inputrc then vi-like editing keys are available in any program that uses readline. This includes bash and the python repl. Presumably, a bunch of other repls and interactive command lines too.
How do you typically go to e.g. beginning/end of line; via insert or normal mode and which key combinations do you prefer?
Always been using ctrl+a and ctrl+e in emacs mode myself . . .
Very true. I have difficulties in training new recruits with UNIX. For some reason, beginners have developed an aversion to UNIX/shell scripting. I myself have started more and more of Ruby/AWK/Python, but it is always SHELL that blows me off with the sort of impact it has on the daily work.
I ended up highly optimizing my work environment to replace long ssh connections with `conn prod` (will use my RSA key and connect). File tranfers with `go get prod filename` or `go send prod filename`. Another script that can remember directory paths (I have to go over lot of them every day, and typing long lengthy ones does not help).
To me, UNIX shell scripting is a lazy men's most effective tool, only if you know how to use that rightly.
I'm a relative newbie in the field, but I really love using terminal (I do all my C work for grad school in ViM), it's really essential at work, there's no faster way to do batch file processing a lot of times (especially with ffmpeg, awesome).
I'm surprised people don't like terminal, I love using it. It makes me feel old school, sort of like one of those hackers in the movies. That's probably just a personal thing.
I was familiar with most of the concepts but the links section made things click in that regard. Enjoyed the post as well.
It just takes a while to be faster in the terminal than with the gui, and most people won't switch from the thing they're used to until they see significant advantages.
I remember when I first started using the terminal, it was slow and confusing. You had to read the man pages for every little thing. Discovering the command you want is tough, I'd be screwed without the internet.
Now I hate when I need to take my hands of the keyboard to use the mouse. What a waste of time!
If you didn't know you can put ssh configurations (hosts, ports, keys, etc) in ~/.ssh/config. You can use it in scp like 'scp prod:path/to/file path/to/destination'. Not sure if there's a pro/con to mapping an alias.
Same case with `scp`, I have bunch of production servers and I have to send/get files from production server all the time. This means, I have to come up with my own one-line command [https://raw.githubusercontent.com/guruparan18/go/master/go]
As I said earlier, to me, UNIX scripting is highly personal. The scripting reflects one's personality. That is why there is not always the right one. There are several way of doing.
Bash scripts are great if they're yours. My current project has ~20 large bash scripts that do all sorts of different things. They were all written by people who haven't worked on the project for two years. Anyone who needs to make changes there spends far too long trying to figure out what's going on. The scripts could have been written in the same language as the project, and it wouldn't take a whole day to make changes to them.
I think they wrote in Bash to avoid the interpreter startup time. But the scripts are run very infrequently and most of them start/stop long-running services.
That being said, getting a bash script to do the right thing is very satisfying!
Bash scripts for very simple series of commands; higher level scripts for when those sets of commands need logic wrapped 'round 'em. For example: provisioning for packer|vagrant, if you don't need to go overkill with puppet|chef.
It's not just UNIX, hey. I come across a lot of programmers that have no idea how to browse the basic command line in windows. I.e. They have no concept of relative paths, browsing through folders, command parameters. It's all incomprehensible "mumbo jumbo" for them.
Which is fine, not everyone has been exposed to it. Eventually, by the fifth time I have to tell them how to move one folder up (Cd ..), I realize that something is very, very wrong.
When I was a student programmer, my boss came over to my desk to introduce my new project. He then fired up a terminal, ssh'd into the box where I would find the data. He then presented me the data by doing all kinds of bash magic. I was fairly impressed each time. I used some time just trying to make sense of what he did and how.
I don't understand why you need options at all... If you point it at a file/directory it should automatically compress and if you point it at an archive it should automatically decompress. The options should be there for advanced tasks not 90% of the tasks you need the app for. It's really poor ui design.
Lately, all of my tar use has been `tar -xvf filename`. I don't remember it always being the case that those options would automatically gunzip/uncompress, but they do now!
Hm, what OS? They didn't in the past. You needed to use 'tar -zxvf' for gunzip and 'tar -jxvf' for bzip2 IIRC. I still use it today to wrap files and move them on my server. On the server I use 'lzma' as default compression for archiving files (sql schemas, conf files, etc.)
Primarily Ubuntu, I'm not sure if this worked on my laptop when I was using Arch a couple years ago... I'd estimate the behavior has been around since 2008-2009.
I've found the option[1], but it's not in my alias list.
Edit: Changelog says Version 1.20 (2008-04-14) introduced the --auto-compress option
My most used bash command is probably "sudo !!", which runs the previous command with "sudo" prepended.
The book "Unix Power Tools" showed me that higher-level programming languages (Perl, Python, Ruby, etc) are not needed to accomplish most administrative tasks. Awk is incredibly useful (but also very confusing, imo).
It should be noted for onlookers that this is the abbreviated form; !-3:4 goes back to the third-to-last command and refers to its fourth argument, and similarly !-3:$ is its last argument.
It's also apparently not universally known that bash has csh-style (similar to sed) editing, so "s^foo^bar" will repeat the previous command with "bar" substituted at for bar. So "ls foo" becomes "ls bar".
Similarly with !-3:s^foo^bar
I freely mix these things with readline-editing, depending on what needs to be done.
Since csh gets a lot of disrespect these days, to give credit where due: these are all Bill Joy features from the original csh -- it's a good thing that bash borrowed innovations from various shells beyond Bourne shell and ksh.
Historical footnote: We donated code to him to do readline-style editing circa 1978, but he said raw mode was bogging down the pdp 11 too much. Systems were a bit slower back then.
You can use slash(/) and question mark(?) to search for text (forward and backward) in vi. It's useful to know these, because they also work with less(1).
If you are Windows user and used to press Ctrl+S to save the file and you accidentally do that in Vi, your terminal would get stuck. But you can use Ctrl+Q to unfreeze it.
"Fact of life is, as you spend time in the terminal, you're probably going to launch Vim at some point, whether willingly or not...For all other intents and purposes, just friggin use nano. Or sublime."
Tip: I recently looked up the man page for "which" and found out about the -a flag which will list all instances of the executable found (instead of just the first one). Incredibly useful when you have multiple installations of the same software and it's causing problems. e.g.:
$ which -a ruby
/Users/olalonde/.rbenv/shims/ruby
/usr/local/bin/ruby
/usr/bin/ruby
My first experience of vim was trying to fix my xorg.conf from a tty. I figured out how to save the file, but couldn't exit. In the end I hard-rebooted :$
^C also pops up this helpful dialog (after you've already pressed it once to get to normal mode, but the use case is that you're probably mashing it trying to figure out why you can't exit this crazy editor):
I love playing around in bash. Most of the scripts I have right now are just for setting up project templates, adding common packages etc.
Actually, I think most people who use computers at work, be they writers, designers, whatever, not just programmers, would benefit from learning some bash (or batch). You can automate a lot of useful processes with a few simple scripts.
The commands are pushd and popd, and they're bash (and zsh, and most sane shell) builtins. Pushd to get to a new directory, popd to go back to the last one on the stack.
More likely, if this is meant to be a gentle introduction to the command line, vim is a pretty scary place. Nano works much more like a "normal" text editor.
Until you want to undo something! Nano is definitely more user-friendly though. Some of the engineers I work with still don't know basic vim shortcuts, like 'w' and 'b'
edit: Actually, something cool I learned recently is that if you put the line "set editing-mode vi" in your ~/.inputrc then vi-like editing keys are available in any program that uses readline. This includes bash and the python repl. Presumably, a bunch of other repls and interactive command lines too.