How to copy a specific file in a folder using terminal - linux

I am using terminal on linux. I am in my current folder now. I want to take a file in this folder that I am currently in and copy it in the exact same folder and I also want to rename it.
What command should I use?

Copy command works well.
cp /currentfolder/filename /currentfolder/newfilename

If you wanna copy a file like .cpp file it is really easy to use:
cp filename.cpp destination

Related

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

Copy only the files within a Directory and not the Directory

I'm trying to copy images in a directory using Python 2.7.12. The problem is that I want to only move the files within the Directory and not the Directory.
So in bash it would look something like
cp /path/to/source/* . /path/to/destination
but I want to do this in Python 2.7.12. I know how to copy the directory using things like shutil.copy but you can't add the /* to move the files within the directory. I'm kind of new to python and Stack Overflow so I'm sorry if there is any errors or confusion.
You could just use cmd terminal if your a windows user.
Type in help Robocopy and it should display different options

Cygwin copy directory with wrong name

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

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.

How to use command zip in linux that folder have short path?

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

Resources