trying to CP a directory to /dev/null
What I'm really tring to do, it verify the the data on an external drive is still readable. I thought the simplest and surest way to do this would be to copy everything to /dev/null
. It works great for a file. But when I add -R
to recursive copy a dirfectory structure, if fails (presumably) because it can't create subdirectories in /dev/null
.
When I try :
cp -R Flintstones/ /dev/null
I get :
cp: cannot overwrite non-directory '/dev/null' with directory 'Flintstones/'
But this works:
cd Flintstones
cp Fred.txt /dev/null
How can I copy the entire directory in one go??
Thank you, and please be gentle with the newbie.
Solution 1:
I found a nice way to replace rsync for reading out my harddisk without copying.
In bash window #1 run this command:
tar -cv <path to your hard disk> 2>/tmp/tt |pv >/dev/null
Progress in Bytes / MB / GB is shown along with the current transfer speed, e.g.:
$ sudo tar -cv /mnt/mnt/ 2>/tmp/tt |pv >/dev/null
111GiB 0:21:57 [99,0MiB/s] [ <=> ]
In bash window #2 run this command to show the file that is currently being read (terminate with ctrl-c once the test is completed).
tail -f /tmp/tt
This works even if your hard disk contains special files like block device descriptors.
Background: tar -cv <dirname> creates an archive containing all the files in <dirname>. The output goes through the pipeline ("|"), the filenames are printed to stderr which is redirected to /tmp/tt. pv prints out the size and the current transfer speed. Using the option "-s" you could tell pv how large your data is (e.g. "pv -s 370G"), so it can also print out the percentage of data already copied:
$ sudo tar -cv /media/jcs/SG4TBR1/ 2>/tmp/tt |pv -s370G >/dev/null
24,7GiB 0:04:07 [ 130MiB/s] [=> ] 6% ETA 0:57:27
"tail -f /tmp/tt" simply prints the contents of /tmp/tt and continues to show any changes (-f: "follow").
Solution 2:
Hello and welcome to Ask Ubuntu!
If I understood your question correctly you just want to run some command that will read all files in the given directory, but you are not interested in any output other than potential error messages saying files could not be read. You can achieve that for example using the grep
command, like this:
grep -r Zaphod Flintstones/
The above command means that grep
will recursively go through all files in the Flintstones
directory looking for the string "Zaphod" (you could put some other string there, it does not matter, just something for grep
to search for, if you want no output pick something that you think will not occur in any file). If the command completes without error messages about unreadable files, then that means the directory is readable.
Not saying this is the best way, probably there are more elegant ways, but the above is one way of doing it.