1
vote
2answers
55 views

How use minimum number of commands to copy all .txt files from all subdirectories to one directory?

I have more than 90 subdirectories and inside each one, there will be a number of .txt files. What I need to do is to copy all those txt files out to one single directory. How can I do that?
3
votes
3answers
453 views

Copy a file and overwrite the existing file

I have two images (image1.png and image2.png) in the same folder on my server, I want to run a command that overwrites image2.png to image1.png. I prefer to overwrite the image instead of deleting it ...
2
votes
1answer
57 views

Copy file from USB drive to a desktop loaded via a LiveCD

I have booted my computer using a LiveCD and want to copy a file from a USB drive to the LiveCD loaded desktop. I want to copy a file from the USB drive to the desktop environment in memory, which ...
6
votes
2answers
694 views

Copying one file to multiple directories

I have a file that I want to copy to another 60 directories. The best way I can think of doing this is by making a bash script that has instructions to every folder like this: cp script.sh ...
1
vote
2answers
998 views

cp and mv if the file named already exists

What happens when you give the following commands if the file named done already exists? $ cp to_do done $ mv to_do done
4
votes
1answer
110 views

When do I use cp --attributes-only

Doing some study on basic Unix commands and trying to get an example when I want to use the following command line option --attributes-only for command cp here is from cp man page --attributes-only ...
1
vote
2answers
5k views

Copy only regular files from one directory to another

I'd like to copy a content of directory 1 to directory 2. However, I'd like to only copy files (and not directories) from my directory 1. How can I do that ? cp dir1/* dir2/* then I still have the ...
2
votes
1answer
107 views

Why does copying from a script screw with my files?

I am at a loss here, trying to find out the reason why a shell script that is basically copying a couple of files and directories from one place to another will result in the content of two of the ...
0
votes
1answer
290 views

Simple bash script taking too long to execute

I wrote the following function in my .bashrc for use instead of rm * : function re() { cp . -R /home/glset/ritwik/trash/ rm * } It works .. but it is very slow. Even for small files it takes too ...
2
votes
2answers
639 views

Can one copy a relpath in one command?

I find myself doing this often enough that I wonder if there's a standard Unix way to do it: % mkdir -p /TARGETDIR/relative/path/to % cp ./relative/path/to/somefile /TARGETDIR/relative/path/to In ...
2
votes
3answers
228 views

How to cp or rm files based on ownership / permission

After a problem with spam, I stopped postfix postfix stop and checked through the mailq manually to find hundreds of thousands of unsent spam. The spam was sent from one of the sites hosted ...
6
votes
2answers
4k views

tar files from another directory without copying them

This should be very simple for experts in here. I have a Linux account with user disk quota of only 6GB. There is some data-folder in /opt with about 3GB of data with when compressed comes up 1GB. ...
9
votes
6answers
1k views

How to copy every 4th file in a folder

I have a lot of files in a folder, named like 00802_Bla_Aquarium_XXXXX.jpg. Now I need to copy every 4th file to a subfolder, saying in selected/. 00802_Bla_Aquarium_00020.jpg <= this one ...
12
votes
3answers
3k views

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is ...
1
vote
1answer
98 views

Will files created under source directory after running `cp` be copied?

Suppose I use cp to copy a directory to another place. If the process takes long, and I create a new file under the source directory, will it be copied, or does it depend on something?
7
votes
5answers
7k views

How to copy directories with preserving hardlinks?

How to move directories that have files in common from one to another partition ? Let's assume we have partition mounted on /mnt/X with directories sharing files with hardlinks. How to move such ...
6
votes
2answers
1k views

How to replace a symbolic link with a copy of a file it links to?

Having a (single, no batch filesystem processing needed) symlink, what a command line to use to replace it with a copy of the file it links to?
2
votes
2answers
3k views

How can I selectively copy files from one directory to another directory?

On Linux, how do I selectively copy most – but not all – files from a directory (dir1) to another directory (dir2)? I do not want to copy *.c and *.txt files to dir2. The cp man page ...
3
votes
3answers
342 views

Delete files in a directory which are also in another directory

I copied a directory using this: cp -r dir/ ../../ without thinking and realized that it copied the contents of dir instead of actually dir to the above directory. Now I have a mess of files I need ...