PDA

View Full Version : copy under command line



jun
8th February 2007, 01:18 AM
Hi there,
If I would like all txt-type files(*.txt) under a specific partition to be copied into a specific directory(e.g. mnt/a/txt),how could it be done?
It's very simple under Windows series desktop.
But if I am under Unix/linux COMMAND LINE(without x-desktop)?

srs
8th February 2007, 01:29 AM
The *nix command to use is cp. In your case

cp *.txt /mnt/a/txt
Check out the manual. For a simple intro, see http://www.linuxcommand.org/learning_the_shell.php#contents

Best wishes, SRS

Edit: by manual I mean 'man cp' or 'info cp'.

ljos
8th February 2007, 02:39 AM
The previous post will work if all the *.txt files are in the current dir. If you want to copy all *.txt files from say /mnt/b whether they are in /mnt/b/dir1/ or /mnt/b/dir2, etc., you could use the following command:

find /mnt/b/ -name "*.txt" -exec cp {} /mnt/a/txt/ \;

jun
8th February 2007, 05:01 AM
The previous post will work if all the *.txt files are in the current dir. If you want to copy all *.txt files from say /mnt/b whether they are in /mnt/b/dir1/ or /mnt/b/dir2, etc., you could use the following command:

find /mnt/b/ -name "*.txt" -exec cp {} /mnt/a/txt/ \;
hey
is this way workable for command "mv"?

ljos
9th February 2007, 12:53 AM
yes. you could replace the cp command with mv. the find command -exec option will work with other commands. see "man find"

for example to do a long listing of any *.txt files that are found:
find /mnt/b/ -name "*.txt" -exec ls -l {} \;