73

Normally in putty you can just select text to copy it, but I can't seem to select text with my mouse in htop.

Of course there's no right click menu to copy, ctrl+c doesn't work, and I didn't see any copy command in the help menu.

Is it possible to copy text in htop?

2
  • You can select and copy text in top, though you have to be quick before the display changes. I don't know what terminal handling is in htop, but as you observe it seems to preclude selecting and therefore copying. I tried Ctrl-z and reset the terminal, but this didn't help when I restarted the task with fg. So at the moment I conclude that the answer to your question is "no". I am not sure why you want to copy text, but screen capture ought to work as a means to save an instantaneous state.
    – AFH
    Commented Sep 10, 2014 at 22:01
  • Ctrl + C in terminal? This terminates the running process.
    – user198350
    Commented Apr 27, 2022 at 20:21

3 Answers 3

90

In my experience, holding Shift lets you select text in programs that have mouse support (of which htop is one, I assume).

3
  • 9
    It is "alt" under mac Commented Jan 2, 2017 at 11:17
  • 5
    One caveat, it can only copy visible text. It would still be useful to have a way to copy the command line from htop when it is much longer than the terminal width.
    – P-Gn
    Commented Nov 16, 2018 at 14:26
  • 2
    In my case it was fn key for MacOS 12.2 (Monterey), htop 3.1.2 that give me the ability to select text. Commented Feb 10, 2022 at 12:25
7

If it's a linux server I'd just use the ps -ef command and pipe it to grep. For instance if you wanted to check on a rsync command you'd do this:

ps -ef | grep rsync

And that would spit out any process with the word rsync in it. Though it always will include the grep search as well. To exclude that just run:

ps -ef | grep rsync | grep -v grep

This will exclude grep itself from the search results.

Remember, htop is great software, but it's not the best for grabbing really long strings of text. In that case use ps -ef

4

One approach to copy long lines from htop is the following:

step 1. Change the font size of your terminal to something very small (say 6pt).

step 2. Run htop and maximize window

step 3. Run your processes, switch to htop window and carefully do Ctrl + Shift + A to select everything, then release A and hit C (without releasing Ctrl + Shift). It might take some time to be able to do it (some of the times you might kill htop accidentally).

step 4. Open gedit or another text editor and Ctrl + V if the editor is a GUI or hit Ctrl + Shift + V if the editor opened on the terminal (for example nano).

1
  • magic operation : )
    – yurenchen
    Commented Mar 19, 2020 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .