最近在windows 上装了curl 和 freesshd 把windows 当Linux用,不亦乐乎,记录下这几天的心得。
下载windows curl 的地址: 看来就是URL里面传了几个参数而已。
https://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=-&ver=*&cpu=x86_64
1. 根据字符串查询进程
-
相当于linux 下的ps -ef |grep -i java
-
tasklist |findstr /I java
-
其实findstr 很复杂, 请看
-
C:\Users\Administrator>findstr -?
Searches for strings in files.
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L Uses search strings literally.
/R Uses search strings as regular expressions.
/S Searches for matching files in the current directory and all
subdirectories.
/I Specifies that the search is not to be case-sensitive.
/X Prints lines that match exactly.
/V Prints only lines that do not contain a match.
/N Prints the line number before each line that matches.
/M Prints only the filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/OFF[LINE] Do not skip files with offline attribute set.
/A:attr Specifies color attribute with two hex digits. See "color /?"
/F:file Reads file list from the specified file(/ stands for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of directories
strings Text to be searched for.
[drive:][path]filename
Specifies a file or files to search.
Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.
Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\
xyz\> Word position: end of word
For full information on FINDSTR regular expressions refer to the online Command
Reference.
看起来windows 下的find 和findstr 也不弱啊。
-
C:\Users\Administrator>help find
-
Searches for a text string in a file or files.
-
-
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
-
-
/V Displays all lines NOT containing the specified string.
-
/C Displays only the count of lines containing the string.
-
/N Displays line numbers with the displayed lines.
-
/I Ignores the case of characters when searching for the string.
-
/OFF[LINE] Do not skip files with offline attribute set.
-
"string" Specifies the text string to find.
-
[drive:][path]filename
-
Specifies a file or files to search.
-
-
If a path is not specified, FIND searches the text typed at the prompt
-
or piped from another command.
2. 重定向。
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version
-
#相当于
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version >con 2>con
-
#这个命令的输出吓了我一跳,原来java.exe -version 的输出居然是stderror.
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version >NUL
-
#2>nul 就可以将stderr 重定向到nul, 就是Linux 上的2 >/dev/null.
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version 2>NUL
-
#来个比较正常的重定向:
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version >1.txt
-
#下面来重定向两个文件
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version >3.txt 2>&1
-
"c:\Program Files\IBM\Director\jre\bin\java.exe" -version 2>4.txt
-
#打印下txt文本的内容
-
type 4.txt
-
#比较下两个文本的异同,有点像linux 下的diff
-
C:\Users\Administrator>fc 4.txt 3.txt
-
Comparing files 4.txt and 3.TXT
-
FC: no differences encountered
-
#最后查看上一条命令的返回值,就是linux下的echo $?
-
echo %ERRORLEVEL%
-
#但是在bat脚本里面就不能这么用,要参考这个https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/setlocal.mspx?mfr=true
3. 在windows 上安装freesshd ,然后通过paramiko 在windows 上执行命令,碰到了很多次这个错误。
-
Output: Unable to execute command or shell on remote system: Failed to Execute process
经过搜索下得知:要在命令前加上"cmd /c"
-
例如我在windows 上通过curl 下载的命令是这样:
-
r"curl -o c:\{0} -s -k -u {1}:{2} {3}".format(filename, user,pass,url)
-
改成:
-
r"cmd /c curl -o c:\{0} -s -k -u {1}:{2} {3}".format(filename, user,pass,url)
阅读(1476) | 评论(0) | 转发(0) |