Skip to main content
Explain why the file ownership is changed.
Source Link
Stephen Kitt
  • 483.2k
  • 60
  • 1.2k
  • 1.4k

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root (to ensure the update can be done safely, less writes the history to a new temporary file, then renames it; this causes the original file’s ownership to be lost).

If you want to avoid this, you can tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

Another option is to temporarily disable the search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root.

If you want to avoid this, you can tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

Another option is to temporarily disable the search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root (to ensure the update can be done safely, less writes the history to a new temporary file, then renames it; this causes the original file’s ownership to be lost).

If you want to avoid this, you can tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

Another option is to temporarily disable the search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

Typo, reorder.
Source Link
Stephen Kitt
  • 483.2k
  • 60
  • 1.2k
  • 1.4k

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root.

If you want to avoid this, you can tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

Another option is to temporarily not store itsdisable the search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

Another option is to tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root.

If you want to avoid this, you can tell less to temporarily not store its search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

Another option is to tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root.

If you want to avoid this, you can tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ... 

Another option is to temporarily disable the search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

Source Link
Stephen Kitt
  • 483.2k
  • 60
  • 1.2k
  • 1.4k

This is normal.

sudo less ... 

runs less as root, but without changing the home directory. Running searches causes the search history to be updated in ~/.lesshst, which changes the ownership of the file to the current user, root.

If you want to avoid this, you can tell less to temporarily not store its search history:

sudo LESSHISTFILE=- less ... 

This does however mean that you won’t be able to use the stored search history (/ followed by , or even n without specifying a search string).

Another option is to tell less to use root’s history, by telling sudo to set the HOME variable to point to root’s home directory:

sudo -H less ...