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
I'm writing a simple archiving script in OSX and I'm trying to use tar to create an archive of a directory deep inside my filesystem. I would love to save that tar on another drive. At some point, I'd love to be able to unpack that tar from the second drive and have it drop right into the same parent directory where I originally archived it. If that directory didn't exist, the tar would create that directory path to that particular folder.
So far I can create a tar that recreates the folder path from the exact place I unpacked it on Drive 2, but I can't figure out how to get it to just drop into a path that already exists. Right now what I'm trying is to get this...
tar cvf Drive2/DirectoryToArchive.tar Drive1/Folder1/ParentFolder/DirectoryToArchive
Followed by this...
tar xvf Drive2/DirectoryToArchive.tar
To yield me an unpacked, reinstated DirectoryToArchive in
Drive1/Folder1/ParentFolder/
I want to be able to give this script to people who don't know terminal and have it work for them without having to place the tar in a specific directory. Is that something tar can do?
Let me show an example of compressing and extracting to the original dir and files using tar.
On host c1669-node2:
% tar -zcvf jdk64.gz /usr/jdk64/jdk1.8.0_112/
% pwd
/root
% ls -1 | grep -Ei jdk
jdk64.gz
On host kyan-hdp01:
% scp root#c1669-node2:/root/jdk64.gz /tmp/
% tar -xzvf /tmp/jdk64.gz -C /
% ls -lh /usr/jdk64/ | head -n 5
total 0
drwxr-xr-x. 8 10 143 255 Sep 23 2016 jdk1.8.0_112
So I think if you compress the file with a absolute path then extract it use the -C / to specify dir it would be exactly as the same path as the orinal dir.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
When using the ls -lSh command, the output of the size of the files is very small. For instance:
ls -lSh | grep Xcode.app #my command to terminal while in Applications directory
drwxr-xr-x# 3 root wheel 96B Dec 17 14:59 Xcode.app #output
As you can see, Xcode is only 96B, when in reality is over 6GB on disk. Can somebody please explain the formula being applied here?
I am running iTerm2 on macosx catalina
ls does not report size of whole directory, but only the directory entry itself. If you want aggregate directory size, you should use du or similar utilities that count sizes recursively. The size output from ls is the size of the directory entry, which generally grows if you have more files and subdirectories, but not when you have large single files, and depends a lot on the underlying filesystem.
.app are actually directories, nor regular files. Try du -sh Xcode.app instead.
The -l switch shows the "allocated size" of the item you're listing. In case of a directory, its size amounts to just its entry in the file system, and that is very small. What one normally thinks of as the "size" of a directory is actually taken by the files residing beneath it, and that is reported by the du command.
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 6 years ago.
Improve this question
If the ls command lists the contents of a directory, then some output to ls <directory would seem to indicate that a directory exists.
For example, this is what I get:
> ls ~/.ssh
id_rsa id_rsa.pub known_hosts
But why then, when I type cd ~/.ssh do I get
> cd ~/.ssh
The system cannot find the path specified.
?
Why can I list the contents of this directory but not navigate to it?
I am using Windows 8
This answer is under the assumption that you are using the command prompt to execute these commands.
The reason that you can ls the directory but not cd to it, is because the ls command comes from a library that you downloaded that makes ls work on windows.
In contrast, your cd command is being executed from Windows, not from the library you downloaded.
In short, ls knows how to parse the tilde (~) as home, but windows doesn't know how to parse ~. try it: cd ~. it won't work.
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.