Splitting files in Mac and then adding .csv extension removed them?
I have been following the methods from this YouTube video.
Method:
cd /Volumes/Seagate/Work/Tickets/Thirdticket/Extinction/species_all.df
split -b 10000m species_all.csv
for i in *; do mv "$i" "$.csv";done
However, when I got to this part:
for i in *; do mv "$i" "$.csv";done
It seemed to have removed all the files (not sure where they have gone as they re not in the bin folder) and left a single file with the .csv
extension, named as $.csv
.
Any idea what has happened and whether these files can still be located?
Solution 1:
You have a typo in your code.
And who can blame you, the terminal screen in that video is almost impossible to read.
Look at the problematic line in question:
for i in *; do mv "$i" "$.csv";done
The key command in that line is this:
mv "$i" "$.csv";
The filename would be contained in $i
which is the source file. But then your destination file is this $.csv
. That $
is really meaningless on its own in Bash. So the designation file is effectively .csv
.
So what happened is each split file was moved (mv
) into the filename .csv
. Meaning all of the files are gone and .csv
contains only the contents of the very last file.
So getting back to the code, you should start from the beginning again. But when you reach that problematic line, change that$.csv
to $i.csv
so the command becomes:
for i in *; do mv "$i" "$i.csv";done
This is confirmed by watching that video… Which to be honest is terribly difficult to read. But here is a screenshot of the pertinent part.
This should solve the issue, but I will suggest that if you want to learn about the macOS command line, you seek out web pages and textual aids and tutorials and videos like this where people post stuff like this as click-bait.
I mean that video is fairly useless as far as being able to read that text goes. And people post stuff like this to “boost views” for their own purposes; not really to help end users like yourself.
Seriously, just look at this screenshot of the Terminal in the video: It is somehow captured in portrait mode (?!?) on a Desktop with the bulk of the video being either blank space on the left and right or the dude’s desktop. What a horrible user experience it is to view — and gain knowledge — from a video like this.