Live data from Hacker News

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

reddit.com

91–100 of 216 posts

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

#91

This is useful for finding and killing a process. ps -A | grep some text in program name upon getting the pid kill -9 pid

Instead of kill -9 (a nuke), you can often get results with just kill, kill -INT or kill -HUP. (The advantage is that the "weaker" signals allow your runaway program to do some cleanup, but kill -9 doesn't.)

There's a nice write-up and a function automating attempts to run increasingly strong signals on this site: http://web.archive.org/web/20080610070315/http://sial.org/ho...

(Thank god for the wayback machine. That site was full of good Unix tips and tutorials, but it's gone now.)

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

#92

It's not a command but it is still useful. When you are typing a long command and you realize that you need to do other command or set of commands first, usually you type ctrl + c to cancel it. By default it does not save in the history. If you put # (comment the command) in front of the command (you can do it quickly with Ctrl + a #) and then you can use Ctrl + r to get it back. I'm sure there are other ways to save…

What I usually do in that situation is Ctrl + u (delete all the way back to the start of the line), then type the intermediate command, then Ctrl + y (place the deleted partial line back on the prompt, with my cursor at the end where it was).

This assume Emacs-style bindings for the shell.

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

#93
post #4

For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l

I was an avid find user until I discovered ack-grep. These days it's one of the first things I sudo apt-get install.

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

#94

It's not a command but it is still useful. When you are typing a long command and you realize that you need to do other command or set of commands first, usually you type ctrl + c to cancel it. By default it does not save in the history. If you put # (comment the command) in front of the command (you can do it quickly with Ctrl + a #) and then you can use Ctrl + r to get it back. I'm sure there are other ways to save…

I just put a random character instead of # to get "command not found".

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

#96
post #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…

> 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.

The pool of knowledgable people decreases with each question asked, especially if you're not making an effort to at least try to do it yourself.

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

#99
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.

disown -h will (reportedly) keep it under job control.

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

#100
post #36
post #33

Earlier quoted context omitted.

every developer should know sed and awk. it is amazing how many devs write cumbersome scripts or little programs to handle tasks that are built for sed and awk. my ~/bin folder has ~50 different little scripts that handle all sorts of small tasks.

I don't really know a lot about this stuff, but my understanding is that Perl was more or less replaced sed and awk.

awk (and to a lesser extent sed) is cleaner and easier to remember.
Post reply on HN