I need to use a shell script to move all files in a directory into another directory. I manually did this without a problem and now scripting it is giving me an error on the mv
command.
Inside the directory I want to move files out of are 2 directories, php and php.tmp. The error I get is cd: /path/to/working/directory/php: No such file or directory
. I’m confused because it is there to begin with and listed when I ls the working directory.
The error I get is here:
ls $PWD #ensure the files are there mv $PWD/* /company/home/directory ls /company/home/directory #ensure the files are moved
When I use ls $PWD
I see the directories I want to move but the error afterward says it doesn’t exist. Then when I ssh to the machine this is running on I see the files were moved correctly.
If it matters the directory I am moving files from is owned by a different user but the shell is executing as root.
I don’t understand why I would get this error so, any help would be great.
Advertisement
Answer
Add a /
after the path to specify you want to move the file, not rename the directory.
You should try this:
mv $PWD/* /home/user/directory/