Live data from Hacker News

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

reddit.com

71–80 of 216 posts

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

#71
post #64
post #8

Earlier quoted context omitted.

Your approach works better than backtick expansion, since it won't run into 'command line too long' issues; but it will still break on "weird" file names (e.g., file names with spaces in them). The correct way to do this is find . -name *.java -print0 | xargs -0 cat | wc -l

xargs can still run you into the 'too many args' issue. You'll want to use this: --max-args=max-args -n max-args Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will exit.

Only if there's a bug in your xargs. POSIX states:

The xargs utility shall limit the command line length such that when the command line is invoked, the combined argument and environment lists (see the exec family of functions in the System Interfaces volume of POSIX.1-2008) shall not exceed {ARG_MAX}-2048 bytes

so you should never run into the ARG_MAX limit.

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

#72
post #65
post #52

Earlier quoted context omitted.

Many comments seem to be shell- and bash-related. Perhaps the thread exposes how difficult to read the bash manpage is. On my system, the bash 4.1 manpage is 41026 words long, or about 80 pages. Manpages are most useful to me when they are short and to-the-point so I can find what I am looking for before I lose interest in skimming through an 80 page book.

How would you make the bash manpage short and to the point, considering the complexity that it implements?

While it doesn't fix the issue, zsh's man page is divided into different sections, which at least alleviates it.

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

#75
post #24

That reddit thread is delightful, because it is full of wonderful commands that I didn't know, or rarely use, or had forgotten. But it's also terrifying, because it exposes how many people will post questions before using man.

Quite often asking a good question to knowledgeable people can give you a tested and well working solution in a fraction of the time it would take to search and try and fail and try a working solution by yourself.

For me, often asking the question and then still trying to figure it out myself worked well. Often I come to a solution, post it (IRC) and then later some guru responds with "try this instead" or "with that flag it could do some thing better".

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

#76
post #52
post #24

That reddit thread is delightful, because it is full of wonderful commands that I didn't know, or rarely use, or had forgotten. But it's also terrifying, because it exposes how many people will post questions before using man.

Many comments seem to be shell- and bash-related. Perhaps the thread exposes how difficult to read the bash manpage is. On my system, the bash 4.1 manpage is 41026 words long, or about 80 pages. Manpages are most useful to me when they are short and to-the-point so I can find what I am looking for before I lose interest in skimming through an 80 page book.

I'm baffled all the time by the lack of clear examples on many manpages.

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

#77
emacs --daemon

(or after you start emacs, M-x server-start). This starts up the emacs server, so that it preserves your open files, and you can start new emacs instances immediately with emacsclient. (I actually symlink emacsclient to vi since it loads as fast as vi, which was one of the weakest points of emacs for me.)

Very useful if you are using a remote box (like a vps) as your dev environment.

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

#78
post #45

Actually the new top comment blew me away. I'm in the 20 year veteran category and was also oblivious. Quoted: disown - bash built in. You know how you always start that mega long rsync in an ssh session from your laptop and then realize you have to go offline halfway through? You forgot to start it in screen or nohup, didn't you? You can pause it (ctrl+z), background it (bg), and then disown it so it is protected fr…

disown is great. However, I don't know if it's possible to start up a new shell, then bring back that process to the foreground. 'jobs' will return no entries, and fg doesn't take a PID parameter. Any ideas? It would be brilliant if that were possible with bash alone.

reptyr: https://github.com/nelhage/reptyr is Linux specific & involves a fairly gruesome abuse of ptrace() to attach a running process to your current pty. It won't put the process in the shell jobs list though.

There's also retty: http://pasky.or.cz/dev/retty/ but again it's not a complete solution.

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

#80
post #70
post #65

Earlier quoted context omitted.

How would you make the bash manpage short and to the point, considering the complexity that it implements?

By reducing the needless complexity that it implements. The purpose of a Unix shell is to interpret a simple language wrapping syscalls so the user can easily give instructions to the kernel. There are several such shells whose source code is smaller than the bash manpage. 13 pages of the 80 page manual are devoted to readline and programmable completion. Readline and programmable completion could be removed from the…

  $ man bash | wc -l
  5351
  $ 9 man rc | wc -l
  496
You may want to check out the `rc' shell from Plan 9 (carried over from latest UNICes). Simple, elegant. Available for linux via http://swtch.com/plan9port/ Manpage at http://swtch.com/plan9port/man/man1/rc.html
Post reply on HN