Essential commands for managing file attributes in Windows

  • Mastering the attrib command is key to managing attributes such as hidden, system, or read-only in Windows.
  • By combining attrib with wildcards, paths, and modifiers, you can act on entire folders and subfolders in bulk.
  • Other commands such as DIR, TREE, COPY, MOVE or RENAME complement file management from the console.
  • Learning a short series of basic and diagnostic commands allows you to troubleshoot problems, automate tasks, and recover files hidden by malware.

Essential commands for managing file attributes in Windows

In Windows, file attributes make all the difference between viewing, modifying, or even locating a file. Managing these attributes from the command line might seem like something only geeks would do, but the reality is that with a few well-learned commands you can do it all. manage thousands of files in seconds, fix problems caused by malware and automate tasks that would be a nightmare to do manually.

In this article you will see, in considerable detail, how to use the command attrib and other essential Windows terminal commands for manage attributes, list, copy, rename or delete files and foldersEverything is explained in Spanish from Spain, with clear examples and without assuming anything, so you can navigate the command prompt (CMD) with ease even if you are not a system administrator.

What are file attributes in Windows and what are they used for?

Windows marks each file and folder with a series of internal flags, called file attributesThese attributes indicate things like whether a file is hidden, whether it is a system file, whether it is read-only, or whether it has been modified since the last backup.

Managing these attributes from the graphical interface is possible, but quite limited. However, with the console you can apply bulk changes to thousands of filesincluding subfolders, entire drives or USB drives, and correct situations where everything seems "disappeared" due to malware that hides your documents.

Recovering deleted files with Recuva PhotoRec
Related article:
Recovering deleted files with PhotoRec and Recuva

The ATTRIB command: the Swiss Army knife of attributes

The command attrib allow show, set or delete file and directory attributesIf you run it without any parameters, it shows you the attributes of all the files in the current directory.

General syntax of ATTRIB

The complete form of the command is:

attrib ]

Each letter indicates an attribute, and the sign that precedes it defines whether you want add (+) or subtract (-) That attribute. The path parameters and trailing modifiers control which files you act upon and how the command is applied.

Classic and advanced attributes that you can manage

The most commonly used attributes (and the ones you should memorize) are:

  • {+|-}r: marks or unmarks the attribute of read onlyA read-only file cannot be easily modified from many applications.
  • {+|-}a: sets or clears the attribute fileThis attribute indicates that the file has changed since the last backup and is used by utilities such as xcopy or backup programs.
  • {+|-}s: activates or deactivates the attribute of system fileFiles with this attribute are intended for the internal functioning of Windows and are usually protected.
  • {+|-}h: adds or removes the attribute of hidden fileIf a file is hidden, it will not be displayed by default in Explorer unless you change the view.

Modern Windows include more manageable attributes from attrib which are rarely explained, but which exist and can appear in advanced file systems:

  • {+|-}o: sets or clears the file attribute offlineThis usually indicates that the file is not currently on the local disk (for example, in sync with the cloud).
  • {+|-}i: activates or deactivates the attribute Not Content IndexedThat is, the file content is not indexed for searches.
  • {+|-}x: marks or unmarks the file attribute of cleaningused by certain maintenance and storage systems.
  • {+|-}p: sets or clears the file attribute anchored (pinned), useful in selective synchronization contexts.
  • {+|-}u: marks the file as unpinnedthe opposite of the previous one.
  • {+|-}b: manages the attribute of SMR blob file, related to specific storage technologies.

Keep in mind that to change some "special" attributes, such as hidden o workYou may need to remove that same attribute first, or have NTFS permissions in WindowsThis is an important detail to avoid going crazy if a seemingly correct command fails. it has no effect.

Route parameters and wildcards

Following the attributes, attrib It receives the path and filename or pattern to which you want to apply the operation:

  • Here you indicate where to act. It could be something like C:\Carpeta\archivo.txta unit like F: or a pattern.
  • You can use wildcards like * y ? in the filename for affect groups of files at the same time, for example *.txt o doc??.docx.

If you do not specify a path, the command acts on the current directorySo it's important to be clear about which folder you're in (with CD o CD.) before you start changing attributes left and right.

Behavior modifiers: /s, /dy /l

In addition to attributes and path, attrib It accepts several modifiers that control the extent of the action:

  • /s: applies the command to all files that match the pattern in the current directory and all its subdirectoriesIdeal for large-scale changes.
  • /d: allows the command to also act on directories (folders)not just about files.
  • /l: makes attrib act upon the symbolic link itself and not about the fate of that link.

