是否有一个终端命令可以将文件夹一分为二?

是否有一个终端命令可以将文件夹一分为二?

我的运行 Ubuntu 12.04.1 的 iMac G5 上有一个包含 80,000 个文件的文件夹,但我甚至无法使用 Nautilus 打开它,因为它会冻结。

我可以ls -a在终端中执行此操作,它会向我显示一切。

有没有一个终端命令可以用来将其拆分成两个大小相等(就文件数量而言)的目录,以便 Nautilus 更容易打开其中一个?或者可能是 4 个文件夹?

答案1

ls -1 | sort -n | head -40000 | xargs -i mv "{}" /destination/folder/

调整head -40000以满足您的需求,/destination/folder/

答案2

尝试下面这个脚本,我在Linux问题网站

PhotosPath="/media/4GBSD/DCIM/101CANON"
SortPath="/home/angus/.imagesort"
LibraryPath="/home/angus/Photos"
CameraPath="/media/4GBSD"

请重命名这些路径以满足您的需要

#!/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…"

相关内容