dosfsck command in Linux with Examples
Last Updated :
23 Sep, 2024
dosfsck stands for DOS File System Consistency Check and is part of the dosfstools package in Unix-like operating systems. This command diagnoses and repairs MS-DOS filesystems (FAT12, FAT16, FAT32). Before running dosfsck, it is crucial to unmount the filesystem to avoid data corruption.
Syntax:
dosfsck [options] device
The most basic usage of dosfsck
simply requires specifying the device you want to check.
Basic Example:
dosfsck [-aAflrtvVwy] [-d path -d ...] [-u path -u ...] /dev/sdX1
Common Issues Resolved by ‘dosfsck’ Command
‘dosfsck’ command can be used to correct some below the mentioned problems:
- Invalid cluster numbers in the FAT are changed to EOF.
- Loops in a file’s cluster chain are broken.
- Bad clusters are marked and removed from associated files or directories.
- Corrupted directories may be dropped.
- Invalid start clusters result in file truncation.
- Duplicate directories may be renamed or dropped.
These filesystem problems can also be detected but are not fixed by dosfsck command if:
- Invalid parameters detected in boot sector.
- . and .. entries not found in non-root directories.
Common Options Used with the ‘dosfsck’ command
Option |
Description |
-a |
Automatically repair the filesystem. |
-A |
Toggle Atari variation of the MS-DOS filesystem. |
-b |
Perform a readonly check on the boot sector. |
-d |
Delete the specified file. |
-f |
Salvage unused cluster chains to files. Unused clusters are typically added to free disk space. |
-l |
List path names of files being processed. |
-n |
No-operation mode; check is performed without making any changes. |
-p |
Automatically repair filesystem errors (similar to -a ). |
-r |
Interactive mode; prompts user for decisions when there are multiple ways to fix an error. |
-t |
Mark unreadable clusters as bad. |
-u |
Try to undelete the specified file. |
-v |
Verbose mode; shows more details about the repairs being made. |
-V |
Perform a verification pass without making any changes. |
-w |
Write changes to disk immediately after fixing errors. |
-y |
Automatically answer ‘yes’ to all prompts (similar to -a) |
Exit Codes for dosfsck
Understanding the exit codes returned by dosfsck helps you determine the result of the command’s execution:
- 0: No recoverable errors detected.
- 1: Recoverable errors were detected and fixed.
- 2: Syntax or usage error occurred.
dosfsck Command Examples
Let us look at some of the examples of dosfsck command to better understand the concept.
1. Automatically repair the file system.
To automatically repair the filesystem on a FAT-formatted partition, use the -a option:
sudo dosfsck -a /dev/sdb1

2. Readonly boot sector check
To perform a readonly check of the boot sector, use the -b option
sudo dosfsck -b /dev/sdb1

3. List path names of files being processed
You can list the path names of files being processed by ‘dosfsck’ using the ‘-l’ option:
sudo dosfsck -l /dev/sdb1

4. Verbose Check and Repair with Marking Bad Clusters
Verbose way of checking and repairing the filesystem non-interactively. The ‘-t’ used to mark unreadable clusters as bad, this will make them unavailable for new files and directories.
sudo -v -a -t /dev/sdb1

5. Perform a Verification Pass
If you want to run ‘dosfsck’ in verification mode without making any changes to the filesystem, use the ‘-V’ option:
sudo -V /dev/sdb1

Conclusion
The ‘dosfsck’ command is a versatile and essential tool for maintaining FAT-formatted filesystems on Unix-like operating systems. It offers both automatic and interactive options to diagnose and repair a wide range of filesystem issues. By following the above mentioned examples, you can confidently manage and repair MS-DOS filesystems using dosfsck.
Similar Reads
depmod command in Linux with examples
depmod(Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a "Makefile"-like dependency file named modules.dep based on the symbols p
7 min read
df Command in Linux with Examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e. 'df' command that
9 min read
How to Compare Files Line by Line in Linux | diff Command
In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process i
9 min read
diff3 command in Linux with examples
diff3 command is used to compare the three files line by line. It internally uses the diff command to compare. When three files are compared then the following output may come which have their own meaning: ==== : It means all the files are different. ====1 : File 1 is different. ====2 : File 2 is di
3 min read
dir command in Linux with examples
The dir command in Linux is used to list the contents of a directory, providing an overview of the files and folders within it. How is the dir command different from ls?dir command differs from the ls command in the format of listing contents that is in default listing options. By default, dir comma
5 min read
Dirname Command in Linux with Examples
dirname is a command in Linux that is used to remove the trailing forward slashes "/" from the NAME and print the remaining portion. If the argument NAME does not contain the forward slash "/" then it simply prints dot ".". In other words, we can say that the 'dirname' command is a useful tool for e
3 min read
dirs command in Linux with examples
dirs command shell builtin is used to display the list of currently remembered directories. By default, it includes the directory you are currently in. A directory can get into the list via pushd command followed by the dir name and can be removed via popd command. Syntax: dirs [-clpv] [+N] [-N] It
1 min read
enable and disable command in Linux
Enables and disables are the built-in shell commands. enable command is used to start the printers or classes whereas the disable command is used to stop the printers or classes. Syntax For enable Command: enable [-a] [-dnps] [-f filename][name ...] Syntax For disable Command: disable [-c] [-W] [ -r
1 min read
dmesg command in Linux for driver messages
dmesg command also called âdriver messageâ or âdisplay messageâ is used to examine the kernel ring buffer and print the message buffer of the kernel. The output of this command contains the messages produced by the device drivers. Usage of dmesg:When the computer boots up, there are lot of messages(
6 min read
dmidecode command in Linux with Examples
The 'dmidecode' command, short for Desktop Management Interface table decoder, is a powerful utility in Linux that retrieves detailed information about your system's hardware components. This tool reads the DMI table and presents the data in a human-readable format, making it invaluable for system a
4 min read