I keep trying this,and I keep doing something wrong.
Code:
$ for FILE in /home/user/Desktop/test2/ ; do
> mv $FILE ${FILE##*-}
> done
mv: cannot move `/home/user/Desktop/test2/' to a subdirectory of itself, `/home/ I don't want to move to another directory,just rename the files and keep them in the same directory.
NOTE:Until I feel comfortable doing this,I'll be testing these commands on test files or copied files in test directories.
Code:
$ for FILE in /home/user/Desktop/test2
> NEWNAME="${FILE##*_}"
bash: syntax error near unexpected token `NEWNAME="${FILE##*_}"' Here I didn't even get the chance to finish the command.
I have no clue as to the syntax error here.
I found this yesterday at another forum and this seems to be working.
Here,I opened a terminal in the directory I want to change the file names in,rather than cd to the directory or state the full path to the directory in the command itself.
I've ran into problems before with using the /path/to/file in the command because there was a space in front of the filename I didn't notice.
Instead of
/home/user/Desktop/practice/test.txt
it was
/home/user/Desktop/practice/ test.txt
What a problem that was because all the commands were in proper order,and not working,because the /path/to/filename wasn't correct when I didn't see the space.
I was several days banging my head because of this space.
I look for this a lot closer now.
Anyhow,this command appears to work good.
Code:
$ for f in *test*.txt; do mv -vf "$f" "${f#*-}"; done
`01-test1.txt' -> `test1.txt'
`02-test2.txt' -> `test2.txt'
`03-test3.txt' -> `test3.txt'
$ Just because this seems to be working,I don't want to abandon what has been suggested here.
I want to get through this and understand where I am making my mistakes with the examples presented here.
There is something I'm doing wrong,just like not seeing a space as I mentioned above.
What is the difference between this command I found at another forum and the commands given here?
I've tried them all except the one ghostdog74 has given.
I'll get to trying that next.
I appreciate every reply.