3

The contents of a directory:

$ ls -l
total 122639
-rw-r--r-- 1 125578080 Aug 20 17:47 - Diana Krall, Stan Getz & Oscar Peterson.7z
drwxr-xr-x 4      4096 Aug 20 18:02 Java

I wish to use the file command in this directory, where a lot of various files are copied

$ file *

The result I expect:

$ file *
- Diana Krall, Stan Getz & Oscar Peterson.7z: 7-zip archive data, version 0.3
java: directory

The result I get:

$ file *
file: illegal option --
file: illegal option -- D
file: illegal option -- a
file: illegal option -- a
file: illegal option --
file: illegal option -- K
file: illegal option -- a
file: illegal option -- l
file: illegal option -- l
file: illegal option -- ,
file: illegal option --
file: illegal option -- S
file: illegal option -- t
file: illegal option -- a
file: illegal option --
file: illegal option -- G
Usage: file [-bchikLNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
            [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
       file -C [-m magicfiles]
       file [--help]

I can spell out the filenames and escape things manually, but I want to use *:

$ file -- -\ Diana\ Krall\,\ Stan\ Getz\ \&\ Oscar\ Peterson.7z
- Diana Krall, Stan Getz & Oscar Peterson.7z: 7-zip archive data, version 0.3

$ file java
java: directory

How can I escape or protect * ?

3 Answers 3

5

Use just the following

file ./*

All is needed.

1
  • 1
    Simple, as expected ;-)
    – Aubin
    Aug 20, 2013 at 18:59
4

You can tell file (and most other Unix command line tools) to stop looking for option switches by passing them -- as an argument. Thus, the following will work:

file -- *

(Of course, val0x00ff's suggestion of file ./* will work too, but will cause the ./ to appear prepended to the file names in the output.)

1

Simple:

file -- *

-- Means end of options of command. Because file command think - in file name is part of your option.

You must log in to answer this question.

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