Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm currently trying to recursive copy a hidden directory using this command
cp -r ../openshiftapp/.openshift .
It is not working.. what can be wrong?
On OS X you should use -R rather than -r. The man page (on Snow Leopard 10.6.8) says:
Historic versions of the cp utility had a -r option. This implementation supports that option; however, its use is strongly discouraged, as it does not correctly copy special files, symbolic links, or fifo's.
The recursive option for the cp command would be used on directories, not files. The documentation states:
-R, -r, --recursive
copy directories recursively
The OSX docs have more info, but don't suggest that the option can be used with files. Instead, it still mentions their use for copying directory contents:
-R If source_file designates a directory, cp copies the directory and the entire subtree connected
at that point. If the source_file ends in a /, the contents of the directory are copied rather
than the directory itself. This option also causes symbolic links to be copied, rather than
indirected through, and for cp to create special files rather than copying them as normal files.
Created directories have the same mode as the corresponding source directory, unmodified by the
process' umask.
In -R mode, cp will continue copying even if errors are detected.
Note that cp copies hard-linked files as separate files. If you need to preserve hard links, consider using tar(1), cpio(1), or pax(1) instead.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have two scripting files to be moved to a new directory.
with mv command I moved those files but couldn't find them in the new directory.
I did a mistake of not providing the filenames in the destination folder. The files are not present anywhere. How to get my files back?
from user1 I moved files
sudo mv script1 /infinitescripts
sudo mv script2 /infinitescripts
I expected script1 and script2 files to be present in infinitescripts directory. But, the directory is empty and the files are not present in the source as well. I dont know where my files are gone.
If I have a file myfile in folder A (so, A/myfile), and I want to move that file into a folder B inside of folder A (so, into A/B/), I need to use mv myfile B. That will result in there being a file A/B/myfile.
What you ran was the equivalent of mv myfile /B, with that extra / in front. What the extra / does is tell the system to look in the root directory for that folder.
So what you did was accidentally created a folder in the root directory called infinitescripts and moved your file into there. The file should be safe and sound. To find it, you can go to that directory with
cd /infinitescripts.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
How to delete large file path/file name files in Windows. Which is slimier to Linux rm -rf . ?
To delete The file name is too long. errors files, we've to go for simple steps using default command of Windows robocopy and rmdir.
Create directory mkdir deleteLongFilesDir under C: or D: drive
Suppose D:\Development\Liferay\themes directory contains the files which are not able to delete simply.
run command in command prompt robocopy D:\deleteLongFilesDir D:\Development\Liferay\themes /purge , this command will print some logs and copy you all the files and sub directory of D:\Development\Liferay\themes into deleteLongFilesDir folder virtually, but when you open that directory... hurreeee...It's Empty ???
Now run the command of remove directory which we created for mapping rmdir deleteLongFilesDir from command line.
Now temporary directory has been deleted and same as for D:\Development\Liferay\themes files and folder.
There is a Powershell cmdlet named Remove-Item2, written by Boe Prox a well-known MVP, and which circumvents the basic limitation path of 260 characters.
https://gallery.technet.microsoft.com/scriptcenter/Remove-LongPathFile-7a4db495
Additionally, like Remove-Item2, there are other cmdlets suffixed by the number 2, like Get-ChildItem2, which are often included in popular third party modules, and also addresses the 260 characters limitation. If you have installed some of these modules, there is a chance that you have already those cmdlets on your computer.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
This post was edited and submitted for review 11 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have this directory called "mock", which contains 3 directories. I am trying to copy all the items from "mock" directory into the "projweek" directory using the following command:
cp /mock/* ~/projweek
But I get this error:
cp: cannot stat ‘mock/*’: No such file or directory
Any ideas as to why that is?
If your source directory is set in quotes, then make sure that the * is outside the quotes, i.e.
cp "source/"* dest
or
cp "source"/* dest
It's an odd thing about the unix system that glob expansion (aka use of the "*") is done by the shell, and not by the program you are calling, and furthermore, if the glob doesn't match anything, instead of expanding to nothing, it expands to itself and passes that to the program. So the cp command sees literally "/mock/*" which doesn't exist, because you have no file called "*". Somewhat perversely if you had a file called "*" it would dutifully copy it without complaining.
cannot stat = file/dir does not exist. Check the path first.
And, you say you want to copy /mock but the error message says mock. Show the real code first.
When I test in ubuntu, cp (GNU coreutils) 8.28, I have no problem with copying all files under a dir to another dir, when both paths are correct.
root#DESKTOP-9NHNV2I:~# cp /root/temp/* /root
root#DESKTOP-9NHNV2I:~# ls
temp test.txt test2.txt test3333.txt
cp is used in unix/linux for copy
cp /mock/* ~/projweek this means copy from /mock folder all files to folder projweek that resides in root
This means cp: cannot stat ‘mock/*’: No such file or directory unable to copy all files from mock folder because file or directory not exists on relevant path
cp: cannot stat ‘mock/*’: No such file or director
Check that the files exist on the path.
Also to copy all the files in a folder to another location, use . operator like: cp /source/. /dest/
When I configured shell script on jenkins(See the following lines), I got this error "cp cannot stat ... No such file or directory".
ssh user#remoteNode
cd /somedir
cp fromdir/xxfile todir/xxfile
The following command solves my problem.
ssh user#remoteNode "cd /somedir; cp fromdir/xxfile todir/xxfile"
Why?
Double quotation marks are required. If not, the cp command will be executed locally.
Thanks to CDSN blogger Jinking01.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
Im trying to write a script that keeps a tar in sync with a folder. I am dealing with a lot of files and don't want to remake the tar every time the script is run. I want it to only add/remove files from the tar that have been added/removed from the folder since the last script run. Here's what I have.
# Create tar if it doesn't exist but don't over write if it does exist
touch -a /home/MyName/data.tar
cd /home/MyName
# Make the tar
tar -uv --exclude='dirToTar/FileIWantToExclude' -f $tarFile dirToTar
This works great for adding files. But if a file is deleted from dirToTar, it doesn't get removed from data.tar.
Unfortunately, tar just doesn't support this. As an alternative, you could use zip, like this:
zip -r -FS myArchiveFile.zip dirToZip
Not "tar" like you asked for, but it does seem to work nicely. Another alternative would be to use 7z (the 7-zip archiver), which may give you better compression. The command-line options for this is obscure, but this works:
7z u -up1q0r2x2y2z1w2 myArchiveFile.7z dirToZip
(I found documentation for these 7z command-line options here: https://www.scottklement.com/p7zip/MANUAL/switches/update.htm. I don't know why it's so hard to find this documentation...).
If, for some reason, you don't want the compression provided by zip or 7z, there are ways to disable that too, so zip or 7z just create a file container kind of like tar does.
In the end, though, I think you should just re-create the archive each time. I suspect that the time saved doing the kind of synchronization you ask for is probably small.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'd like to take a large folder (~100GB) and copy it over to another folder. I'd like it to skip any files that exist (not folders) so if /music/index.html does not exist it would still copy even though the /music directory already exists.
I found this, but my shell is saying -u is not a valid argument.
I don't know how rsync works, so please let me know if that's a better solution.
Thanks.
Always use rsync for copying files, because It Is Great.
To ignore existing files:
rsync --ignore-existing --recursive /src /dst
Do read the manual and search around for many, many great examples. Especially the combination with ssh makes rsync a great tool for slow and unreliable connections on account of its --partial option. Add --verbose to see which files are being copied. Be sure to check out the plethora of options concerning preservation of permissions, users and timestamps, too.
rsync(1) absolutely shines when the source and destination are on two different computers. It is still the better tool to use when the source and destination are on the same computer.
A simple use would look like:
rsync -av /path/to/source /path/to/destination
If you're confident that any files that exist in both locations are identical, then use the --ignore-existing option:
rsync -av --ignore-existing /path/to/source /path/to/destination
Just for completeness, when I use rsync(1) to make a backup on a remote system, the command I most prefer is:
rsync -avz -P /path/to/source hostname:/path/to/destination
The -z asks for compression (I wouldn't bother locally, but over a slower network link it can make a big difference) and the -P asks for --partial and --progress -- which will re-use partial file transfers if it must be restarted, and will show a handy progress bar indicator.