Sample Header Ad - 728x90

Moves files with the same name to a directory and writes the counted number to the directory name

0 votes
1 answer
54 views
find /volume1/file/* -type f \( -name "*DF*" -a -name "*LIVE*" \) -print0 | while IFS= read -d '' file do # extract the name of the directory to create dirName="${file%.E*}" count=$(find "$file" -type f | wc -l;) # create the directory if it doesn't exist [[ ! -d "$dirName$count" ]] && mkdir "$dirName$count" mv "$file" "$dirName$count" done Hi there, I'm using another coder's shell script, but I modified it because I wanted to add more features, but it doesn't work modified part count=$(find "$file" -type f | wc -l;) For example, there are about 10,000 files in my Linux HDD, and among those 10,000 files, I read the file title before ".E" and create a directory with that title to move the files. Here, I want to put the number of files in that directory into the directory name. EX) artist.E01.DF.LIVE artist.E02.DF.LIVE artist.E03.DF.LIVE artist.E04.DD.LIVE directory name = "artist3" I want to do this, but with the script I modified, only 1 is counted
Asked by anisphia (3 rep)
Mar 13, 2023, 08:46 AM
Last activity: Mar 13, 2023, 11:53 AM