Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 * ?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Use just the following

file ./*

All is needed.

share|improve this answer
1  
Simple, as expected ;-) –  Aubin Aug 20 '13 at 18:59

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.)

share|improve this answer

Simple:

file -- *

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.