Language: EN


Linux Commands - File System Operations

Here is a compilation of the most useful Linux commands for File System Operations

File System Analysis

#Check file integrity on disk hda1 in Linux system
fsck /dev/hda1

#Check file integrity on disk hda1 in ext2 system
fsck.ext2 /dev/hda1

#Check file integrity on disk hda1 in ext3 system
fsck.ext3 /dev/hda1

#Check file integrity on disk hda1 in Fat system
fsck.vfat /dev/hda1

#Check file integrity on disk hda1 in Dos system
fsck.msdos /dev/hda1

#Check defective blocks on disk hda1
badblocks -v /dev/hda1

File System Formatting

#Format hda in Linux system
mkfs /dev/hda1

#Format hda in FAT32 system
mkfs -t vfat 32 -F /dev/hda1

#Format hda in ext2 system
mke2fs /dev/hda1

#Format hda in ext3 system
mke2fs -j /dev/hda1

Mounting File Systems

#Mount hard disk hda2
mount /dev/hda2 /mnt/hda2

#Mount floppy disk
mount /dev/fd0 /mnt/floppy

#Mount cdrom or dvdrom
mount /dev/cdrom /mnt/cdrom

#Mount rewritable cdrom dvdrom
mount /dev/hdc /mnt/cdrecorder

#Mount rewritable cd or dvd
mount /dev/hdb /mnt/cdrecorder

#Mount usb pen-drive or memory
mount /dev/sda1 /mnt/usbdisk

#Mount file or iso image
mount -o loop file.iso /mnt/cdrom

#Unmount a device named hda2
umount /dev/hda2

#Force unmount (when device is busy)
fuser -km /mnt/hda2

ISO Images and CDROM Writers

#Mount an iso image
mount -o loop cd.iso /mnt/iso

#Create iso image of cdrom on disk
mkisofs /dev/cdrom > cd.iso

#Create iso image of a directory
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd

#Burn iso image to cdrom
cdrecord -v dev=/dev/cdrom cd.iso

#Clean or erase a rewritable cd
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force

Working with SWAP

#Create swap system file on hda3
mkswap /dev/hda3

#Activate swap partition on hda3
swapon /dev/hda3

Backups and Data

#Make a complete backup of directory
dump -0aj -f /tmp/archivo.bak /directory

#Make an incremental backup of directory
dump -1aj -f /tmp/archivo.bak /directory

#Restore a backup iteratively
restore -if /tmp/archivo.bak

#Synchronize directories
rsync -rogpav --delete /directory1 /directory2

#Dump hard drive content to file
dd if=/dev/sda of=/tmp/archivo

#Find and copy all files with .txt extension from one directory to another
find /home/user -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents

#Find all .log files and create a bzip file
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2

For the complete compilation of Linux commands, click on this link: List of Linux commands