Formatting Hard Drives
Source: nixCraft
Partition the new disk
sudo fdisk -l | grep '^Disk'
Output:
Disk /dev/sda: 111.8 GiB, 119998218240 bytes, 234371520 sectors
Disklabel type: gpt
Disk identifier: <some identifier>
Disk /dev/sdc: 447.1 GiB, 480070426624 bytes, 937637552 sectors
Disklabel type: dos
Disk identifier: <some identifier>
Disk /dev/sdb: 111.8 GiB, 119998218240 bytes, 234371520 sectors
Disklabel type: gpt
Disk identifier: <some identifier>
Partition the disk you want. In this case, I’m partitioning the second disk or sdb
sudo fdisk /dev/sdb
Generally, you would delete the partitions you need to and add the partitions as needed. When creating a new partition, I generally use a primary partition if I’m going to use the whole disk
Format the new disk
To format the Linux partition on the new disk
sudo mkfs.ext4 /dev/sdb1
Mount the new disk
The general process is to create a mount point and then mount the disk to the mount point
sudo mkdir /[new directory name for mount point]
sudo mount /dev/sdb1 /[new directory name for mount point]
df -H
Update the /etc/fstab file
sudo vi /etc/fstab
Append the following line to the file
/dev/sdb1 /[new directory name for mount point] ext4 defaults 1 2
File Management
Deleting Files
Delete files older than 30 days
find [directory name] -type f -mtime +[number of days] -exec rm -f {} \;
find /opt/backup -type f -mtime +30 -exec rm -f {} \;
Delete files with a filter
find [directory name] -name "[file filter]" -type f -mtime +[number of days] -exec rm -f {} \;
find /var/log -name "*.log" -type f -mtime +30 -exec rm -f {} \;