create file in HP


 
Thread Tools Search this Thread
Operating Systems HP-UX create file in HP
# 1  
Old 10-06-2010
create file in HP

Thanks

Last edited by rocky1954; 11-18-2010 at 01:35 PM..
# 2  
Old 10-06-2010
Code:
(
cd dir1
find * -type d | cpio ( create_archive_options ) 
)| (
 cd dir2
 cpio ( unpack_archive_options )
 )

OR check the cpio pass option on the man page. Usually I feed cpio flat files and ask it to make dirs as necessary, but I know it can move empty dirs. "cp -rp" moves everything. In fact, I think scp, scp2, rcp, cp, *cp -rp all use cpio under the covers. The -p and cpio properly optioned preserves group, user, permissions, dates. I do not know the cpio options offhand because I immediately put them in scripts and forget them, and do not have UNIX here. Wait, I have cygwin; the first script takes in file names and makes a bzip2 compressed archive, and the second does somewhat the reverse:

Code:
$ pg ../*/mysrc_sol/b*cpio|cat
::::::::::::::
../DavidGPickett/mysrc_sol/bcpio
::::::::::::::
#!/usr/bin/ksh

cpio -oaH crc $1 |bzip2 $2

::::::::::::::
../DavidGPickett/mysrc_sol/buncpio
::::::::::::::
#!/usr/bin/ksh

bunzip2 <$2 |cpio -idmH crc $1
$


Last edited by DGPickett; 10-07-2010 at 05:33 PM..
# 3  
Old 10-07-2010
Hi,

As posted in another thread, check this link: https://www.unix.com/302460613-post23.html

Regards!
# 4  
Old 10-07-2010
The ususal method is to use for example "find . -xdev -type d -print" piped to for example "cpio -pdmv /target_dir" . This does not require an intermediate archive (it writes directly to the target directory) and is just about the fastest way to copy a directory tree complete with permissions.
There are examples in both "man cpio" and "man find" . I haven't posted a formal example because there is some variation and we don't know what Operating System you have.




Be very cautious of the DGPickett post. You MUST use relative pathnames for this sort of operation.
# 5  
Old 10-07-2010
Hi Felipe and all




Thanks

Last edited by rocky1954; 11-18-2010 at 01:35 PM..
# 6  
Old 10-07-2010
The script in filipe.vinturin post does not contain any of the design or coding errors which we see in your post.

I don't endorse your design based on the output from "find" piped to "ls -ld" because you lose the exact directory name. It becomes very awkward to deal with directory names containing space characters from that point on.

Using filipe.vinturin construct with "find" piped to "while read" is much better.

I was tempted to debug your script but I have just noticed that $destination is a directory under $source which makes it just too awkward because you generate an infinite loop by picking up "/tmp/dest" in the initial find.

There are also multiple design issues in the script which means that it does not do what you expect at all ... and if run after getting the syntax errors out could harm your system.
You certainly don't want to issue "chmod -R" in this circumstance - just use "chmod" for individual directories.


It is still much easier with "find" piped to "cpio" but that is also a non-starter if destination directory is under source directory.
# 7  
Old 10-07-2010
Quote:
Originally Posted by methyl
The ususal method is to use for example "find . -xdev -type d -print" piped to for example "cpio -pdmv /target_dir" . This does not require an intermediate archive (it writes directly to the target directory) and is just about the fastest way to copy a directory tree complete with permissions.
There are examples in both "man cpio" and "man find" . I haven't posted a formal example because there is some variation and we don't know what Operating System you have.




Be very cautious of the DGPickett post. You MUST use relative pathnames for this sort of operation.
Yes, sharp knives can cut the cook, too. It is very common to move subtrees around relatively pathed in archives, like for instance every bit of open source app source. You can make a file from the first cpio and do a cpio table of contents to see if you like the archive.

You are afraid you will hit a mount (-xdev)?

I mentioned the cpio pass option to do it in one step.

I use the 2 cpio on a pipe because it does not slow things down or take any more space than -p pass, but you can pipe it off-host using ssh2/ssh/rsh/remst/rexec and not leave any temp file clutter around, and compress it, and put the intermediate product in a file to reuse it. So, cpio pass mode does not do much of substance but expand the cpio man page. But I was not on that committee! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a text file and a pdf file from Linux command results.

Hello. The task : Using multiple commands like : gdisk -l $SOME_DISK >> $SOME_FILEI generate some text file. For readiness I must insert page break. When the program is finished I want to convert the final text file to a pdf file. When finished, I got two files : One text file and One pdf... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Splitting a text file into smaller files with awk, how to create a different name for each new file

Hello, I have some large text files that look like, putrescine Mrv1583 01041713302D 6 5 0 0 0 0 999 V2000 2.0928 -0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 5.6650 0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 3.5217 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

3. Shell Programming and Scripting

How to compare 2 files and create a result file with unmatched lines from first file.?

HI, I have 2 text files. file1 and file2. file1.txt (There are no duplicates in this file) 1234 3232 4343 3435 6564 6767 1213 file2.txt 1234,wq,wewe,qwqw 1234,as,dfdf,dfdf 4343,asas,sdds,dsds 6767,asas,fdfd,fdffd I need to search each number in file1.txt in file2.txt's 1st... (6 Replies)
Discussion started by: Little
6 Replies

4. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

5. Shell Programming and Scripting

How to create a log file that simply shows the name of a file and what directory it was moved to.

Newbie...Thank you for your help. I am creating my first script that simply generates subdirectories to organize video, music, and text files within those subdirectories from my current working directory. PROBLEM: I am trying to write a log file that contains, for each file, the original file... (0 Replies)
Discussion started by: BartleDoo
0 Replies

6. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

7. Shell Programming and Scripting

Newbie.. Find if a file exists and open, if not create the desired file..

Hey all, I'm brand new to script writing, I'm wanting to make a script that will ask for a file and then retrieve that file if it exists, and if it doesn't exist, create the file with the desired name, and I'm completely stuck.. so far.. #! bin/bash echo "Enter desired file" read "$file" if ... (5 Replies)
Discussion started by: Byrang
5 Replies

8. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

9. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies
Login or Register to Ask a Question