Lots of questions like this one but none of them have helped and i've already killed a day on this single command.
Basically I need to understand how I can mv a folder into a subfolder in the same directory from a bash script.
To isolate this problem as much as possible i made the following movetest.sh:
sudo mv /home/zoctavous/vault/repos/work/recup_dir1000/ /trash/
All the folders specified exist and there are no folders that are currently named this. All I get in response is
mv: cannot stat '/home/zoctavous/vault/repos/work/recup_dir1000/': No such file or directory
please help :(
I figured out my issue... I was deleting part of the filename farther up in the script that it was a part of.
/home/zoctavous/vault/repos/work/recup_dir.1000/ is the actual directory name.
the variable for the directory was being stored as shown above
/home/zoctavous/vault/repos/work/recup_dir1000/
Related
Ive looked over some other questions similar to this but none of the solutions worked for me. I've got two directories Teacher and Employee. I've got a file in the Teacher directory called Emp7.tar.gz and i want to move it into the Employee directory. I'm using a shell script to move it but i keep getting the same error. The code im using to move it is
#:/bin.bash
mv Emp7.tar.gz Employee/
I know its probably simple but im just getting used to linux so any help is appreciated.
Welcome to StackOverflow! If your working directory is Teacher, then your command should be:
mv Emp7.tar.gz ../Employee/
If your working directory is one above Teacher, then your command should be:
mv Teacher/Emp7.tar.gz Employee/
If your working directory is Employee, then your command should be:
mv ../Teacher/Emp7.tar.gz .
mv Emp7.tar.gz ../Employee
You need to specify the relative path to the Employee directory.
As you're in the Teacher directory, you need to get up once
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.
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/
Are your variables properly quoted? You could try :
ls "$PWD" #ensure the files are there
mv "$PWD"/* "/company/home/directory"
ls "/company/home/directory" #ensure the files are moved
If any of your file or directory names contains characters such as spaces or tabs, your "mv" command may not be seeing the argument list you think it is seeing.
I have a bash script which i want to call from any directory, but i don't want to add the directory it is in to PATH as it is filled with lots of other scripts which will just clutter.
The script in question manipulates environment variables, so i have to source it.
I tried creating an alias
alias aliastoscript="/path/to/script"
source aliastoscript #This does not work says no such file
I also can't copy the script itself to a different location as it depends on the directory structure and other scripts in the directory.
So i tried a symlink to a location already in path:
ln -s /path/to/script /directory/already/in/path/myscript
But this does not work either:
source myscript #says no such file exists
Can anyone suggest how i achieve this? And why does the symlink approach not work?
If it makes any difference, i am using a zsh shell on ubuntu 14.04
EDIT:
The answer given below works, but i also wanted to know why the symlink approach was not working.
Here is the sequence of commands
ln -s /path/to/script /directory/already/in/path/myscript
#Now there is a symlink called myscript in a directory which is in PATH
source myscript arg1 #This throws an error saying no such file myscript,
#but it is not supposed to happen because myscript resides in a directory which is in PATH
EDIT 2:
I just figured what i was doing wrong, the symlink i created, i had used relative paths, totally stupid of me, using absolute paths it worked like a charm.
Try replacing:
alias aliastoscript="/path/to/script"
with:
export aliastoscript="/path/to/script"
You have a $ missing in front of the variable name.
source $aliastoscript
You do not need soft link for the source. The complete file name should work. Better is
source /path/to/script
I used command zip in linux (RedHat), this is my command:
zip -r /home/username/folder/compress/zip.zip /home/username/folder/compressed/*
Then, i open file zip.zip, i see architecture as path folder compress.
I want to in folder zip only consist list file *.txt
Because i used this command in script crontab hence i can't use command cd to path folder before run command zip
Please help me
I skimmed the zip man page and this is what I have found. There is not an option archive files relative to a different directory. The closest I have found is zip -j which removes the entire path and stores the files directly in the zip rather than sub directories. I do not know what happens in the case of file name conflicts such as if /home/username/folder/compressed/a.txt and /home/username/folder/compressed/subdir/a.txt both exist. If this is not a problem for you, you can use this option, but I am concerned because you did specify the -r option indicating that you expect zip to traverse sub folders.
I also thought of the possibility that your script could somehow call zip with a different working directory, but I took a look at this unix stack exchange page and it looks like their options use cd.
I have to admit I do not understand why you cannot use cd and I am very curious about it. You said something about using crontab, but I have never heard of anything wrong with changing directories in a crontab script.
I used option -j in command zip
zip -jr /home/username/folder/compress/zip.zip /home/username/folder/compressed/*
and i was yet settled this problem, thanks
I want to move csv file from home folder to tmp folder in linux OS using below command:
$ mv /home/users_data.csv /tmp
But I am getting below error:
mv: cannot stat `/home/users_data.csv': No such file or directory
Kindly suggest me, how to resolve this error.
Hope for reply.
Thanks
It is most likely /home/your_username/users_data.csv what you need or shortly: ~/users_data.csv. So the error exactly tells you what is wrong.
There can be two possible reason of this error:
1. The source directory may not exist,
(OR)
2. The source directory might be empty.