我只是想知道如何使 MEMUSAGE 列按降序或升序排列。我在网上搜遍了,还是没有找到答案,我得到的最接近的一点是:
tasklist | sort
但是当我尝试使用 /m 进行排序时...:
tasklist | sort /m
Invalid switch.
感谢您的帮助。
C:\> tasklist | sort /R /+58
神奇数字
58
取决于你的输出。58
列中的字符对文件进行排序(不保证!)。
注意: 我还需要按“内存使用情况”列对任务列表进行排序。 当按第n列排序不友好时,我有点累,它是n个字符
在我的电脑上,“MemUsage”栏是第68栏,我必须将其粘贴到记事本中以帮助正确计算。这是命令行:
tasklist | sort /R /+68
在管道传送到 SORT 之前,启用 TASKLIST 中的 /NH 选项。这会抑制与排序混淆的表头。
TASKLIST /NH | SORT
实际上,您所需要做的就是输入以下内容:
tasklist | sort (This will sort the list items in ascending order)
tasklist | sort /R (This will sort the list items in descending order)
如果您输入:排序/?您可以看到 /R 按降序列出项目的位置,详细信息请参见下文:
C:\windows\system32>sort /?
SORT [/R] [/+n] [/M kilobytes] [/L locale] [/REC recordbytes]
[[drive1:][path1]filename1] [/T [drive2:][path2]]
[/O [drive3:][path3]filename3]
/+n Specifies the character number, n, to
begin each comparison. /+3 indicates that
each comparison should begin at the 3rd
character in each line. Lines with fewer
than n characters collate before other lines.
By default comparisons start at the first
character in each line.
/L[OCALE] locale Overrides the system default locale with
the specified one. The ""C"" locale yields
the fastest collating sequence and is
currently the only alternative. The sort
is always case insensitive.
/M[EMORY] kilobytes Specifies amount of main memory to use for
the sort, in kilobytes. The memory size is
always constrained to be a minimum of 160
kilobytes. If the memory size is specified
the exact amount will be used for the sort,
regardless of how much main memory is
available.
The best performance is usually achieved by
not specifying a memory size. By default the
sort will be done with one pass (no temporary
file) if it fits in the default maximum
memory size, otherwise the sort will be done
in two passes (with the partially sorted data
being stored in a temporary file) such that
the amounts of memory used for both the sort
and merge passes are equal. The default
maximum memory size is 90% of available main
memory if both the input and output are
files, and 45% of main memory otherwise.
/REC[ORD_MAXIMUM] characters Specifies the maximum number of characters
in a record (default 4096, maximum 65535).
/R[EVERSE] Reverses the sort order; that is,
sorts Z to A, then 9 to 0.
[drive1:][path1]filename1 Specifies the file to be sorted. If not
specified, the standard input is sorted.
Specifying the input file is faster than
redirecting the same file as standard input.
/T[EMPORARY]
[drive2:][path2] Specifies the path of the directory to hold
the sort's working storage, in case the data
does not fit in main memory. The default is
to use the system temporary directory.
/O[UTPUT]
[drive3:][path3]filename3 Specifies the file where the sorted input is
to be stored. If not specified, the data is
written to the standard output. Specifying
the output file is faster than redirecting
standard output to the same file.
这是在 Windows 2008 服务器和 Windows 7 SP1 上测试的
按 PID 编号对结果进行排序:
C:\> tasklist /NH | sort /R /+29
/NH 用于“无标题” - 它跳过任务列表视图的标题
/R 用于反向排序(降序)
/+29 表示反向排序顺序从第 30 个字符开始(因此在第 29 个字符之后)
这适用于服务器、家庭或专业版本上的所有 Windows CMD 提示符。
也可以使用长护发素:
任务列表 |排序/内存/类型/R/+35
非常整齐地按进程的内存使用情况排序
(注意:你不能使用两种类型的搜索,这不仅仅是像任务管理器更改选项一样,Roger脚本最初可以在上面工作,但在使用这个矿井后将不再工作(再次是Roger类型)(*年轻版本类型)脚本。
:)这是 Peer1 DC /Dell / Windows Vista 类型的脚本。
# sort by Memory Usage ascending, avoid header lines with /NH:
tasklist /NH | sort /+65
# sort by Memory Usage descending:
tasklist /NH | sort /R /+65
注意:数字可能不同,只是从左边开始的数字(见下文)。排序
sort /?
想象有一个简单的文本文件“txt”,看看从字符排序如何适用于以下 4 个命令(“/+1”是第一个字符,因此不需要指定它)
"type txt" | "type txt | sort" | "type txt | sort /+2" | "type txt | sort /+3"
============================================================================
c4D-test | a3B-test | d1C-test | b2A-test
d1C-test | b2A-test | b2A-test | a3B-test
b2A-test | c4D-test | a3B-test | d1C-test
a3B-test | d1C-test | c4D-test | c4D-test
| | |
| sorted from start | sorted from 2nd character | sorted from 3rd character
对任务列表进行排序
tasklist /FI "memusage gt 10000"
想象一下你有这样的输出:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
Registry 96 Services 0 10,656 K
winlogon.exe 580 Console 1 12,180 K
...
这是一个具有相等缩进的表格,因此我们可以使用“排序”来指定列的开头。查看
标题行(标题名称下方),或者更重要的是,标题行之间的空格(======),这些空格指示新列开始的位置,我们需要计算从左边到该点的字符数,并用它来排序。
从左边开始计算字符的示例:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
| | | | |
|(1th character) |(27th) |(36) |(53) |(65)
12345678901234567890123456789012345678901234567890123456789012345
0 1 2 3 4 5 6 (illustrate tenths)
每列从某个位置开始:
1 = Image Name
27 = PID
36 = Session Name
53 = Session#
65 = Mem Usage
现在只需将数字与要排序的列相匹配,如下所示:
tasklist /NH /FI "memusage gt 1000" | sort
tasklist /NH /FI "memusage gt 1000" | sort /+27
tasklist /NH /FI "memusage gt 1000" | sort /+36
tasklist /NH /FI "memusage gt 1000" | sort /+53
tasklist /NH /FI "memusage gt 1000" | sort /+65
要反转排序顺序,只需添加 /R
tasklist /NH /FI "memusage gt 1000" | sort /R
tasklist /NH /FI "memusage gt 1000" | sort /R /+27
tasklist /NH /FI "memusage gt 1000" | sort /R /+36
tasklist /NH /FI "memusage gt 1000" | sort /R /+53
tasklist /NH /FI "memusage gt 1000" | sort /R /+65
对任何其他正确缩进的列表进行排序
ipconfig /all | findstr /I "ipv4"
IPv4 Address. . . . . . . . . . . : 192.168.1.59(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.10(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.20(Preferred)
| |
|(1th character) |(36th character)
123456789012345678901234567890123456
0 1 2 3 (illustrate tenths)
在这种情况下,我们没有标题行,但仍然可以排序:
# 1 = Description
# 36 = IPv4 Address
# sort by ip address
ipconfig /all | findstr /I "ipv4" | sort /+36
IPv4 Address. . . . . . . . . . . : 192.168.1.10(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.20(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.59(Preferred)
我想补充一点,如果他们想按升序列出内存列,则如下所示:
tasklist | sort /+58
/R 告诉 sort 按降序排列项目。