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
答案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●›
╰─$