TotalSizeAfter=$(( `du -hks testfiles | cut -f 1 -d \t` / 1024 ))Įcho "Total space occupied before: $totalSizeBefore" MiBĮcho "Total space occupied after: $totalSizeAfter" MiB TotalSizeBefore=$(( `du -hks testfiles | cut -f 1 -d \t` / 1024 )) Let’s run it and take a look at the log:īased on that, let’s write another Bash script, which we can save as noDuplicates.sh, that parses the output of fdupes and replaces duplicates with hard links: #!/usr/bin/env bashĮcho "Please specify the directory in which to search for duplicates"Įcho "Looking for all duplicates in the $1 folder and its subfolders." TotalSize=$(( `du -hks testfiles | cut -f 1 -d \t` / 1024 ))Įcho "Total space occupied: $totalSize" MiBĪs this self-explanatory code suggests, it creates a total of 30 files of 1 MiB each, five of which are duplicates. # Check total space occupied (rounded down in MiB) # Creates five subdirectories with five random files eachĭd if=/dev/urandom of="$file" bs=1024 count=1024 2>/dev/nullĬp $directory/subdir1/file1.bin $directory/duplicate1.binĬp $directory/subdir1/file1.bin $directory/duplicate2.binĬp $directory/subdir3/file3.bin $directory/duplicate3.binĬp $directory/subdir5/file4.bin $directory/duplicate4.binĬp $directory/subdir5/file4.bin $directory/duplicate5.bin # Creates the $directory folder if it doesn't existĮcho "$directory already exists, exiting." Let’s start by writing a Bash script that creates a testfiles folder containing various files with random contents, distributed in different subfolders, and with some duplicates: #!/usr/bin/env bash
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |