Cygwin copy directory with wrong name - cygwin

I create a little script to copy a directory.
Sadly, cygwin do not copy the name of the directory, but instead copy all the content in a directory called ·(it's an intepunct, not a dot en.wikipedia.org/wiki/Interpunct ).
There are no problems to execute all the commands directly in the terminal!
Anyone has ideas?
this is the script:
cp -r //REMOTE-PC/folder1/folder2/folder-to-copy/ ./local-folder/folder-to-copy/
thanks

Related

Copy Linux files to another location

We have a linux server and for some transactions it is keeping the log files only for the last 10 days. After than the file gets deleted. I want to copy these files to another location using a script. I searched google but couldn't satisfactory result. I'm new to Linux also.
Can someone please guide me if this can be achieved and how ?
You can use the previous answer by nissim abehcera in a sh script:
cp -R SOURCE_DIRECTORY DESTINATION_DIRECTORY
Just paste the bash commands in a text file, name it file.sh and make sure it is executable:
chmod +x file.sh
You can just run the script and it will do whatever you wrote in there.

How do I make a copy of one directory files(hidden files included) into another directory?

I'm trying to make a copy of one directory files into another directory.
I have Desktop/projectOne and Desktop/projectTwo and I'm trying to copy projectOne files into projectTwo. I need to use terminal for this as I need to copy hidden files also and I'm not familiar with linux commands...
So my question is...
What commands do I have to use to copy all files (hidden files included) from Desktop/projectOne to Desktop/projectTwo?
What commands do I have to use to copy only hidden files from Desktop/projectOne to Desktop/projectTwo?
Thanks in advance.
cp -r
Example: cp -r /oldfolder /home/newfolder
Noticed: if newfolder is already exist it will create new folder in it
/home/newfolder/oldfolder

Files get copied and renamed but I also get errors

I have a script that reads a text file that has all the nodes listed in there:
node1
node2
node3
.
.
.
It creates a ".conf" file for each node in the /etc/icinga2/zones.d/master/hosts/new/ directory
Copies the content of the file name linux-template into each new conf file.
Everything worked as I expected, but I also get errors for each node:
Can anyone please help?
Thanks
This is my script:
#!/bin/bash
cd /etc/icinga2/zones.d/master/hosts/new
while read f; do
cp -v "$f" /etc/icinga2/zones.d/master/hosts/new/"$f.conf"
cp linux-template.conf "$f.conf"
chown icinga:icinga "$f.conf"
done < linux-list.txt
Once everything got copied, I get these errors below (for all the nodes, ie. node 1):
cp: cannot stat ‘node1’: No such file or directory
chown: cannot access ‘node1’: No such file or directory
It looks like it's complaining because there isn't a file called "node1" in your directory and you have verbose mode on.
This script looks like it will also cause undesired behavior if you're not located in the /etc/icinga2/zones.d/master/hosts/new/ directory when you run it.
The script is saying:
Copy files node1,node2,... in my current directory and place the
copy here: /etc/icinga2/zones.d/master/hosts/new/"$f.conf"
Copy linux-template.conf from the current directory and name it "node[1-9].conf" in the current directory.
Chown the "node[1-9].conf" in the current directory.
I suggest using absolute paths and I'm not quite sure why the first cp is necessary. If you're intending to copy linux-template.conf into each node[1-9].conf that you created in step 1, the second copy will create and overwrite the file anyway and step 1 would not be needed.

linux source a symbolic link

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

Bash, copy files from folder to another

I have a problem with an Uni OS Course assignment.
Basically the task says:
Deliver now a file for assessment. The content of the file is: one line, containing a command that
copies all files with prefix "2016", from directory "ExercisesOS" to directory "OSLab".
Consider the current directory to be "~" when writing such command.
I have already tried with that code:
cp /ExercisesOS/2016* /OSLab
but it performs me two error.
How can I write the correct command?
You probably want to copy from the directory you are working.
To check where you are working:
$ pwd
/home/userdir
To copy from your working directory:
$ cp ExerciseOS/2016* OSLab/
mkdir OSLab && cp /ExercisesOS/2016* OSLab
This solution would assume that the directory 'OSLab' isn't already created.

Resources