How to use the "Which" command in Windows Linux

Source: Internet
Author: User

In Linux, there is a command called which, which can find and display the directory where a command is located in Path.

In Linux:
[Adam @ I ase adam] $ which ls
/Bin/ls
[Adam @ I ase adam] $ which rm
/Bin/rm has a where.exe in the Resource Kitts of NT. It also has the same effect, but Resource Kit charges fees. Here we can make a batch file to implement this function.

Use NotePad to edit a which. bat file and store it in the Wi t directory or another Path variable. The content of the batch processing file is as follows:

@ Echo off Rem check command line parameters
If {% 1 }={} goto: Usage
For % I ({/{-) do if {% 1 }=%% I ?} Goto: Usage % I
Echo.: Rem checks the current directory to see if the file exists.
For % I (% 1) do if exist % ~ Nx % I (
Echo % ~ Fi
Goto: EOF
): Rem checks the file in Path.
For % I (% 1) do (
If exist % ~ $ PATH: I (
Echo % ~ $ PATH: I
) Else (
Echo Error: % 1 is not in the path !!!
Goto: Usage
)
)
Goto: EOF
: Usage
Echo.
Echo WHICH quot; filename"
Echo.
Echo input file description, returns the full path of the file!
Echo.

Let's test our program:

Microsoft Window 2000 [Versio 5.00.2195]
(C) Copyright 1985-1998 Microsoft Corp. C:> which WHICH quot; filename "input file description, return the full path of the file!
C:> which cmd.exe C: WI tsystem320000.exe C:> OK, test passed!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.