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 ./
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I use Cygwin, and I write commands. On my Desktop I have two folders, named folder1 and folder2. In folder1 there is a text file. I want to move the text file to folder2. But when I use the mv command it doesn't work. I get an error message "no such file or directory".
My question is: how can I move file.txt from folder1 to folder2?
My code is:
/cygdrive/c/Users/Maichel/Desktop/folder1
$ mv file.txt folder2/.
This also doesn't work:
/cygdrive/c/Users/Maichel/Desktop/folder1
$ mv Desktop/file.txt Desktop/folder2/.
I have one question more: How can I open Dreamweaver in Cygwin? If I use notepad file.txt then the file is opened in notepad. How do I do this with Dreamweaver?
You need to reference your paths properly. If your directory hierarchy looks like this:
Desktop/
- folder1/
- folder2/
Then from inside folder1, you need to navigate up one directory with .. to get to Desktop, then go back down into folder2:
/cygdrive/c/Users/Maichel/Desktop/folder1
$ mv file.txt ../folder2/
You can also use the absolute path:
/cygdrive/c/Users/Maichel/Desktop/folder1
$ mv file.txt /cygdrive/c/Users/Maichel/Desktop/folder2/
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 want to remove all files that exist in folder new-files from another folder in linux using bash commands.
I need this for two things:
I got some setup scripts which copy some pre-configured config files over. I would like to have the option to remove those files again
Sometimes it happens that archives get unpacked into the root of your downloads directory and not into a subdir because the person packing the file put everything to the archives root
What's the best way to do that?
Edit, to clarify:
I got a folder with files called new-files.
Now I execute cp -r new-files/* other-directory/.
Lets say other-directory is not the directory I wanted to copy them to but it already contains other files so I can't just do rm other-directory/*.
I need to delete all folders which I accidently copied. How do I do that?
You could use the following command:
cd new-files ; find . -exec rm -rf path/to/other-directory/{} \;
It will list all the files that where copied from the new-files directory (new-files directory will not be taken in consideration). For each file, it will remove the copied version in other-directory.
But you've to be careful, if a file in new-files erase a file in other-directory, you won't be able to restore the old file using this method. You should consider to use a versioning system (like Git for example).
From your:
Edit, to clarify:
I got a folder with files called new-files.
Now I execute cp -r new-files/* other-directory/.
Lets say other-directory is not the directory I wanted to copy them to but it already contains other files so I can't just do rm
other-directory/*.
I need to delete all folders which I accidently copied. How do I do that?
You can loop through the original dir new-files/ and delete files with same name in the other-directory/:
for file in /new-files/*
do
rm /other-directory/"$file"
done
wee script to do what you want:
pushd `pwd`
cd /path/to/new-files
x=`find . -type f`
popd
echo $x | xargs rm
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
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 am working on linux scripts , Assume that the directory is consisting of these following scripts .
ls *.sh
test.sh
MyScripts.sh
My question is , before making any modifications to test.sh script , i want to keep a backup copy of it , so that if anything messes up , i will be not screwed up .
please tell me how can i keep a copy of test.sh in the same directory ?? before making any modifications to the actual file test.sh .
Thank you very much .
Consider using revision control, such as git or Subversion.
You can make a copy before your work too:
cp test.sh test.sh.orig
The usual approach is to
cp test.sh test.sh~
(or test.sh.bck or whatever naming convention). In fact, any decent editor should have an option to do this automatically for you. Vim does it by default (saves a backup name filename~ on modification)
May I heartily suggest a version control solution for this purpose instead?
Good 'starter' options include:
bazaar
mercurial
I personally vouch for git.
I took care to name (D)VCS methods that have ample interoperability options so as to prevent data lockin.
cp test.sh test.sh.`date +"%m_%d_%Y"`
Will make a timestamped backup named test.sh.10_10_2011
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