Here is a bash script that does that:
Note: This script does not work if any of the file names contain spaces.
# Only go through the directories in the current directory.
for dir in $(find ./ -type d)
# Remove the first two characters.
# Initially, $dir = "./directory_name".
# After this step, $dir = "directory_name".
# Skip if $dir is empty. Only happens when $dir = "./" initially.
if [ ! $dir ]
# Go through all the files in the directory.
for file in $(ls -d $dir/*)
# Replace / with _
# For example, if $file = "dir/filename", then $new_file = "dir_filename"
# where $dir = dir
# Move the file.
mv $file $new_file
# Remove the directory.
rm -rf $dir
- Copy-paste the script in a file.
- Make it executable using
chmod +x file_name
- Move the script to the destination directory. In your case this should be inside
- Run the script using