By combining these modifiers you can, for example, remove system and hidden attributes from an entire folder structure on a USB drive in a single command, a very common operation when Malware changes the attributes of your files to hide them.

Practical examples with ATTRIB

These examples will help you see how the command is actually used in everyday life:

  • View the attributes of a specific file in the current directory:
    attrib news86
  • Mark a file as read-only, for example report.txt:
    attrib +r report.txt
  • Remove the read-only attribute of all the files in B:\public and its subfolders:
    attrib -r B:\public\*.* /s
  • Prepare and clean the Archive attribute on a drive, first putting it on all the files of A: and then taking it away only from the .bak:
    attrib +a A:*.* & attrib -a A:*.bak

Notice how commands are chained together with the operator &This allows multiple operations to be performed consecutively on a single line. This type of combination is the basis of... batch programming in Windows.

Using ATTRIB to recover files hidden by malware

A typical case in which attrib It becomes your best friend when you connect a USB drive and all your files "disappear"In reality, many malware programs mark documents and folders as hidden and system files, so that File Explorer does not display them by default.

In this scenario, it is usually recommended to locate it in your USB drive, for example F:and execute a command like:

attrib -s -r -h /s /d

This command removes all attributes from system (-s), read-only (-r) y hidden (-h) of all files and folders (/s y /d) that hang from that drive. In practice, after a few seconds, your documents are back to normal. visible and editable as before the attack.

If you want to be more specific and act only on the unit, you can use something like this:

attrib -s -r -h F: /s /d

The idea is the same, but this way you ensure that You don't touch anything outside of that unitThis is recommended when working with multiple disks connected to the system.

Batch programming and the use of ATTRIB in scripts

Essential commands for managing file attributes in Windows

When you combine several console commands into a text file with the extension . '.bat', .cmd o .btmWhat you get is a batch processing scriptTraditionally, we speak of DOS or OS/2 language, although nowadays we run it in the Windows environment.

These scripts allow Automate tasks with FreeCommander XEas the normalize file attributes, clean external drives, prepare folder structures or launch backups. Attrib It fits very well into this type of automation because it accepts wildcards, routes, and powerful modifiers.

A typical structure would look something like this:

attrib

For example, to ensure that a working folder never contains hidden or system files, you could have a line like this in your .bat file:

attrib -s -h "C:\Proyectos\*.*" /s /d

Running that file periodically or at login guarantees that whatever is inside C:\Projects It will always be visible and easily manageable from the Explorer.

Console commands for managing files and folders in bulk

Besides playing with the attributes, in your day-to-day life you'll need list, create, copy, move, rename and delete Large numbers of files and directories. The Windows console offers a good selection of commands to do this without the need for external programs.

Encrypt files and folders with VeraCrypt
Related article:
How to encrypt files and folders with VeraCrypt step by step

List contents: DIR and TREE

The command DIR It's the classic way to display the contents of the current directory. It's possible. filter, sort and export This list with different parameters:

  • DIR: displays all visible files and folders in the current directory.
  • DIR *.ext: only files that end in a specific extension, for example DIR *.txt.
  • DIR /AIt also shows hidden and system files, very useful for Detect files that you don't see from the graphical interface.
  • DIR /B: displays only names, in "basic" format, ideal for redirecting output to a file or using it in scripts.
  • DIR /OS: sorts the results by size, from smallest to largest.

If you want to save the list of files in a text document, simply redirect the output:

DIR /B > listado.txt

This creates a file called list.txt in the current folder with the list of names, something very practical for document projects, review content, or prepare scripts.

For its part, the command TREE generates an ASCII character representation of the folder and file structure:

  • TREE folder: draws the subdirectory tree of the specified folder.
  • TREE folder /F: includes files, not just folders.

This type of exit is very convenient for technical documentation, explanatory emails, or quick analyses of a directory hierarchy without the need for screenshots.

Create folders and files from the console

To create directories, the reference command is MKDIR (or his alias) MD):

  • MKDIR folder_name: Creates a new folder in the current directory.

From there you can play with relative and absolute paths. For example, if you are in C:\Users\alumno\Desktop and you want to create C:\webYou can use a relative path like this:

MKDIR ..\..\web

That double ..\..\ It takes you up two levels from the desktop to the root of C:, and then create the web folderFollowing the same pattern, you can create subfolders like c:\web\sistemas, c:\web\redes o c:\web\bbdd with variations of:

