Live data from Hacker News

What's the one Linux command you wish you knew years ago?

reddit.com

161–170 of 216 posts

Re: What's the one Linux command you wish you knew years ago?

#161
post #46

Not really a command but this: mv /path/to/some/file.{jpg,png} Has been a huge timesaver. It's the same as mv /path/to/some/file.jpg /path/to/some/file.png But saves you the typing/copy pasting the path for the second argument. Can also be used with cp etc.

The best is when you mix filename expansion and brace expansion :

  > ls *.{png,jpg,bmp,gif}
But this gives error if there is no jpg files. In bash, you can activate the extglob mode with "shopt -s extglob" and do this :

  > ls *.@(png|jpg|bmp|gif)
http://www.faqs.org/docs/bashman/bashref_35.html

Re: What's the one Linux command you wish you knew years ago?

#162
post #143

Earlier quoted context omitted.

Perhaps not, but tmux's bindings are nearly all backwards-compatible with screen's. Well, the default escape char is ctrl-B but I (and I think most folks) just remap it to ctrl-A immediately.

How do people use CTRL-A for screen without being driven batty that the emacs-style 'start-of-line' command is not available? I use that constantly!

I actually only learned that ctrl-A works in bash 3-4 months ago, and haven't yet picked a new screen/tmux escape and retrained to it. Mainly because these days, I only use screen when I WFH or am traveling, when I ssh into my workstation. Almost nobody has ssh rights to a production machine, so I'm actually struggling to think when I would use it from my workstation.

Re: What's the one Linux command you wish you knew years ago?

#163
post #143

Earlier quoted context omitted.

Perhaps not, but tmux's bindings are nearly all backwards-compatible with screen's. Well, the default escape char is ctrl-B but I (and I think most folks) just remap it to ctrl-A immediately.

How do people use CTRL-A for screen without being driven batty that the emacs-style 'start-of-line' command is not available? I use that constantly!

People rebind it. I bind it to ^o.

  # put this in your .screenrc
  escape ^Oo

Re: What's the one Linux command you wish you knew years ago?

#164

watch for not having to repeatdly type a comnand, usually for an sw app stat for checking when a files been accessed tee piping to a log file with tee, while still seeing normal stdout on screen

I love the watch command too. I really enjoy it with -d (delta or differences) which will highlight what changed since the last run.

Re: What's the one Linux command you wish you knew years ago?

#166
post #143

Earlier quoted context omitted.

Perhaps not, but tmux's bindings are nearly all backwards-compatible with screen's. Well, the default escape char is ctrl-B but I (and I think most folks) just remap it to ctrl-A immediately.

How do people use CTRL-A for screen without being driven batty that the emacs-style 'start-of-line' command is not available? I use that constantly!

Pressing ^A then a in screen should deliver a single ^A to emacs.

Re: What's the one Linux command you wish you knew years ago?

#167
post #62

Quitting SSH connections that hang: ~. If you frequently connect through VPNs to other hosts, often enough the SSH connection times out and just siits there, taking no commands. Hitting ~ and . will kill the session (it's an openssh feature). Other frequently used tools: awk, sort, uniq, tail, find, grep.. they alone make the shell a really powerful tool

it's important to note that this needs to be preceeded by a newline to work.

so:

    ~? (list possible escapes)
    ~. (disconnect session)
If you're dumping binary data through ssh as a pipe, this can sometimes bite you if these sequences appear in your data.

    ssh -oEscapeChar=none ...
handles that situation. (for the gory details, man ssh_config)

Re: What's the one Linux command you wish you knew years ago?

#168

Earlier quoted context omitted.

You will be pleased to know that there is a site full of little gems like this: http://www.commandlinefu.com/commands/browse/sort-by-votes Most of my time savers that I've never thought of were found there.

python -m SimpleHTTPServer Love this one.

And for you crazy people on python3..

python3 -m http.server

Re: What's the one Linux command you wish you knew years ago?

#169

Earlier quoted context omitted.

python -m SimpleHTTPServer Love this one.

And for you crazy people on python3.. python3 -m http.server

    [ward@hathor ~]$ ls -l /usr/bin/python
    lrwxrwxrwx 1 root root 7 Sep  5 00:45 /usr/bin/python -> python3
Arch default

Re: What's the one Linux command you wish you knew years ago?

#170

Earlier quoted context omitted.

sed -i does the same thing as perl -pi. Though I've not encountered a system that doesn't have both.

Does sed allow in-place file replacement, or do you need to redirect to a different file then cp/mv it over the original? I haven't used it in many years, but sed didn't used to allow this.

Note: "cmds" is one or more s commands. For other commands, if it's a big file, I will just pipe through less (still no temp file) and then save the buffer (to overwrite the original file), instead of using this hack.

A hack for in-place editing, for old school sed (no -i):

sedi(){ case $# in 0) echo usage: sedi cmds file;; 2) sed -an ' '"$1"'; H; $!d; g; w '"$2"'' $2;; esac; }

Post reply on HN