2

I have 6 .txt files on my desktop that I am trying to move using the Terminal. However when I try to mass move them all into the texts folder that is on my Desktop, I get the the following error:

mv: cannot stat ‘Desktop/*.txt’: No such file or directory

Here is the code that I am executing to perform the task:

mv Desktop/*.txt Desktop/texts

What am I doing wrong?


Also I am currently in ~/home/dlundy1


Here is out of ls -al ~/Desktop/*.txt

ls: cannot access /home/ubuntu/Desktop/*.txt: No such file or directory

** NOTE: ** I want to get the hang of using only the terminal to perform basic tasks to please restrict solutions to those that don't utilize GUI.

  • Would you please edit your question and add your current working directory (prompt or pwd output) and the output of ls ~/Desktop/*.txt? Thank you! – Byte Commander Apr 16 '15 at 21:12
  • 1
    Desktop/*.txt is called a "relative pathname", meaning the path is relative to the directory you are currently in. If Desktop/ is not a child directory of your present working directory, you would need to use an "absolute pathname", such as /home/user/Desktop/*.txt or ~/Desktop/*.txt, where ~ expands to the current users home directory. – cremefraiche Apr 16 '15 at 21:15
  • current directory: ~/home/dlundy1 – dlundy1 Apr 16 '15 at 22:05
1

Did you create the directory first? If not,

mkdir Desktop/texts

Use the -p option to create intermediate directories that are missing.

mkdir -p Desktop/texts/DoesNotExist/NotHere/Yet

You also didn't mention in what path you are currently in, by default the Terminal session starts in your own home directory, but to make sure you could use the full path or the ~ to indicate your home directory. ~ gets expanded to fill out the rest of the path of your home directory.

After making sure the destination exists,

mv ~/Desktop/*.txt ~/Desktop/texts

Because of the ~, its the same as using,

mv /home/dlundy1/Desktop/*.txt /home/dlundy1/Desktop/texts
  • I did not use this command to create the directory, However I assumed that it exists because I can see it on my desktop. And I am currently in home/dlundy1 – dlundy1 Apr 16 '15 at 21:57
  • Please then, as ByteCommander asked, edit and post the output of ls -al ~/Desktop/*.txt. Also, does the following work command work, cd ~/Desktop/texts or does it return an error? If the latter, post the error please. – Sinn3d Apr 17 '15 at 6:08
  • post updated with output of ls -al ~/Desktop/*.txt – dlundy1 Apr 17 '15 at 20:16
1

When files with names ending in .txt exist in the directory ~/Desktop, the bash shell will replace ~/Desktop/*.txt by the list of files that match the glob pattern *.txt before the mv command is executed:

mv ~/Desktop/*.txt ~/Desktop/texts

would be changed to

mv ~/Desktop/first.txt ~/Desktop/second.txt ~/Desktop/texts

if ~/Desktop contains first.txt and second.txt, for example.

But if there are no files matching the glob pattern *.txt in ~/Desktop, the shell has nothing to replace it. Depending on the shell options, it will either refuse to run the command, showing an error, or it will just not change the command, and run it as is. In your case, it did the second: So mv tries to move the file with the name *.txt in directory ~/Desktop - but it turns out there is no such file.
The error cannon stat means it can not find anything by that name.

So the problem seems to be that the files you like to move do not exist in that directory. Maybe you already moved them?

0

You should write the following

mv ~/Desktop/*.txt ~/Desktop/texts

You forgot the ~ which indicates your home directory .

  • 1
    Depends on the directory he is in! If his working directory (pwd output) is already ~/=/home/USERNAME/, the command will also work with just the relative part. – Byte Commander Apr 16 '15 at 21:14
  • 2
    i assume that he isn't in his home directory because as you can see the error is ‘Desktop/*.txt’: No such file or directory – nux Apr 16 '15 at 21:17
  • Yes, just to make it sure and obvious also for future readers who don't know this. – Byte Commander Apr 16 '15 at 21:24
  • I tried this, no luck. mv: cannot stat ‘/home/dlundy1/Desktop/*.txt’: No such file or directory – dlundy1 Apr 16 '15 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.