Is there a terminal command to split a folder in two?
I have a folder with 80.000 files on my iMac G5 running Ubuntu 12.04.1 and I can't even open it with Nautilus because it freezes.
I can do ls -a
in Terminal and it shows me everything.
Is there a terminal command I could use to split it in two equally sized (in terms of number of files) directories so it would be easier for Nautilus to open one of them? Or maybe 4 folders?
Solution 1:
ls -1 | sort -n | head -40000 | xargs -i mv "{}" /destination/folder/
Adjust head -40000
to fit your needs, also /destination/folder/
Solution 2:
Try this script below i found it on Linuxquestions.org
PhotosPath="/media/4GBSD/DCIM/101CANON"
SortPath="/home/angus/.imagesort"
LibraryPath="/home/angus/Photos"
CameraPath="/media/4GBSD"
please rename these path to fit your needs
#!/bin/bash
#
#
PhotosPath="/media/4GBSD/DCIM/101CANON"
SortPath="/home/angus/.imagesort"
LibraryPath="/home/angus/Photos"
CameraPath="/media/4GBSD"
CharFromName=4
echo
echo
############
# Test to see if $PhotosPath exists, if not promp for new path / exit.
test -d $PhotosPath || read -p "$PhotosPath does not exist, close to exit or type new path:" PhotosPath
test -d $PhotosPath || "read -p '$PhotosPath is invalid. Press enter to close' && exit"
############
# move files from camera to $SortPath
mv $PhotosPath/* $SortPath/
############
# rename all image files in $SortPath
# FolderDateDD-HHMMSS.ext
jhead -autorot -ft -nf%y%m%d-%H%M%S $SortPath/*
###########
# Sort files into folders using $CharFromName letters of the file name
#
ls $SortPath | while read file; do
# extract first $CharFromName characters from filename
FolderDate=${file:0:$CharFromName}
# create directory if it does not exist
test -d $LibraryPath/$FolderDate || mkdir $LibraryPath/$FolderDate
# move the current file to the destination dir
mv -v $SortPath/$file $LibraryPath/$FolderDate/$file
done
##########
# move sorted files into photo library
#mv -v $SortPath/* $LibraryPath/
##########
# Umount the card
umount $CameraPath
##########
# End notification
echo
echo "Photos from: $PhotosPath"
echo "End location: $LibraryPath"
echo
echo "The card has been ejected."
echo
read -p "Press enter to close this window…"