English 中文(简体)
Unix 查找命令 - 等效. net 文件. existists and generotty. exists in Unix 中
原标题:Unix find command - Equivalent of .net File.Exists and Directoty.Exists in Unix
  • 时间:2012-05-22 12:48:34
  •  标签:
  • unix
  • find

在我们的. net 应用程序中, 我们必须对 Unix 系统运行文件操作命令。 我正在尝试等同文件. exists 和 目录. exists 。

使用 net 中的 ssh, 至今为止工作的方式如下:

只查找匹配名的文件 :

find /folder/subfolder -maxdepth 1 -type f -iname test.mov

只查找匹配名称的目录 :

find /folder/subfolder -maxdepth 1 -type d -iname test

问题 - 能否在不完全分道扬镳的情况下完成以上行动?

分割路径并不重要,但现有的生产服务只接受运行命令和路径。

最佳回答
test -d  /path/to/directory_name  
[ -d /path/to/directory_name  ] 

返回真或假 - 即目录。

test -f /path/to/filename
[ -f /path/to/filename ]  

对文件相同

您可以使用这些构造来返回 ok 或 ok 。

[ -f /path/to/filename ]  && exit 0 || exit 1

找不到指定目录或文件时不返回错误

问题回答

暂无回答




相关问题
Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Function to create the array by reading the file

I am creating scripts which will store the contents of pipe delimited file. Each column is stored in a separate array. I then read the information from the arrays and process it. There are 20 pipe ...

Compare characters at the end of the string C++

This program supposed to find command line arguments entered on Unix which ends with “.exe”. For some reason it doesn t work. Here is the code: int main( int argc, char* argv[] ) { for ( int ...

Batch Job Dependencies Using Open Source/Free Software

I run a large data warehouse plant where we have a lot of nightly jobs running concerruently however many have dependencies on a extract or data load process before they start. Currently we use an ...

Writing application for both Unix and Windows

I ll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE_UNIX). But in a year it will be ported to Windows. I ll write it in ANSI C and/or SH-script. When it runs on Windows ...

Development Environment in Windows [closed]

What are your recommendations for setting up a development environment in Windows, especially when not using an IDE. I am attempting to familiarize myself with Windows, and I feel a bit lost. What ...

热门标签