Welcome to forums. While seeing your code I think you need to rename all txt files into your present directory. If this is the case then following may help you in same.
for file in *.txt; do echo mv $file ${file%_*}$(date +%Y%m%d%H%m)".txt"; done
Above code will write the move command, so if you are ok with this then you could remove echo in bold above code and could change the .txt files to as per your need.
EDIT: Adding a non-one liner form of solution above too.
for file in *.txt
do
echo mv $file ${file%_*}$(date +%Y%m%d%H%m)".txt"
done
Yes, it will rename the files in current folder where you are running the script or command as mentioned above. In case we want it to take care of a folder where we are not currently in then you should mention the complete path of those .txt files as follows.
for file in /tmp/test/*.txt ######Basically mention complete path of .txt files in here.
do
echo mv $file ${file%_*}$(date +%Y%m%d%H%m)".txt"
done
As mentioned before you could remove echo from your code in case you are happy with the printed commands by echo .
Please use code tags as per forum rules into your posts. I think above error shows because command is not able to find files.
So could you please try following, seems you haven't used correct variable names.
DPATH=/your/actual/path/where_files_are_present
for file in ${DPATH}/*.txt.pgp; do mv ${file} ${file%_*}$(date +%Y%m%d%H%m)"test.txt.pgp" ; done
I haven't tested above but you should make sure you are using correct variable names and value of variable named DPATH is set as per your system.
The permissions to rename a file are required on the directory. The file exists as just a collection of data blocks on disk somewhere and it is the directory that holds the file name, references when to find the data blocks, file permissions etc. To rename the file, you are actually editing the directory.
If you are in the appropriate directory/directories, can you run the following:-
id -G
ls -ld .
This will show some of your account details and the directory details.