mv equivalent rsync command [closed] - linux

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 9 years ago.
Improve this question
i'm trying to move folders to another folders using command line, with overwrite if already exists, but i got error "Is a directory" when using mv..
example:
mv src/test/ dest/
there are many files and folders on src/test/, there are also some files and some folders on dest/
and i want files and folders on dest/ replaced with files and folder from src/test/ if exists, example:
src/test/bla/boo replaces dest/bla/boo
src/test/bla/bla/boo replaces dest/bla/bla/boo
also, everytime one file transfer completed, that one file deleted from src/test/
and overall transfer progress bar would be fine..
what rsync flag should i use to make this happend?

The following command line should achieve what you want:
$ rsync -a --progress --remove-source-files src/test/ dest

Related

Linux -How to delete all files in a directory without using find [closed]

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 9 years ago.
Improve this question
I am trying to delete all files in my directory "XYZ" without using find command in bash on Linux.
Use the following command:
rm -f XYZ/*
If you want to delete also subdirectories, use:
rm -fr XYZ/*
If you also want to delete the directory, use
rm -fr XYZ
If you want to delete all files in a directory, go into the directory and execute: rm -f *
Why would find even enter into it? use rm -r XYZ to recursively remove the directory XYZ.

How to use zip command in unix? [closed]

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 9 years ago.
Improve this question
Suppose i have a zip file Old.zip , inside it are fileA and fileB. then i unzip them using: unzip Old.zip -d Old, then i will have a directory named Old, with fileA and fileB inside.
Now the Old.zip is gone, and i want to zip it again, but if i use: zip -r New.zip Old, the New.zip is different from Old.zip: inside it are not two files, but one directory!
Before: After: I want:
Old.zip--+ New.zip--+ New.zip--+
+--fileA +--Old--+ +--fileA
+--fileB +--fileA +--fileB
+--fileB
Any suggestions? How should i use zip command correctly to keep the structure? I will NOT go into Old folder and use zip New.zip fileA fileB and move it to the parent folder since i will write it in shell script.
Try passing the the -j (junk paths) option to zip:
$ zip -rj New.zip Old
That way, the files will be stored without their relative paths.

copy file now paste later [closed]

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
in linux to copy and paste a file we have cp command
cp [OPTION]... SOURCE... DIRECTORY
But what if I don't want to paste the file to any directory right now and I just want to copy it for future use? For example in GUI
right click to file>click on copy
#Do something else change directory/use internet/have coffee
Right click at some other directory/place>click on 'Paste' >file will be pasted at DIRECTORY
same procedure is applied to cut/move the file. Is there any command for such copy/cut in linux??
Assign the name of the file to a variable.
$ file_to_copy=`pwd`/important_notes.txt
cd elsewhere, use internet, have coffee. Ok, we want that file in our current directory.
$ cp $file_to_copy .
Use mv to move instead of copy.
(Please don't call this copy-pasting. It's just copying. Note that the initial $ represents the prompt, don't type that.)
The method above only copies the name of the file, not the file itself, which is fine, unless it gets modified or deleted in the meantime.
You might be better off copying the file to /tmp/
cp theFileIWant.txt /tmp/
cd wherever
mv /tmp/theFileIWant.txt ./

Untaring files into a new folder [closed]

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've got a bunch of tar and tar.gz files that I would like to unzip. Inside these files, most of them have the same folder structure zipped up inside (although with different files).
If I were to do this manually by right-clicking and selecting "Extract Here," it'd would create a new folder for me with the original file name and dump the files there.
However, when I do this via the command line, the behavior isn't always the same. Sometimes it'd create the desired new folder and other times it wouldn't, causing it to overwrite the extraction of others.
Using the -C option seems to require the folder already existing. How can I mimic the behavior of the manual "Extract Here" in the command line?
Thanks.
You could create a bash function like this;
function untarhere() {
(mkdir -P $1; cd $1; tar xzf $2)
}
and then call it like
untarhere /your/destination/directory /your/tar/file.tar

How do I delete old[er] files from my centos /tmp directory EXCEPT certain files still in use? [closed]

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 need to figure out how to automatically remove most files from my /tmp directory on a centos server. The directory keeps filling up with junk that needs to go, however there are files in there that need to stay, so:
How can I delete files in /tmp that are over 24 or so hours old AND keep files with certain name patterns?
I believe Centos has tmpwatch.
You can use find to accomplish this.
find -mtime 1 -regex [your_pattern_here] -exec rm -f {} \;
mtime looks for any files older than N days old, and the [your_pattern_here] in this case would be the pattern of files you want to keep. It'd be best to do this without the exec portion at the end first to make sure it's finding the files you're expecting (or more importantly, not finding files you want to keep)

Resources