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.

I've used DOS for 22 years but I'm new to Linux. So in Linux, when I execute

ls -R *.zip

Why do I receive:

ls: *.zip: No such file or directory

When I'm at the top of a huge folder and file tree? Alternatively, how do I do

Dir /s *.zip

In Linux?

share|improve this question
    
I hear that this is possible in the zeal shell (with similar syntax): ls **/*.zip –  Ярослав Рахматуллин Nov 27 '12 at 14:50
add comment

2 Answers

up vote 2 down vote accepted

Try ls -R|grep .zip or for full paths:

find .  -name '*.zip'

This will find any files ending in .zip in current directory and any subdirectories.

It seems a little longer but is much more powerful than the dir /s *.zip way of windows.

share|improve this answer
    
Okay - I getcha. I sometimes use dir /s/a/b|find /i "blah" which is conceptually the same. –  Luke Puplett Nov 27 '12 at 12:42
    
Exactly; grep matches a string, or if you use "grep -E 'blah'" then you can use regular expressions in it –  Justin Nov 28 '12 at 0:09
add comment

To expand a bit further on the above answer, on Linux, the wildcards are expanded by the shell, which means that the shell will call the command with a list of matching file names as arguments. And the shell only looks in the current directory for matching files (or in whatever directory you specify prior to the wildcard). For example, a command such as:

ls *.zip

will actually translate into:

ls file1.zip file2.zip file3.zip

And, if there are no .zip files in the current directory, the literal file name *.zip gets passed to the command, in which case it doesn't fine a file called *.zip. (A * is a legal character in a Unix/Linux file name, btw). Now if you don't want the shell to expand the wildcards, but instead if you want the wildcard passed directly to the command you are calling, you will have to enclose it in quotes. This has an interesting effect, in that a command such as:

find . -name *.zip

will give the expected results if you have no .zip files in your current directory (the find command sees *.zip). But if you do have one or more .zip files in the current directory, what gets executed is:

find . -name file1.zip file2.zip

which won't find any matches in any subdirectories (unless they happen to be named exactly file1.zip or file2.zip, etc). So the moral of the story is, when using find, make sure to use quotes around any file name with wildcards.

share|improve this answer
    
Wow. Thanks Derek. –  Luke Puplett Nov 29 '12 at 21:00
add comment

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.