MKDIR ..\..\web\sistemas ..\..\web\redes ..\..\web\bbdd

To create an empty file, a common trick is to use threw out with redirection:

  • echo. > filename.txt: creates an empty text file with that name.

If you want to write content directly from the console, you can do so with TYPE combined with redirection or open notepad filename.html to edit it visually, as is often proposed in many introductory exercises.

FOR loops to create or process many files

The command FOR It's another one of the great unknowns for many Windows users, but it allows automate repetitive operations over many elements (files, numbers, lines of text, etc.). Some typical patterns:

  • Create a file sequence from 0 to 10:
    for /L %i in (0, 1, 10) do echo. > "%i hola.md"
  • Create numbered folders with the same type of loop:
    for /L %i in (0, 1, 10) do mkdir "%i hola"
  • Create files from a list in a .txt file:
    for /f "tokens=*" %i in (nombres.txt) do echo. > "%i.md"
  • Create folders from that list:
    for /f "tokens=*" %i in (nombres.txt) do mkdir "%i"

You can also use FOR For more sophisticated tasks, such as grouping several text files into one:

for %i in (*.txt) do type "%i" >> archivo_salida.txt && echo. >> archivo_salida.txt && echo. >> archivo_salida.txt

In this case, for each file .txt Its content is copied to the end of output_file.txt and blank lines are added between them for cleaner reading. Varying the pattern of the for You can repeat the trick to .bat scripts, .md notes or any other type of text.

Copying and moving files and folders

To copy files from one point to another, the basic commands are COPY y XCOPY, plus MOVE to move:

  • COPY source destination: copies one or more files to another location.
  • MOVE origin destination: moves the file or folder, that is, It copies it and then deletes the original.
  • XCOPY: more advanced copy, capable of replicating entire directory structures with great control.

For example, if you want to copy the same file readme.txt To access all folders in the current directory, you can use:

for /D %a in (*) do (xcopy /Y readme.txt "%a")

Here, FOR /D It only scans subdirectories, and XCOPY /Y It copies the file by overwriting without asking, which is great when you have "hundreds" of folders.

If you're looking to clone the folder structure from one site to another, but without the files, xcopy There is also a solution:

  • xcopy source destination /T: copies the directory structure without files.
  • xcopy source destination /T /E: same, but including empty folders.

One detail: if the destination doesn't exist, it's a good idea finish the route with a backslash (\) to make it clear that you want to create a directory and not overwrite a file.

Rename many files at once

To rename files, the standard command is RENAME (o REN):

  • REN source_file new_name: changes the name of a specific file.

Combining it with FOR, Can use NirSoft tools or add prefixes or suffixes to all files in a folder in one go:

  • Add prefix to all files:
    for %a in (*.*) do ren "%a" "prefijo - %a"
  • Add suffix:
    for %a in (*.*) do ren "%a" "%~na - sufijo%~xa"

In the case of the suffix, it's advisable to play with %~n (name without extension) and %~x (extension) to avoid breaking the file type. You can also filter by extension, for example for %a in (*.jpg) if you just want to edit photos.

Another very useful case is Rename the same file in many subfoldersFor example, convert all the readme.txt en readme.md recursively:

for /R %G in (readme.txt) do ren "%G" "readme.md"

This command recursively traverses the structure, finding each readme.txt and renames it, which saves a considerable amount of time if you manage many projects or templates.

Delete files and directories from CMD

Deleting from the console is powerful, but also dangerous, since certain deletions they don't go in the trash. The key commands are:

  • DEL filename: deletes the specified file.
  • DEL /Q /F *.*: silently deletes (/Q) and forced (/F) all files in the current directory.
  • RMDIR directory_name o RD: deletes an empty directory.
  • RMDIR /S /Q directory_name: deletes the specified directory and all its content (including subfolders) without asking for confirmation.

A typical use would be to delete, for example, a directory website the entire thing once you've made a previous backup with xcopyIt is advisable to exercise extreme caution and ensure that the path is correct; if you encounter locked folders, follow the Solution to delete locked folders in Windows.

One detail: if the destination doesn't exist, it's a good idea finish the route with a backslash (\) to make it clear that you want to create a directory and not overwrite a file.

Basic navigation and editing commands for practice

