当前位置:网站首页>[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
2022-06-25 07:37:00 【dssgresadfsrgre】
One 、 Directory operation command
1.1 Create and delete directories ——md、rd、xcopy
- New folder :
md test( The effect is the same MKDIR test, Notice that it's not mk test)
Delete directory
:rd test- duplicate catalog :xcopy %Directory% %Directory2%
1.2 Set and use directory variables ——set
- Set the directory variable :set Directory=F:\test;
- Set the file path variable :set filepath=test1\file.exe
- Call the directory variable :%Directory%.
- After setting variables , Any variable needs to be used with other instructions . For example, collocation del Command to use ,del "%Directory%\%filepath%" Equivalent to del "F:\test\test1\file.exe".
1.3 Show directory structure / File tree ——dir、tree
1.3.1 Display file / Directory listing :dir
stay win10 Systematic cmd Window , To display the files in the current directory 、 Folder information , It can be used dir command .
To display the information under the target directory , You can switch the working directory first (cd Command or other means ) For the target directory , And then use dir.
Or directly execute the order 【dir Target directory 】, For example, I want to display the file directory information of the download folder of Baidu online disk .
linux In the system , To display files in a directory ( clip ) list , It can be used ls command , You can also use it dir command .
1.3.2 Show tree level directory structure ——tree
Let's continue with windows in cmd Window tree Instructions .
Windows+R Input cmd command , We type directly in the window help tree, You can see the help information :
- tree : Displays the tree structure of all child folders under the current directory ( Exclude files ).
- tree D:\ChromeCoreDownloads\test : Displays the tree structure of all child folders under the specified directory ( Exclude files ).
- tree D:\ChromeCoreDownloads\test /f : Displays the tree structure of all child folders under the specified directory ( Including documents ).
- tree D:\ChromeCoreDownloads\test /f /a: When the author tests , Not found plus /a And no addition /a The obvious difference .
- tree D:\ChromeCoreDownloads\test /f > tree.txt: The tree structure of all child folders under the specified directory ( Including documents ) The information is written to... In the current directory tree.txt file .
- tree D:\ChromeCoreDownloads\test /f > D:\ChromeCoreDownloads\test\tree.txt: The tree structure of all child folders under the specified directory ( Including documents ) The information is written to... In the specified directory tree.txt file .
tips:windows Under the tree Command function is not powerful enough , Can download git tree shell To supplement this function , For example, if there are too many files , You can only display the folder hierarchy information down to the specified directory .
1.4 Find a file or folder in the directory
dir The general usage of is to find which files or folders are in a directory , more “ Fee computer ” Is used to find a file with a specified name in a directory ( clip ) Where are they distributed 、 What are the sizes 、 What is the total number .
For example, I want to find out how many are under the download folder of Baidu online disk demo.bat file , You can execute the command first 【cd /d D:\BaiduNetdiskDownload】 To switch the current working directory , Then execute the order 【dir demo.bat】, The final result is shown in the figure below .
Very strange , It is also possible to find the number of folders with specified names under a directory , But we can't do it in practice .
1.5 Toggle directory , Enter the specified folder ——cd or chdir
The title is clear enough ,cd Command and chdir Commands are completely equivalent .
Print cd Command help information , We can know cd The command is used to display the current working directory and switch working directories .
C:\WINDOWS\system32>cd /?
Display the current directory name or change the current directory .
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. Specify to change to parent directory .
type CD drive: Displays the current directory on the specified drive .
Type only without parameters CD, The current drive and directory are displayed .
Use /D switch , In addition to changing the current directory of the drive ,
You can also change the current drive .
If command extension is enabled ,CHDIR Will change as follows :
The current directory string will be converted to use the case on the disk name . therefore ,
If the case on the disk is so ,CD C:\TEMP The current directory will be set to
C:\Temp.
CHDIR The command does not treat spaces as separators , Therefore, it is possible to change the directory name to a
Subdirectory names with spaces but without quotes . for example :
cd \winnt\profiles\username\programs\start menu
Same as the following :
Please press any key to continue . . .
1.5.1 Direct execution without parameters 【cd】, The current working directory will be returned .
Some people may think this order is mentally retarded , Obviously, you can see , Why should there be ?
Actually in echo When echo status is off , The working directory is not displayed in cmd On the window .
1.5.2 Do not switch disks , Only on the current disk “ Wandering around ”
- Enter folder :
cd \test1\test2
( Get into test2 Folder ) - Return to root ( Disk directory ):
cd \
- Go back to the parent directory :
cd ..
1.5.3 Switch disks , You need to turn the wheel first
If the target path you want to switch is different from the disk where the current working directory is located , Then you need to switch disks .
The way 1: Execute the switch disk command first ( for example D The disk corresponds to the command 【d:
】), And then use cd command ( Enter, for example d Disk Baidu download folder BaiduNetdiskDownload, Carry out orders 【cd /BaiduNetdiskDownload】 or 【cd d:/BaiduNetdiskDownload】) Enter target directory .
The way 2: Directly with parameters /d Execute the command including the full directory path , For example, you want to enter the target folder d:/BaiduNetdiskDownload, It can be executed 【cd /d d:/BaiduNetdiskDownload】 command .
Be careful 1, The way 2 Medium /d The parameters are fixed , No matter which plate it is /d. Not for the target directory e:/BaiduNetdiskDownload, You should execute the order 【cd /e d:/BaiduNetdiskDownload】, This is wrong !
Be careful 2, command 【cd d:】 Is unable to switch disk to D Discoid , Although it will output a d:, It does not mean that the working directory is switched 、.
On it cd Command to switch working directory , Actually, it's more troublesome , The most convenient method is to enter the target folder in the explorer , Execute... In the address bar cmd that will do .
Two 、 File external operation ——move、copy、del or erase、rename or ren
2.1 Moving files ——move
Print move Command help information , Carry out orders 【move /?】.
We can find out ,move The command can not only remove files from the path A Move to path B, And you can rename the file during the move , You can even rename a folder .
If , In my computer 【D:\BaiduNetdiskDownload】 Contents and 【D:\D-desktop】 There's one in each category demo.bat file .
If I want to 【D:\BaiduNetdiskDownload】 The files in the directory are moved to 【D:\D-desktop】 Catalog , I can execute the following commands 【move demo.bat D:\D-desktop】, then cmd Whether to overwrite... Is prompted in the window , I'll do it again y, The move and overwrite succeeded .
If I also want to rename this file 【demo1.bat】, I can execute orders 【move demo.bat D:\D-desktop\demo1.bat】.
In summary , If you are moving a file , Do not want to rename , Then the target path does not need to include the file name ( There is no need to keep the original file name ); If you want to rename , You need to include the file name
Parameters /y and -y It means : If you do not specify one of these two parameters , The default is to prompt in the direct command 、 Do not prompt in the batch file , If specified as /y, Do not prompt for direct coverage , If specified as -y, They all prompt , You can manually select whether to overwrite .
2.2 Copy file ——copy
Print copy Command help information , Carry out orders 【copy /?】.
copy The command of is similar to move Orders are the same .
If you just copy files to another directory , Without changing the name , There is no need to include the file name on the target path , For example, order 【copyF:\directory1\test.txt D:\directory2】.
If you need to copy to another directory , Rename it , You need to include the file name in the target path , For example, order 【copyF:\directory1\test.txt D:\directory2\test1.txt】.
2.3 Delete file ——del or erase
del Command and erase Command is equivalent to ; But after the command extension function is enabled , Only available erase command .
(1) Print del Command help information , Carry out orders 【del /?】.
(2) If we want to delete a file , Direct command execution 【del filepath】,filepath Is the full path .
such as , We want to delete the... Under the download folder of Baidu online disk demo.bat file , You can execute orders 【del D:\BaiduNetdiskDownload\demo.bat】
Be careful , Although no feedback results indicate that it has been deleted , But it has been deleted successfully .
(3) If you want to delete a folder , We can execute orders 【del directory_path】, It is recommended that the folder path be set completely .
Suppose that D There is a test Folder , There's another one in it demo.bat, Can execute orders 【del D:\test】, Then reuse y Reply to confirm deletion .
Order executed , We can find that the files in the directory are missing , But the folder itself still lingers on the computer .
I guess ( Rigorous enough ...):del The command can only delete files in the specified directory and subdirectories
I'm in again test A... Is created in the folder test1 Folder , Then order 【del D:\test】 It's an experiment , If so !
linux In the system , Delete file / The directory directive is rm.
grammar :rm [ Options ]
- -d: Directly delete the hard connection data of the directory to be deleted into 0, Delete this directory ;
- -f: Force deletion of files or directories ;
- -i: Ask the user before deleting an existing file or directory ;
- -r or -R: Recursive processing , Process all files in the specified directory together with subdirectories ;
- –preserve-root: No recursive operation on the root ;
- -v: Display the detailed execution process of the instruction .
2.4 Rename file ——rename or ren
(1) Print first ren Help for , Carry out orders 【ren /?】
(2) If the current working directory contains renamed files , Directly by order 【rename filename1 filename2 】 that will do .
(3) If the current working directory does not include , You can switch the working directory first (cd Orders, etc ), And then use (2) The commands mentioned in , You can also use the command directly 【rename filepath new_filename】.
below 3 Pictures , Is to demonstrate how to use commands directly 【ren D:\test\test1\demo1.bat demo2.bat】, Put in the directory 【D:\test\test1】 Under the demo.bat Rename the file to demo2.bat Of .
3、 ... and 、 File internal operation ——type、sort
3.1 Read text file ——type
Have a look first type Help for .
thus it can be seen ,type To read the contents of a file , The content can be referred to “ In the form of Notepad ” Open the situation , If it is txt、md、bat This plain text file , There is no garbled code after opening , But if it is doc、excel、exe、jpg、mp3、mp4 This binary file , It must be garbled after opening .
type Only meaningful for plain text files , Because if you open a garbled code , I can't understand !
The most basic command format for reading text files 【type filepath】, Try opening a bat file , as one wishes .
Heart is not willing to open a doc file , See if you can ? To lose completely ...
stay Linux In the system , And type The command corresponds to cat command .
3.2 Sort text files ——sort
Print it first sort Command help information .
(1) The most basic without any parameters sort command ——sort filepath .
Suppose there is a on the desktop tool.txt Text file for , The contents are as follows :
Now I want to sort and sort them out . Carry out orders 【sort D:\D-desktop\tool.txt】, The results are shown in the figure below .
We can find out 31 stay 4 In front of , It shows that this sorting algorithm gives priority to the first bit , If the first one has been decided, no comparison will be made .
Be careful , This sort The command does not change the original txt The content of the document , It's just that the output has changed , If you want to put the sorted content in the new txt In file , You can execute the redirection command 【sort D:\D-desktop\tool.txt>D:\D-desktop\tool
_sorted.txt】.
(2) If you want to start from n Bit start sort , Through adjustment /n Parameter realization , If you want to start from the 2 Bit start sort , Carry out orders 【sort /+2 D:\D-desktop\tool.txt】
(3) If you want to sort in reverse , You can add /r Parameters , Carry out orders 【sort /r D:\D-desktop\tool.txt】
边栏推荐
- Alphassl wildcard certificate for one month
- VectorDraw Developer Framework 10.10
- Let's talk about MCU crash caused by hardware problems
- 用太极拳讲分布式理论,真舒服!
- Intel announced five new technological developments, including quantum computing, neural pseudo computing, machine programming, integrated optoelectronics, and secure computing
- [batch dos-cmd command - summary and summary] - CMD window setting and operation commands (CD, title, mode, color, pause, CHCP, exit)
- 【批處理DOS-CMD命令-匯總和小結】-cmd擴展命令、擴展功能(cmd /e:on、cmd /e:off)
- Google extender address
- Full range of isolator chips with integrated isolated power supply
- Chuantuwei ca-is3720lw alternative material No. iso7820fdw
猜你喜欢
Cocos learning diary 3 - API acquisition nodes and components
Harmony美食菜单界面
Tempest HDMI leak receive 1
Chuantu microelectronics high speed and high performance rs-485/422 transceiver series
VectorDraw Developer Framework 10.10
图扑软件数字孪生 3D 风电场,智慧风电之海上风电
韩信大招:一致性哈希
[batch dos-cmd command - summary and summary] - external command -cmd download command and packet capture command (WGet)
我与CSDN的一年时光及大学经验分享
LeetCode 每日一题——515. 在每个树行中找最大值
随机推荐
音频(五)音频特征提取
【UVM入門 ===> Episode_9 】~ 寄存器模型、寄存器模型的集成、寄存器模型的常規方法、寄存器模型的應用場景
【批處理DOS-CMD命令-匯總和小結】-cmd擴展命令、擴展功能(cmd /e:on、cmd /e:off)
N – simple encoding
LabVIEW jump to web page
TEMPEST HDMI泄漏接收 2
Escape analysis of 982 golang
[Yu Yue education] engineering testing technology reference of Wenhua University
Domestic MCU perfectly replaces STM chip model of Italy France
太上老君的炼丹炉之分布式 Quorum NWR
Reading sensor data with GPIO analog SPI interface
Orcad Schematic常用功能
MySQL face Scripture eight part essay
Selection of Hongmeng page menu
Sichuan Tuwei ca-is3105w fully integrated DC-DC converter
Global variables & local variables
Ltpowercad II and ltpowerplanner III
CPDA | how to start the growth path of data analysts?
Tuwei Digital Isolator and interface chip can perfectly replace imported brands Ti and ADI
MySQL - definition and assignment of variables