8

I have installed Debian 10 remotely on a server from a live netinstal iso USB over KVM, but then I encounter this strange problem:

# fdisk -l
bash: fdisk: command not found

However if I use /sbin/fdisk -l , the command executes with no issues.

I'm wondering what has caused this and how can I fix it?

3
  • What is the value returned by echo $PATH? Commented Mar 31, 2020 at 10:53
  • You've been told how to fix it, but what caused it is that /sbin is for system commands that regular users don't normally have the rights to execute (like fdisk, for example), so /sbin isn't included in regular users' PATHs by default. Commented Mar 31, 2020 at 10:56
  • Try sudo fdisk -l, if not work then add to the PATH variable :/sbin/fdisk Commented Oct 11, 2022 at 15:33

3 Answers 3

13

You have to add /sbin to your PATH:

vagrant@stretch:~$ PATH="/sbin:$PATH"
vagrant@stretch:~$ command -v fdisk
/sbin/fdisk

And use fdisk with sudo:

vagrant@stretch:~$ sudo fdisk  -l
Disk /dev/sda: 19.8 GiB, 21265121280 bytes, 41533440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa0fd0b1a

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 39438335 39436288 18.8G 83 Linux
/dev/sda2       39440382 41531391  2091010 1021M  5 Extended
/dev/sda5       39440384 41531391  2091008 1021M 82 Linux swap / Solaris
1

Is /sbin in your path? Run echo $PATH to check. Often /sbin is a symlink to /usr/bin so check if that is also in the path. See this question for how to modify the path.

1

In my case, Debian 11 Bullseye, fdisk wasn't installed at all. I run this command to check if it was installed or not:

apt policy fdisk

Which returned:

fdisk:
  Installed: (none)
  Candidate:  2.36.1-8+deb11u2
  Version table:
     2.36.1-8+deb11u2 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages
        500 http://security.debian.org bullseye-security/main amd64 Packages

Then I installed it with:

apt install fdisk

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.