Last active
November 2, 2020 13:32
-
-
Save daysm/7608a27fe4519c7ee4c544b8d5c38a71 to your computer and use it in GitHub Desktop.
Move files to (new) directory based on file name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
START=$1 | |
END=$2 | |
for file in *; do dir=$(echo $file | cut -c $START-$END); mkdir -p $dir; mv "$file" "$dir"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To do this for multiple directories, the command could look like this:
for dir in dir1 dir2 dir3; do cd $dir && ../scripts/move-files-to-new-directory-based-on-file-name.sh 27 43 && cd .. ; done