To navigate the system from CMD and perform small tests, you only need to learn a few very simple commands:

  • CD: without parameters, it shows the current routeUsing a path, change to that directory. For example, CD \ It takes you to the root of unity.
  • DIR: as we have already seen, it lists the contents of the current folder.
  • NOTEPAD file.html: Opens Notepad and, if the file does not exist, creates it so you can edit it.
  • TREE folder: displays the directory tree of the specified path.

With these controllers you can solve typical exercises such as Create a sample website in C:\web, create subfolders, copy a file index.html to several different routes and then check the structure with TREEIt's a very practical way to overcoming the fear of the console.

Diagnostic commands to understand what's happening with your computer

Besides the "masonry" aspect with files, the Windows console has a good number of commands designed for diagnose problems and obtain system informationSome of the most useful ones are:

  • Systeminfo: shows a fairly complete summary of your computer: system name, processor, RAM, Windows version, etc.
  • CHKDSKIt analyzes the disk surface and the logical structure of the file system, locating bad sectors and errors. Highly recommended if you suspect that Something is wrong with your hard drive.You can also complement CHKDSK with tools from disk monitoring and SMART for more information.
  • IPCONFIG: displays your computer's network configuration, including IP address, mask, gateway, and other parameters.
  • NETSTAT: list of protocol statistics and open TCP/IP connections, which is useful for detect suspicious connections or bottlenecks.
  • TRACERT host: shows the route that packets follow to reach a destination (for example TRACERT www.microsoft.com), indicating each jump and the time it takes.
  • GETMAC: returns the MAC address of your computer's network card.
  • MORE: indicates the exact version of Windows you are using.
  • CONTROL PANEL: Opens the classic Control Panel directly.
  • TEAM: displays (and allows you to adjust) the system time.
  • DRIVERQUERY: lists all installed drivers, with their name and type.
  • Tasklist: shows all running processes and the memory they use.
  • TASKKILL /PID number: ends the process whose identifier (PID) you specify, which is very useful when a program has frozen.
  • SFCThis command checks the integrity of system files and repairs corrupted ones using cached copies. It needs to be run in a console with [command missing]. administrator permission.
  • CLEANMGR: Launches the disk space cleaner, which allows you to delete temporary files and other unnecessary items.
  • FORMAL WINSATRun a suite of performance tests on the computer. You can customize it with variations such as WINSAT CPUFORMAL, MEMFORMAL, GRAPHICSFORMAL o DISKFORMAL to focus on one component.
  • Defrag: Starts defragmenting the specified disk, in systems where it makes sense (not recommended on SSDs).
  • DISKPART: advanced tool for manage partitions and disksCombined with LIST DISK o LIST VOLUME It shows you all available disks or volumes.
  • Shutdown: Turns off or restarts the computer from the console. For example, SHUTDOWN -S -T 60 schedule a shutdown in 60 seconds, and SHUTDOWN -R restart.
  • Logoff: logs off the current user while keeping the computer turned on.

Learning to use these diagnostic commands saves you a lot of time when you're dealing with network problems, resource-intensive processes, or suspected file system errors. You don't need to memorize them all, but it's helpful to have a clear understanding of them. four or five and their main function.

Control and shutdown of the equipment from the console

Beyond managing files, you can also control system shutdown and restart From the console, something very useful for scheduling automatic tasks or maintenance scripts that shut down the computer when finished.

With the command Shutdown you have several options:

  • SHUTDOWN -S: turns off the equipment after a default time.
  • SHUTDOWN -S -T 300: schedule a shutdown in 300 seconds (5 minutes).
  • SHUTDOWN -RRestart your computer.
  • SHUTDOWN /A: Cancels a scheduled shutdown or restart that is still pending.
  • SHUTDOWN /P: turns off the equipment immediately, without waiting time.

By combining these commands with batch scripts you can prepare, for example, a task that launches a CHKDSK or a backup, wait for it to finish and turn off the equipment automatically while you are already out of the office.

Mastering the command attrib And a handful of basic Windows console commands gives you enormous control over your files: you can recover files hidden by malware, normalize attributes in complex structures, automate copies, rename huge batches of documents, and diagnose problems without relying on graphical menus.

How to mass rename files in Windows 10
Related article:
How to mass rename files in Windows 10

You don't need to memorize an entire manual, but you do need to internalize these key commands and practice with them in test environments, because with a little practice the command line goes from being intimidating to becoming a fast, flexible and very useful tool for anyone who regularly works with Windows. Share the guide and help other users learn how it's done.