Windows (path, file) common commands

The following are some commands commonly used in windows, including path switching and file operations (CRUD). At some point, permissions are required to operate files in the editor, and some commands will always be faster, so as to avoid operating files in the file manager and improve our development speed.

# 切换根目录
D:

# 显示当前路径
echo %cd%

# 进入下级目录
cd ./path

# 返回上一级级目录
cd ..

# 返回之前所在目录
cd -

# 返回根目录
cd \



# 创建文件夹(目录)
mkdir folderName
# or
md folderName

# 创建新的文件或向文件中写入内容。
echo text > pathname



# 删除文件,再加/S /Q ,/S 表示删除文件夹及其所有内容,/Q 表示不显示确认提示。
del pathname

# 使用erase命令删除文件
erase pathname

# 删除空文件夹
rm pathname
# or
rmdir pathname

# deltree,用于删除指定的非空文件夹及其所有子文件夹和文件。0
deltree pathname



# 在终端修改文本文件的内容
edit pathname

# 重命名。参数,/A:将文件属性保留在重命名后的文件中。/F:强制重命名文件,即使目标文件已经存在。/N:对于不存在的文件,不要创建一个新文件。
rename pathname newName
# or
ren pathname newName



# 查看文件夹的内容
dir pathname
# or
dir

# 使用记事本查看某一个目录文件的文件内容
notepad pathname

# 在终端查看文本文件的内容。如果指定的文件不存在,则会创建一个新文件。
type pathname

# 使用more命令分页查看文本文件的内容
more pathname

# 使用findstr命令搜索文本文件中的内容
findstr keyword pathname

# 搜索当前目录及其子目录中所有包含指定字符串的文件。
findstr /s /i /m "searchterm" *

# 搜索当前目录及其子目录中的文件。
dir /s filename

# 搜索当前目录及其子目录中所有特定扩展名的文件。
dir /s *.extension

# 搜索系统中所有包含指定文件名的位置。
where filename



# 复制文件。参数:/A /B /V /Y 。 /A,将文件属性保留在目标文件中。/B,将文件作为二进制文件复制。/V,在复制每个文件之前验证源和目标文件是否匹配。/Y,在没有提示的情况下覆盖目标文件。
copy originPathname targetPathname

# 使用move命令移动文件
move  originPathname targetPathname 

# 使用xcopy命令复制文件并保留文件属性。其中,/I 表示目标是一个目录,/E 表示复制所有子目录和文件,/H 表示包括隐藏文件,/K 表示保留原始文件属性。
xcopy originPathname targetPathname /I /E /H /K

# 使用robocopy命令复制文件和目录树。其中,/E 表示复制所有子目录和文件,/COPYALL表示复制所有文件属性和时间戳信息。
robocopy originPathname targetPathname /E /COPYALL



# 下载文件,把 "file.zip" 文件下载到当前目录
curl -o file.zip http://example.com/file.zip
# or
Invoke-WebRequest -Uri http://example.com/file.zip -OutFile file.zip 



# 解压文件
Expand-Archive -Path /path/file.zip -DestinationPath getFileFolder



# 搜索并安装应用
winget install soft # such as:winget install Google.chrome

# 安装本地*.exe应用
/path/*.exe

# 安装本地*.msi应用
msiexec /i /path/*.msi

Guess you like

Origin blog.csdn.net/qq_58062502/article/details/129209914