The dir command is one of the most useful commands while navigating the command line, and is present in its different forms in several operating systems. In this article, we will look at the Dir command and learn several use cases for it.
What is the dir Command
dir command in Windows OS is a built-in function that allows the user to do the following task:
- View the contents of any directory
- Check file attributes (both hidden and read-only)
- Filter search results based on date or file type.
Basic Syntax
The general syntax of the dir command is:
dir [path] [options]
- Path: specifies the location
- Options: modifies to filter the output
1. List Files & Directories
This command is used to list all files and directories in the current one:
help dir
help dir command
Output :
Displays a list of files and subdirectories in a directory.
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
[drive:][path][filename]
Specifies drive, directory, and/or files to list.
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files I Not content indexed files
L Reparse Points O Offline files
- Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
.
.
output
Usage explanation:
The command is mainly used for displaying the list of files and subdirectories in a directory. This could be done by executing the Dir command without any arguments.
Dir
dir
Which would produce an output similar to this.
Output
Directory of C:\Users
09/26/2020 11:34 AM <DIR> .
09/26/2020 11:34 AM <DIR> ..
09/02/2020 07:07 PM 1, 000 applese
09/24/2020 08:59 PM <DIR> Public
10/20/2020 06:39 PM <DIR> Soap
1 File(s) 1, 000 bytes
4 Dir(s) 13, 879, 459, 840 bytes free
Output
2. List Content of a Specific Directory
The output of the dir command in this enable users to specify a directory to view its contents. The syntax for this command is as follows:
Input
dir C:\Users\gfg19310\Documents
List all content – Input
Output
Directory of C:\Users\gfg19310\Documents
20-03-2023 13:02 <DIR> .
20-03-2023 13:02 <DIR> ..
20-03-2023 13:02 <DIR> Custom Office Templates
List all content – Output
3. Show Hidden Files
Here, we will use /A option with the H attribute to include hidden files along with it. Here’s the syntax:
Input
dir /A:H
show hidden file – Input
Output
07-06-2023 16:36 <DIR> AppData
07-06-2023 16:36 <JUNCTION> Application Data [C:\Users\GFG19310.GFG\AppData\Roaming]
07-06-2023 16:36 <JUNCTION> Cookies [C:\Users\GFG19310.GFG\AppData\Local\Microsoft\Windows\INetCookies]
07-06-2023 16:36 <JUNCTION> Local Settings [C:\Users\GFG19310.GFG\AppData\Local]
07-06-2023 16:36 <JUNCTION> My Documents [C:\Users\GFG19310.GFG\Documents]
07-06-2023 16:36 <JUNCTION> NetHood [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
11-12-2024 05:46 3,670,016 NTUSER.DAT
07-06-2023 16:36 688,128 ntuser.dat.LOG1
07-06-2023 16:36 1,085,440 ntuser.dat.LOG2
02-01-2025 10:40 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.0.regtrans-ms
18-12-2024 09:56 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.1.regtrans-ms
18-12-2024 09:56 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.2.regtrans-ms
18-12-2024 09:56 65,536 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.blf
07-06-2023 16:36 65,536 NTUSER.DAT{53b39e88-18c4-11ea-a811-000d3aa4692b}.TM.blf
07-06-2023 16:36 524,288 NTUSER.DAT{53b39e88-18c4-11ea-a811-000d3aa4692b}.TMContainer00000000000000000001.regtrans-ms
07-06-2023 16:36 524,288 NTUSER.DAT{53b39e88-18c4-11ea-a811-000d3aa4692b}.TMContainer00000000000000000002.regtrans-ms
07-06-2023 16:36 20 ntuser.ini
07-06-2023 16:36 <JUNCTION> PrintHood [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Printer Shortcuts]
07-06-2023 16:36 <JUNCTION> Recent [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Recent]
07-06-2023 16:36 <JUNCTION> SendTo [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\SendTo]
07-06-2023 16:36 <JUNCTION> Start Menu [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Start Menu]
07-06-2023 16:36 <JUNCTION> Templates [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Templates]
show hidden file – Output
4. List Files with Specific Extensions
To display files with a specific extension (e.g., .txt): Here’s a sample
Input
dir *.txt
Display Text -input
Output
Directory of C:\Users\GFG19310.GFG
14-11-2024 15:32 3 example.txt
20-11-2024 14:44 0 filename.txt
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
Display Text -Output
5. View Subdirectories
To include all subdirectories and their contents, use the following command:
Input
dir /S
dir /S
Output
Directory of C:\Users\GFG19310.GFG\Saved Games
07-06-2023 16:36 <DIR> .
07-06-2023 16:36 <DIR> ..
0 File(s) 0 bytes
Directory of C:\Users\GFG19310.GFG\Searches
07-06-2023 16:38 <DIR> .
07-06-2023 16:38 <DIR> ..
08-11-2022 16:52 855 winrt--{S-1-5-21-1623517014-2252875782-278851815-1404}-.searchconnector-ms
07-06-2023 16:37 859 winrt--{S-1-5-21-2245693176-3959787992-2909979321-1244}-.searchconnector-ms
2 File(s) 1,714 bytes
Directory of C:\Users\GFG19310.GFG\Videos
07-06-2023 16:38 <DIR> .
07-06-2023 16:38 <DIR> ..
26-12-2024 13:37 <DIR> Captures
0 File(s) 0 bytes
Directory of C:\Users\GFG19310.GFG\Videos\Captures
26-12-2024 13:37 <DIR> .
26-12-2024 13:37 <DIR> ..
26-12-2024 13:37 185,053 File Explorer 26-12-2024 13_37_47.png
11-10-2023 15:51 23,668 Network Connections .png
Fetching Directory
6. Sort by Date, Size, or Name
We can fetch data based on date, size or name. Let’s check them out:
By Date:
Input
dir /O:D
dir /O:D
Output
Directory of C:\Users\GFG19310.GFG
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
07-06-2023 16:36 <DIR> Favorites
07-06-2023 16:36 <DIR> Music
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:36 <DIR> Links
07-06-2023 16:37 <DIR> OneDrive
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos
07-06-2023 16:40 <DIR> Documents
18-04-2024 12:51 2,635,835 get-pip.py
18-04-2024 16:16 2,635,835 get-pip.p
14-11-2024 15:32 3 example.txt
14-11-2024 15:35 3 Rqapture.txt
20-11-2024 14:44 0 filename.txt
20-11-2024 14:45 0 Rapture.txt
12-12-2024 18:45 <DIR> my-node-project
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
26-12-2024 10:02 <DIR> Downloads
30-12-2024 18:34 <DIR> Pictures
31-12-2024 16:02 <DIR> Desktop
Output
By Size:
Input
dir /O:S
dir /O:S
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Videos
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:32 3 example.txt
14-11-2024 15:35 3 Rqapture.txt
18-04-2024 12:51 2,635,835 get-pip.py
18-04-2024 16:16 2,635,835 get-pip.p
Output
By Name:
Input
dir /O:N
dir /O:N
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2,635,835 get-pip.p
18-04-2024 12:51 2,635,835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos
Output
7. View Results Page by Page
This command is used where too many files exists, we can use the /P option to get results one page at a time. Here’s the command:
Input
dir /P
dir /P
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2,635,835 get-pip.p
18-04-2024 12:51 2,635,835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos
Output
8. List File Attributes
We can also include attributes such as read-only files and archives using the following command:
Input
dir /A
dir /A
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> AppData
07-06-2023 16:36 <JUNCTION> Application Data [C:\Users\GFG19310.GFG\AppData\Roaming]
07-06-2023 16:36 <DIR> Contacts
07-06-2023 16:36 <JUNCTION> Cookies [C:\Users\GFG19310.GFG\AppData\Local\Microsoft\Windows\INetCookies]
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2,635,835 get-pip.p
18-04-2024 12:51 2,635,835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <JUNCTION> Local Settings [C:\Users\GFG19310.GFG\AppData\Local]
07-06-2023 16:36 <DIR> Music
07-06-2023 16:36 <JUNCTION> My Documents [C:\Users\GFG19310.GFG\Documents]
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:36 <JUNCTION> NetHood [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
11-12-2024 05:46 3,670,016 NTUSER.DAT
07-06-2023 16:36 696,320 ntuser.dat.LOG1
07-06-2023 16:36 1,003,520 ntuser.dat.LOG2
02-01-2025 10:40 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.0.regtrans-ms
18-12-2024 09:56 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.1.regtrans-ms
18-12-2024 09:56 1,048,57 ..
Output
9. Display File Size
You can also check the file size (in bytes) using the following command:
Input
dir /-C
dir /-C
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2635835 get-pip.p
18-04-2024 12:51 2635835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos
Output
Advanced Syntax
The above-mentioned syntaxes is for general usage. Now, let’s see some of the advanced usage syntax along with their examples.
10. Save Output to a File
We can redirect the output to a text file (dir command) using the syntax below:
Input (file name: rapture.txt)
dir /S > rapture.txt
dir /S > filename
Output
A file name with the provided name will be created containing the directory list.
Output
11. Search for any Specific File
You can search for any file by its name (or even partial name), following this syntax:
Input (file name: rapture – taken as a partial name “rapt”)
dir *rapt*
*filename*
Output
Directory of C:\Users\GFG19310.GFG
03-01-2025 11:03 7,854,908 Rapture.txt
1 File(s) 7,854,908 bytes
0 Dir(s) 116,168,089,600 bytes free
Output
12. Check the Total Number of Files
This syntax will summarise the total count of a file including directory:
Input
dir /W
dir /W
Output
Output
Bonus: Useful cmd Options (Summarization)
Option | Description |
---|---|
/P |
Fetch results one page at a time |
/S |
Includes all files in subdirectories. |
/A |
Displays files with specified attributes (e.g., /A:H for hidden files). |
/O |
Sorts output (e.g., /O:D for date, /O:N for name). |
/B |
Displays output in bare format (file names only, without additional details). |
/L |
Displays names in lowercase. |
/T |
Displays time attributes (e.g., /T:C for creation time). |
/Q |
Displays file ownership information. |
The dir command is vastly used among users for managing and exploring directories through different ways and patterns in Windows OS. You can give it all a try and organize your work smoothly.
The dir
command is used to list files and folders in the Windows command prompt (CMD).
dir
The dir
command without a path will display a list of files and folders in the current working directory.
You can provide a path to see the listing for a different directory:
dir C:\Windows
By default, the dir
command does not show hidden files and folders. To include hidden files, run the dir
command as follows:
dir /a
You can use the /B
switch to show the file names only without heading information or summary.
dir /b C:\Windows
The /s
option lists all files in a specified directory and all subdirectories.
dir /s
List Files Using Patterns
The dir
command supports wildcard character (*
) that you can use to describe a pattern to match.
For example, the following command lists all files that begin with the letter A:
dir a*
Here is another example that lists all files that have a .doc
extension:
dir /b *.doc
Displays files with specified attributes
The /A
switch is used to list files and folders with specified attributes. For example, the letter H
represents the hidden attribute.
dir /a:h
The following table describes each of the values that you can use for Attributes.
D | Folders. |
H | Hidden files and Folders. |
S | System files. |
L | Reparse Points. |
R | Read-only files. |
A | Files ready for archiving. |
I | Not content indexed files. |
O | Offline files. |
— | Prefix meaning not (See examples). |
Examples
List Files and folders in C:\Windows\System32
directory:
dir C:\Windows\System32
Obtain a listing of all files in C:\Windows\System32
that ends with the .txt extension:
dir C:\Windows\System32\*.txt
Search for files with .dll
extension in C:\Windows\System32
and all subdirectories:
dir /s C:\Windows\System32\*.dll
Returns the listing for the parent directory of the current working directory:
dir ..
List all files and folders, including hidden files:
dir /a
Show hidden files only:
dir /a:h
List only folders:
dir /a:d
Don’t list folders:
dir /a:-d
Show only hidden folders:
dir /a:dh
List read only files:
dir /a:r
Sort the result by name:
dir /o:n
This will sort the result set by size:
dir /o:s
Sort the result set by size (largest first):
dir /o:-s
Sort the result by date:
dir /o:d
Includes the name of the owner for each file:
dir /q
Show creation time:
dir /t:c
Show last access time:
dir /t:a
Show the last written time:
dir /t:w
Run the dir /?
command to see a list of all the available command-line options.
Программистам часто приходится работать в консоли — например, чтобы запустить тестирование проекта, закоммитить новый код на Github или отредактировать документ в vim. Всё это происходит так часто, что все основные действия с файлами становится быстрее и привычнее выполнять в консоли. Рассказываем и показываем основные команды, которые помогут ускорить работу в терминале под OS Windows.
Для начала нужно установить терминал или запустить командную строку, встроенную в Windows — для этого нажмите Win+R
и введите cmd
. Терминал часто встречается и прямо в редакторах кода, например, в Visual Studio Code.
Чтобы ввести команду в консоль, нужно напечатать её и нажать клавишу Enter
.
Содержимое текущей папки — dir
Выводит список файлов и папок в текущей папке.
C:\content-server>dir
Том в устройстве C имеет метку SYSTEM
Серийный номер тома: 2C89-ED9D
Содержимое папки C:\content-server
06.10.2020 00:41 <DIR> .
06.10.2020 00:37 <DIR> .circleci
16.07.2020 16:04 268 .editorconfig
16.07.2020 16:04 10 .eslintignore
16.07.2020 16:04 482 .eslintrc
06.10.2020 00:37 <DIR> .github
16.07.2020 16:04 77 .gitignore
06.10.2020 00:41 <DIR> assets
06.10.2020 00:41 <DIR> gulp
16.07.2020 16:10 379 gulpfile.js
16.07.2020 16:10 296 320 package-lock.json
16.07.2020 16:10 751 package.json
16.07.2020 16:04 509 README.md
Открыть файл
Чтобы открыть файл в текущей папке, введите его полное имя с расширением. Например, blog.txt или setup.exe.
Перейти в другую папку — cd
Команда cd
без аргументов выводит название текущей папки.
Перейти в папку внутри текущего каталога:
C:\content-server>cd assets
C:\content-server\assets>
Перейти на одну папку вверх:
C:\content-server\assets>cd ..
C:\content-server>
Перейти в папку на другом диске:
c:\content-server>cd /d d:/
d:\>
Чтобы просто изменить диск, введите c:
или d:
.
Создать папку — mkdir или md
Создаём пустую папку code
внутри папки html
:
d:\html>mkdir coded:\html>dir
Содержимое папки d:\html
03.11.2020 19:23 <DIR> .
03.11.2020 19:23 <DIR> ..
03.11.2020 19:25 <DIR> code
0 файлов 0 байт
3 папок 253 389 438 976 байт свободно
Создаём несколько пустых вложенных папок — для этого записываем их через косую черту:
d:\html>mkdir css\js
d:\html>dir
Том в устройстве D имеет метку DATA
Серийный номер тома: 0000-0000
Содержимое папки d:\html
03.11.2020 19:23 <DIR> .
03.11.2020 19:23 <DIR> ..
03.11.2020 19:25 <DIR> code
03.11.2020 19:29 <DIR> css
Создаётся папка css
, внутри которой находится папка js
. Чтобы проверить это, используем команду tree
. Она показывает дерево папок.
Удалить папку — rmdir или rd
Чтобы удалить конкретную папку в текущей, введите команду rmdir
:
d:\html\css>rmdir js
При этом удалить можно только пустую папку. Если попытаться удалить папку, в которой что-то есть, увидим ошибку:
d:\html\css>d:\html>rmdir css
Папка не пуста.
Чтобы удалить дерево папок, используйте ключ /s
. Тогда командная строка запросит подтверждение перед тем, как удалить всё.
d:\html>rmdir css /s
css, вы уверены [Y(да)/N(нет)]? y
Показать дерево папок — tree
В любом момент мы можем увидеть структуру папок. Для этого используется команда tree
.
d:\html>tree
Структура папок тома DATA
Серийный номер тома: 0000-0000
D:.
├───code
└───css
└───js
Если вы хотите посмотреть содержимое всего диска, введите tree
в корне нужного диска. Получится красивая анимация, а если файлов много, то ещё и немного медитативная.
Удаление файла — del или erase
Команда для удаления одного или нескольких файлов.
d:\html>del blog.txt
Переименование файла — ren или rename
Последовательно вводим ren
, старое и новое имя файла.
d:\html>dir
Содержимое папки d:\html
03.11.2020 19:23 <DIR> .
03.11.2020 19:23 <DIR> ..
03.11.2020 19:59 0 blag.txt
d:\html>ren blag.txt blog.txt
d:\html>dir
Содержимое папки d:\html
03.11.2020 19:23 <DIR> .
03.11.2020 19:23 <DIR> ..
03.11.2020 19:59 0 blog.txt
Команды одной строкой
Очистить консоль — cls
.
Информация о системе — systeminfo
.
d:\html>systeminfo
Имя узла: DESKTOP-6MHURG5
Название ОС: Майкрософт Windows 10 Pro
Версия ОС: 10.0.20246 Н/Д построение 20246
Изготовитель ОС: Microsoft Corporation
Параметры ОС: Изолированная рабочая станция
Сборка ОС: Multiprocessor Free
Информация о сетевых настройках — ipconfig
.
d:\html>ipconfig
Настройка протокола IP для Windows
Адаптер Ethernet Ethernet 2:
Состояние среды. . . . . . . . : Среда передачи недоступна.
DNS-суффикс подключения . . . . . :
Список запущенных процессов — tasklist
.
c:\>tasklist
Имя образа PID Имя сессии № сеанса Память
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 КБ
System 4 Services 0 2 688 КБ
Secure System 72 Services 0 23 332 КБ
…
Справка по командам — help
Команда help
без аргументов выводит список всех возможных команд. help
вместе с именем команды выведет справку по этой команде.
d:\html>help tree
Графическое представление структуры папок или пути.
TREE [диск:][путь] [/F] [/A]
/F Вывод имён файлов в каждой папке.
/A Использовать символы ASCII вместо символов национальных алфавитов.
В этой статье приведены не все команды и не все их возможности, но вы всегда можете воспользоваться командой help
и узнать о том, что ещё может командная строка.
👉🏻 Больше статей о фронтенде и работе в айти в телеграм-канале.
Подписаться
Материалы по теме
- 10 горячих клавиш VS Code, которые ускорят вашу работу
- Полезные команды для работы с Git
- Полезные команды для работы с Node. js
«Доктайп» — журнал о фронтенде. Читайте, слушайте и учитесь с нами.
ТелеграмПодкастБесплатные учебники
The `dir` command in CMD is used to display a list of files and directories in a specified directory or the current directory by default.
dir
Understanding the Basics of CMD and the `dir` Command
What is CMD?
The Command Prompt, commonly known as CMD, is a powerful tool within the Windows operating system that allows users to execute commands to perform a variety of tasks including file management, system configurations, and network operations. For both beginners and advanced users, mastering CMD is essential as it offers a more flexible and efficient way to interact with the system compared to traditional graphical user interfaces.
What is the `dir` Command?
The `dir` command is one of the fundamental commands in CMD. It is primarily used to list the contents of a directory, including files and subdirectories. Understanding how to effectively utilize the `dir` command can significantly enhance your efficiency in navigating and managing the filesystem.
Mastering mkdir Cmd for Effortless Directory Creation
How to Use the `dir` Command
Basic Syntax
The general syntax for the `dir` command is as follows:
dir [options] [path]
- Options: These modify the behavior of the command.
- Path: This specifies the directory whose contents you want to display. If no path is specified, it lists the contents of the current directory.
Simple `dir` Command Examples
To get started, you can use the `dir` command without any options to display the contents of the current directory:
dir
In the output, you’ll see details about each file, including its name, size, and the last modified date. This simple command is a fantastic way to familiarize yourself with your file structure.
If you want to list files in a specific directory, you can specify the path like this:
dir C:\Users\YourUsername\Documents
This command will display all files and subdirectories located within the specified directory.
Nir Cmd: Mastering Commands with Ease
CMD `dir` Options
Overview of `dir` Options
Using options with the `dir` command can enhance your results and tailor the output to your needs. This makes your command line experience more efficient and effective.
Common `cmd dir options`
-
/B: The bare format that shows only the file names, excluding extra information. It’s useful for obtaining a clean list of file names without metadata:
dir /B
-
/A: This option allows you to display files with specific attributes, such as hidden files and system files. You can specify which attributes to include:
dir /A:AH
-
/S: This option is particularly useful when you need to search directories and their subdirectories. It lists every file within the specified directory tree:
dir /S
-
/P: If you have many files, the `/P` option pauses the output after each screen, allowing you to read it comfortably:
dir /P
Advanced `dir` Options
-
/O: This option enables you to order the output based on specific criteria, such as file name, size, or date. For example, using `/O:D` will order files by date:
dir /O:D
-
/T: Use this to control which time field is displayed, such as creation time or last modified. For instance, to view the creation times, you would use:
dir /T:C
Create a New Folder in Cmd: A Simple Guide
Practical Examples of Using `dir` Command in Different Scenarios
Using `dir` to Find Specific Files
One notable feature of the `dir` command is its ability to locate files based on specific attributes. For example, if you want to list only the hidden files within a directory, you can combine options:
dir /A:H
This command will help you easily identify hidden files that might otherwise be overlooked.
Using `dir` for Backup and Management
If you are managing files or preparing for a backup, you might want to obtain a comprehensive listing of all files directory, including their paths. You can achieve this by combining `/B` and `/S` options alongside output redirection:
dir /B /S > backup.txt
This command will save a complete list of files and their paths in `backup.txt`, making it easier to track or migrate your files later.
`dir` Command for System Information
The `dir` command can also assist in checking the sizes of files within a directory. This can help in identifying large files that may be occupying significant storage. To order files by size, use:
dir /O:S
This is especially useful for system maintenance and cleaning.
Master Win Cmd: Your Quick Start Guide to Commands
Common Errors and Troubleshooting
Common `dir` Command Errors
As you begin to work with the `dir` command, you may run into some common errors. These may include:
-
«File Not Found»: This can occur if you specify a path that does not exist. Double-check the directory path for accuracy.
-
«Access Denied»: This error signifies that you do not have the required permissions to view the directory’s contents. Ensure you are running CMD as an administrator if needed.
Tips for Troubleshooting
- Always confirm the accuracy of your paths.
- Use the `/A` option to inspect file attributes and ensure you aren’t missing hidden or system files.
- Familiarize yourself with your user permissions—this can save time in navigating hierarchical folders.
Mastering In Cmd: Quick Tips for Everyday Use
Conclusion
The `dir` command is a powerful tool within CMD that greatly simplifies file management. Its rich set of options allows you to customize your output to suit your specific needs. By practicing and mastering the `dir` command, you can handle your system’s files more efficiently and gain deeper insight into your file structures.
Do Cmd: Unlocking the Power of Command Line Magic
Additional Resources
Links to Further Reading
For those interested in diving deeper into CMD and its capabilities, numerous reference guides and online forums are available. Websites dedicated to software development and technology can be excellent resources.
Tools and Practice Environments
Consider using Windows Command Line or PowerShell for practice. Experimenting with commands will boost your confidence and competence in using CMD effectively.
on August 9, 2009
dir
command can be used to list the files from command prompt. This article explains the syntax for different usecases.
- A simple
dir
command without any other arguments lists all the files/subfolders that exist in the current folder.dir
- Lists the subfolders/files names in bare format.
dir /b
This command prints the file names. No other file meta data like file modified time, file size etc are not displayed.
- List the files in the current folder and also the ones in the subfolders recursively.
dir /s
Using wild cards with dir
Dir command accepts wild cards to display information only for the files that match the pattern specified. The below examples illustrate different use cases where we can use these wild cards
- List files of certain type or based on extension
For example to list all jpeg files in the current folder, we can run the below command.dir *.jpeg
To list all excel files
dir *.xls
We can even specify multiple extension in dir command to list files of any of the types. To list all files created with Office applications like Word, Excel, Powerpoint etc we can run below command.
dir *.docx *.xlsx *.pptx
- List files beginning/ending with specific pattern
List all files in the current folder whose names begin with ‘Picture-‘dir /S Picture-*
List file names based on type
dir command can list the file names and also the subfolders names. We can be selective and say that we want only names of the files to be listed or only the names of the subdirectories to be listed.
- List only directories
dir /A:D
- List only files
dir /A:-D
Display files based on file attributes
We can filter out which files should be listed in the dir
command output based on read-only, system, hidden archive file attributes.
- For example, to list read-only files in the current directory, the command is:
dir /A:R
- Similarly to display hidden files
dir /A:H
- For the opposite case of looking for files where an attribute is not set, we can append
'-'
to the attribute code. For example, to print the file names without archive attribute set, we can use the below command.dir /A:-A
- Exclude Read-only files from the listing.
dir /A:-R
- Exclude hidden files from listing.
dir /A:-H
- Exclude system files from listing
dir /A:-S
Print metadata of files using dir command
- Find out who owns a file
dir /Q
Example:
c:\>dir /Q 1.txt 05/03/2015 01:12 AM 151,906 BUILTIN\Administrators 1.txt
The above result of dir indicates that file 1.txt is owned by Administrators group.
- Get created time of a file
dir /TC
- Find last accessed time of a file
dir /TA
- Find last modified time of a file
dir /TW