News for hackers. Stuff that matters.
Re:What's the one Linux command you wish you knew years ago? by mmaunder on Sunday November 20, 2011 @02:13AM (#3257526)
100% agree with CTRL-R. It changed my life. Others that I love:

screen, pdsh,

perl -pi -e 's/find/replace/g' *.txt

redis-cli's new ability to have piped in data be the last argument of a command.

vim -o file1.txt file2.txt file3.txt (opening multiple files with vim)

Using vim instead of less as a pager: cat file.txt | vim -

Re:What's the one Linux command you wish you knew years ago? by sixtofour on Sunday November 20, 2011 @04:39AM (#3257728)
http://www.vim.org/scripts/script.php?script_id=1723

vimpager. Set vim as your pager. I love reading man pages in syntax-colored vim glory.

Re:What's the one Linux command you wish you knew years ago? by dredmorbius on Sunday November 20, 2011 @03:20PM (#3258920)
I prefer keeping file viewing and file editing as separate actions.

'most' will colorize bash output as well (it's strictly a pager, in the pg / more / less / most continuum).

Re:What's the one Linux command you wish you knew years ago? by sashahart on Sunday November 20, 2011 @10:24PM (#3259824)
As I recall, vimpager doesn't edit files, it just uses vim to view the file instead of using a different program to view the file.
Re:What's the one Linux command you wish you knew years ago? by Aissen on Sunday November 20, 2011 @11:10AM (#3258349)
Wow! I knew about less.sh (aka vim less), but this seems even more powerful. Installing now!
Re:What's the one Linux command you wish you knew years ago? by steve-howard on Sunday November 20, 2011 @03:14AM (#3257601)
sed -i does the same thing as perl -pi. Though I've not encountered a system that doesn't have both.
Re:What's the one Linux command you wish you knew years ago? by Someone on Sunday November 20, 2011 @03:34AM (#3257637)
sed's regular expressions are different from those perl uses (even when using the (¿gnu sed?) flag that tells sed to use extended regular expressions). Especially if you "live in perl", that can be a problem.
Re:What's the one Linux command you wish you knew years ago? by michaelcampbell on Sunday November 20, 2011 @11:43AM (#3258424)
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.
Re:What's the one Linux command you wish you knew years ago? by derwiki on Sunday November 20, 2011 @11:58AM (#3258463)
sed -i 's/old/new/g' file
Re:What's the one Linux command you wish you knew years ago? by 1010010101 on Sunday November 20, 2011 @04:42PM (#3259095)
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; }

Re:What's the one Linux command you wish you knew years ago? by philjackson on Sunday November 20, 2011 @05:12AM (#3257778)
Did you know that Ctrl-s will search forwards through the history too? You'll have to switch flow control off first.
Re:What's the one Linux command you wish you knew years ago? by sixtofour on Sunday November 20, 2011 @11:19AM (#3258366)
Fantastic. I've always wanted to know what I'm going to do next.
Re:What's the one Linux command you wish you knew years ago? by dredmorbius on Monday November 21, 2011 @05:25PM (#3263092)
C-R was one of a few watershed moments for me. I discovered it over a decade a go as a cow-orker was flying through commands way faster than was humanly possible. "How did you do that?". And so I learned.

It, along with other readline functionality, shell functions, substitutions, expansions, scripts, and the bazillion utilities are what make Linux (and Unix) shell so much more than just "it's like DOS, right?".

Yeah, kind of, in the same way that ... a cross between a Prius, a Mack Truck, an Lamborghini, an F-16 fighter, a helicopter, and a freight train are like a pushcart. It's an interface that helps you manage your computers, the things on them, and the things they're connected to. It's also a hugely efficient and effective way to process information and issue commands and controls in a useful way.

Re:What's the one Linux command you wish you knew years ago? by beej71 on Sunday November 20, 2011 @03:20PM (#3258921)
And vim -p file1.txt file2.txt to open them in tabs.
Re:What's the one Linux command you wish you knew years ago? by adgar on Sunday November 20, 2011 @11:04AM (#3258333)
> screen

