0

When i run this command in Debian

sudo find . ! -name . -type d -or -type f 

It lists all the files in the current path, but not the directories, so I think I know what it does.

But what does the -name . part do?

All names in the directory? is this a valid use of -name? I don't see this documented in man find.

Also what is the -or doing here? I don't see it listing any directories when i run the command.

thanks

4
  • 1
    "but not the directories" – Are you sure? Create a subdirectory and try again. Jul 19, 2022 at 17:38
  • Yes, directories and subdirectories are not listed, only files.
    – Tlink
    Jul 19, 2022 at 21:38
  • @Tlink are you absolutely sure about that? On my machine with GNU find it will list both files and directories and their subdirectories, just as expected with the given options. Jul 20, 2022 at 0:56
  • You're right, GNU does, if you can try on a mac or a different shell, please confirm that you get different results.
    – Tlink
    Jul 20, 2022 at 18:05

1 Answer 1

1

Note the exclamation mark before the -name option, it is interchangable with the -not option. It will behave like a logical NOT and negate the following option.

In this case your command would search for all files and directories, starting from the current directory, with a name that is NOT ..

It basically does the same as find . -name "*" -type d -or -type f would do, with the exception that it won't print the current directory as a search result:

╭─user@machine ~/somedir ‹master●› 
╰─$ find . -name "*" -type d -or -type f               
.
╭─user@machine ~/somedir ‹master●› 
╰─$ find . ! -name . -type d -or -type f               
╭─user@machine ~/somedir ‹master●› 
╰─$ 

You must log in to answer this question.

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