Score:0

lost file after do "mv" file in filename.sh

nu flag

I try to run filename.sh which contains:

mv /home/newdir/test1.jpg /home/backupdir
mv /home/newdir/test2.jpg /home/backupdir
mv /home/newdir/test3.jpg /home/backupdir
mv /home/newdir/test4.jpg /home/backupdir
mv /home/newdir/test5.jpg /home/backupdir

after that, my test.jpg file is not located on /home/backupdir, and that has 2 backupdir:

backupdir and 'backupdir'$'\r'

Then I try to "cd" to 'backupdir'$'\r' but the result is:

bash: cd: $'backupdir\r': Not a directory

Any can help me, please? or maybe have the same issue as me?

hr flag
Unfortunately if your script was written with Windows line endings (CRLF in place of plain LF) and there wasn't a pre-existing directory named `/home/backupdir\r` then you likely created and then overwrote the same file multiple times.
Score:0
ni flag

Try adding a / to the end of your mv commands. I think whats happening is you're creating a file named backupdir with the contents of test*.jpg, and then overwriting it many times.

Also, you can use wildcards instead of running many commands.

mv /home/newdir/test*.jpg /home/backupdir

If this dosent work please answer:

  • What is in newdir?
  • Is this script being run as root?
  • Post the ls of your home directory.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.