bash: file: command not found. How to install file

last updated in Categories , , , ,

I am running file /usr/sbin/arp command on a Debian VM minimal but getting an error that read as:
bash: file: command not found
How do I fix this error on a Debian or Ubuntu Linux system? How can I install file command on Linux cloud?

Introduction: The file command determines file type on Linux and Unix-like systems. The file command tests each argument in an attempt to classify it. There are three sets of criteria, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed. For example, one can use the file command to find out whether the given file is a shell or Perl script.

Fix bash: file: command not found error

Type the following command to find out if /bin/ls is a shell script or not?
file /bin/ls
Sample outputs:

bash: file: command not found

Try to locate the file with type command/command command:
$ type -a file
$ command -v file

Display your PATH settings on Linux with help of echo command:
$ echo "$PATH"

Debian / Ubuntu Linux file command not found

Getting rid of “-bash: file: command not found” is easy. All you have to do is search for file package as follows using the apt command:
apt info file

Package: file
Version: 1:5.35-4+deb10u1
Priority: standard
Section: utils
Maintainer: Christoph Biedl 
Installed-Size: 105 kB
Depends: libc6 (>= 2.4), libmagic1 (= 1:5.35-4+deb10u1), zlib1g (>= 1:1.1.4)
Homepage: https://www.darwinsys.com/file/
Download-Size: 66.4 kB
APT-Sources: http://security.debian.org/debian-security buster/updates/main amd64 Packages
Description: Recognize the type of data in a file using "magic" numbers
 The file command is "a file type guesser", a command-line tool that
 tells you in words what kind of data a file contains.
 .
 This package contains the file program itself.

N: There is 1 additional record. Please use the '-a' switch to see it

How to install file on a Debian or Ubuntu Linux

Run the following apt command/apt-get command:
sudo apt update && sudo apt upgrade
sudo apt install file

bash: file: command not found on Linux
Now error “bash: file: command not” must disappear from your system.

How do I use file command?

The syntax is:
file /path/to/file
file [options] /path/to/file

Examples

file /bin/ls
file /usr/sbin/adduser
file bin/mk.newsletter

How to install and use file command on a Debian and Ubuntu Linux
Do not prepend filenames to output lines:
file -b /bin/date
Sample outputs:

ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=731c2a7a56b2d07e67ac99b4960ec700b3faad68, for GNU/Linux 3.2.0, stripped

How to look inside compressed file

file -z file.zip

Getting help

Type the following command
man file
file --help

Sample help:

Usage: file [OPTION...] [FILE...]
Determine type of FILEs.
 
      --help                 display this help and exit
  -v, --version              output version information and exit
  -m, --magic-file LIST      use LIST as a colon-separated list of magic
                               number files
  -z, --uncompress           try to look inside compressed files
  -Z, --uncompress-noreport  only print the contents of compressed files
  -b, --brief                do not prepend filenames to output lines
  -c, --checking-printout    print the parsed form of the magic file, use in
                               conjunction with -m to debug a new magic file
                               before installing it
  -e, --exclude TEST         exclude TEST from the list of test to be
                               performed for file. Valid tests are:
                               apptype, ascii, cdf, compress, elf, encoding,
                               soft, tar, json, text, tokens
  -f, --files-from FILE      read the filenames to be examined from FILE
  -F, --separator STRING     use string as separator instead of `:'
  -i, --mime                 output MIME type strings (--mime-type and
                               --mime-encoding)
      --apple                output the Apple CREATOR/TYPE
      --extension            output a slash-separated list of extensions
      --mime-type            output the MIME type
      --mime-encoding        output the MIME encoding
  -k, --keep-going           don't stop at the first match
  -l, --list                 list magic strength
  -L, --dereference          follow symlinks (default if POSIXLY_CORRECT is set)
  -h, --no-dereference       don't follow symlinks (default if POSIXLY_CORRECT is not set) (default)
  -n, --no-buffer            do not buffer output
  -N, --no-pad               do not pad output
  -0, --print0               terminate filenames with ASCII NUL
  -p, --preserve-date        preserve access times on files
  -P, --parameter            set file engine parameter limits
                               indir        15 recursion limit for indirection
                               name         30 use limit for name/use magic
                               elf_notes   256 max ELF notes processed
                               elf_phnum   128 max ELF prog sections processed
                               elf_shnum 32768 max ELF sections processed
  -r, --raw                  don't translate unprintable chars to \ooo
  -s, --special-files        treat special (block/char devices) files as
                             ordinary ones
  -C, --compile              compile file specified by -m
  -d, --debug                print debugging messages

Conclusion

You learned how to install and use file command on a Debian or Ubuntu Linux system when you get an error “bash: file: command not”. You can download file command here.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive