help with simple unix file copy and output in directories
Hi, I am fairly new to unix, and am trying to copy all files with the name "*.cons" within a directory (and all of the many directories within it) to a new directory called "output". There are multiple nested directories, and I would like to just pull out the files with ".cons" and not the other stuff. Do I use the "find ./ -name" option? Can anyone help me?
Lets start with the starting directory: you probably want to start in the current working directory, which is always named "." If this is the case you shouldn't obscure this pathname with additional slashes - in the best case this alters the path to something else, rendering it uninterpretable for the system in the worst case.
Btw., it is a good idea to "build gradually" towards the correct command. This way you easily find out where you have gone wrong. We start by simply printing what we find and use "more" to pagewise read output (read the mapage of "more" to see what it does):
Ok, this seems to work. Now we want only the files, leaving out the directories:
The order of the clauses for "find" doesn't matter (not in your case), but it is a good idea to keep some sort of order to be able to read it easily. I made a habit of always put the "output clause" ("-print" in this case) at the end and the limiting clauses first. Whatever you do, be consistent with yourself.
As next step we limit the files (we already deal with files only, because of the "-type" clause) to the ones which match out name criteria. The clause for that is "-name" (not "-iname", as you wrote, probably a typo):
Just an observation: in DOS/Windows all files have a filename and an extension. These parts of the filename are divided by a dot. In UNIX there is no such thing as an extension and the dot (if there is one) is a simple part of the name. This makes not a big difference here, but is good to know, because sometimes people implicitly assume the naming convention of DOS/Windows to be in effect, which doesn't have to be the case.
We seem to have gotten all the files we want and left out all the files we don't want (yes? - if not, we will have to start over) and get to the hard part: moving the files. Again we first want to see what we might do to the files and only then do it in fact. There lets "mask" the command with an "echo" command to just print it instead of executing:
The output should look like this:
If the commands look like the ones you really want to execute remove the "echo" in the "-exec" part and execute the "find"-command once more to actually do it. You should be done. If you are not it will be things outside the scope of "find": does the directory "/consensus" already exist? Are your rights sufficient to write there? Is there enough space in the filesystem to move the files there? Are you allowed to access the files you want to move or only their directory information? Etc., etc.
If you want to retain the directory tree structure in the target directory it is easier with "find" combined with "cpio -p". See "man find" and "man cpio".
I was trying to copy the files inside the path /home/user/check/Q1/dir/folder1/expected/n/a1.out1 and a1.out2 and a1.out3 to /home/user/check/Q2/dir/folder1/expected/n/
if n directory is not present at Q2/dir/folder1/expected/ then directory should be created first. And, script follow the... (5 Replies)
I have directory path in which there are several sub directories. In all these sub dir there will be one env.cnf file. I want to copy this env.cnf file from
each sub dir's and place them in destination path by creating same filename as sub dir_env.cnf.
After copying env.cnf files from source... (4 Replies)
Hi All Genious,
I want to copy a file name XYZ .In a directory /HOME/dir/IXOS1/dir1
which contain multiple directories named not in pattern want to copy the XYZ in all of the directories available on path /HOME/dir/IXOS1/dir1 .
Thanks in advance . (2 Replies)
The below code works to tail client.log file. but I want to copy the output into an external file /home/tail.txt
Can anyone please help.
#!/opt/bin/perl -w
open my $pipe, "-|", "/usr/bin/tail", "/var/log/client.log" or die "could not start tail on /var/log/client.log : $!";
print while... (2 Replies)
Hello,
Imagine I am on a Unix system, connected to server via telnet. I do 'ls' and I see the file listed - OK. Filename=ems.log.
Then I need to copy such file from this server to my Windows network share \\windowsserver\myshare\smith.
How can I do that? (2 Replies)
Hello-
I need to copy a file into multiple directories, and each directory's sub-directories (of which there are 5)
Currently, the parent directory is set up like this:
dir1
sub-dir1
sub-dir2
sub-dir3
sub-dir4
sub-dir5
dir2
sub-dir1
sub-dir2
sub-dir3
... (1 Reply)
Please help - I need to copy a single file to multiple directories.
Dir structure:
Parent_Directoy
Filename1
Child_Directory1
Child_Directory2
Child_Directory3
Child_Directory4
....
So I need to copy Filename1 to all of the... (2 Replies)
Hello,
I have a nohup.out file that, when executed, outputs a spreadsheet file
with four-to-seven columns of number. I want to copy this output (in its entirety), so that I could then paste it on excel@ , or Notepad@.
Please help, thanks. (3 Replies)
I have software on Z drive " I map it " , its about 50 MB , I want to copy the whole directory in to unix server , under some folder ...
What are the steps how Ican perform this ?
I have UNIX user name and password and rights to create files and folders..
Remember I want to copy all the folder... (3 Replies)