cd path/to/directory FILE_EXT="txt" for x in *.txt; do mkdir "${x%\.txt}" && mv "$x" "${x%\.}" done