Unless you only use GPL software, there's no reason to not use tmux these days. Well, maybe if you're on HP-UX or something.

http://tmux.sourceforge.net/

Re:What's the one Linux command you wish you knew years ago? by gnosis on Sunday November 20, 2011 @01:48PM (#3258696)
I've switched from screen to tmux about a year or two ago, after decades of using screen.. and I'm perfectly happy with tmux, as it fits my needs.

However, it's not true that screen has no advantages over tmux. Each program has its own strengths and weaknesses. For instance, screen is scriptable via its Lua bindings, tmux is not. Screen has zmodem support built in, tmux does not. There are probably many other examples, since screen has a bazillion features which have been developed over decades, while tmux is relatively new (and its developers don't seem to care to duplicate every one of screen's features).

Re:What's the one Linux command you wish you knew years ago? by adgar on Sunday November 20, 2011 @02:04PM (#3258740)
tmux is scriptable from the shell via its command-line arguments, so any language can script it.

It's certainly true that screen does have tons of small old features... but I sort of swept that in with "unless you're using HP-UX or something." zmodem support isn't exactly relevant to the overwhelming majority of programmers, but yes, I admit these things are still relevant to a few niches.

Re:What's the one Linux command you wish you knew years ago? by gnosis on Sunday November 20, 2011 @02:26PM (#3258791)
"tmux is scriptable from the shell via its command-line arguments, so any language can script it."

I'm not sure if tmux is scriptable to the same extent that screen is via screen's Lua bindings, as the latter probably exposes many of screen's internals, while scriptability of tmux is limited to what you could do with its command line arguments. I haven't researched the matter, though, so I may well be wrong.

Re:What's the one Linux command you wish you knew years ago? by gcb on Sunday November 20, 2011 @02:03PM (#3258738)
Is tmux as available as screen?

I often have to fix servers that are not from own group, so all my knowledge is honed around tools that i can find anywhere.

Re:What's the one Linux command you wish you knew years ago? by adgar on Sunday November 20, 2011 @02:06PM (#3258747)
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.
Re:What's the one Linux command you wish you knew years ago? by LogicHoleFlaw on Sunday November 20, 2011 @03:43PM (#3258971)
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!
Re:What's the one Linux command you wish you knew years ago? by spudlyo on Sunday November 20, 2011 @04:12PM (#3259038)
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? by lambda on Sunday November 20, 2011 @10:15PM (#3259810)
I always rebind it to ^z. Since I never need to put a process in the background (I just open a new screen instead) when running screen, it never bothers me that that combo is a bit harder to type.
Re:What's the one Linux command you wish you knew years ago? by _mrc on Sunday November 20, 2011 @06:22PM (#3259329)
or if you never use toggle-input-method, maybe C-\

  escape ^\\
Re:What's the one Linux command you wish you knew years ago? by nitrogen on Sunday November 20, 2011 @04:26PM (#3259065)
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? by gnosis on Sunday November 20, 2011 @08:26PM (#3259571)
I don't use CONTROL-A to go to the start of the line, instead I hit ESCAPE 0

It works because I have my shell configured to use vi mode for command line editing.

Re:What's the one Linux command you wish you knew years ago? by there on Sunday November 20, 2011 @09:08PM (#3259663)
i use the ratpoison window manager (it works a lot like tmux/screen, but for x11) and have control+a set as its prefix key. i use tmux for some long-lasting remote sessions, so to send a control+a to the shell running under tmux, under ratpoison, i type control+a, a, control+a, a. yes, i do it a lot. no, i'm not going to change it.
Re:What's the one Linux command you wish you knew years ago? by adgar on Sunday November 20, 2011 @04:10PM (#3259026)
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? by erez on Monday November 21, 2011 @06:03AM (#3260714)
Crtl-Z, you mean. Ctrl-A is for start of line in bash and emacs, so that won't do