Sponsored Content
Top Forums Shell Programming and Scripting How to copy files/folders and show the files/folders? Post 302983974 by hicksd8 on Wednesday 19th of October 2016 12:34:37 PM
Old 10-19-2016
Referring to vbe's post#2 and suggested command line he gives (which is the way to do it), I would comment as follows.

1. The destination path MUST already exist before the command is run. If necessary create the destination path yourself first.
2. If you are copying within a filesystem then don't use the 'l' switch on the cpio command otherwise it will link the files where possible and won't actually copy them (although of course the files will appear in the new path location because of the links made).
3. Before you run the command execute a 'cd' command to the source location of the files to be copied. If you use a '.' in the find command then everything in that directory will be copied. If you only want a subset then you need to specify that subset within find. Once you have 'cd' to the source location a mirror image of the files you can see with a 'ls' command will be copied to the destination folder. An exact copy of the whole tree, sub-directories and all.
4. If you want to see more information as the files are copied include a 'v' switch in cpio (eg, cpio -puvdm /<dest dir>)

If you're still having trouble making this work do post back your problem. We can sort it.

---------- Post updated at 05:34 PM ---------- Previous update was at 12:45 PM ----------

So, for example:

Code:
 
 # cd /a/b/c/sourcedir
 # find . -print|cpio -puvdm /d/e/f/destinationdir


Last edited by hicksd8; 10-21-2016 at 06:10 AM..
This User Gave Thanks to hicksd8 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

copy all files and folders and cjange or remove ownership

So tried: cp -r -p test1/ user@machine:///srv/www/vhosts/domain.co.uk/httpdocs/backup/ but this didn't work either :( Anyone able to help with this? Many thanks Mr M (3 Replies)
Discussion started by: misterm
3 Replies

2. Shell Programming and Scripting

Need to create a script to show what files in what folders

Hi everyone, I'm stuck with this scenario where our system creates files every night and puts them in several folders according from whom it came from. I have managed to create a script which will list the folders in one column and the files that are in them in another column, now my problem... (6 Replies)
Discussion started by: kumaran21
6 Replies

3. Shell Programming and Scripting

copy some files from users home folders to my folder

i have users home directories in /home all the users have some files starting with character e and i want to copy all these files in a folder in my (root) home using a script i tried the script for i in m5 do cd m5 cp e1* /home/pc/exam cd .. done but get these... (3 Replies)
Discussion started by: pcrana
3 Replies

4. Shell Programming and Scripting

I need script Copy permissions of files and folders from one server to another

Hi.. I have 2 servers with linux suse10. I made a mistake and on one of the servers changed with chmod the permission of root in directory /. In the other servers the permissions are correct Please i need a script, to change the permissions of one server 1, using the same permission of the... (11 Replies)
Discussion started by: ave-phoenix
11 Replies

5. Windows & DOS: Issues & Discussions

Windows mass copy files with same name in differnt folders

I have files existing with same names in the folders with date as display below c:\2010-09-10 <==== folder arr1.jpg arr2.jpg arr3.jpg arr4.jpg c:\2010-09-09 <==== folder arr1.jpg arr2.jpg c:\2010-09-08 <==== folder arr2.jpg arr3.jpg arr4.jpg ... (5 Replies)
Discussion started by: jville
5 Replies

6. UNIX for Dummies Questions & Answers

copy mutilple files to mutiple folders

Hi, I just started to learn shell progamming and just can't get my head around the following problem. I need to do the following: I have a folder which contains 100+ subfolders. Inside these subfolders there is one folder named 'Morph' and several jpg's. I need to copy all the files into... (4 Replies)
Discussion started by: M474746
4 Replies

7. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

8. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

9. Shell Programming and Scripting

Linux Script to compare two folders and copy missing files

Hi, I need help in shell scripting. If someone can help me, that would be great! Problem. I want Linux Script to compare two folders and copy missing files. Description. I have two directories /dir1 /dir2 I need to copy all distinct/new/unique/missing files from /dir1 and that... (1 Reply)
Discussion started by: S.Praveen Kumar
1 Replies

10. HP-UX

Recursive copy of Folders with files

Dear All, I will appreciate any help received. Our system is running on hpux v1 My problem is as follows: We have many customer folders with name fd000100, fd000101 and so on e.g. (Testrun)(testsqa):/>ll /TESTrun/fd000100 total 48 drwxrwx--- 2 fq000100 test 96 Jun 27 2004... (17 Replies)
Discussion started by: mhbd
17 Replies
cpio(1) 						      General Commands Manual							   cpio(1)

NAME
cpio - Copies files to and from archive storage. SYNOPSIS
cpio -o[aBcehvV] [-C value] [-M"string"] [-Odevice] cpio -i[bBcdefmrsStuvz6] [-C value] [-M"string"] [-Idevice] [pattern...] cpio -p[adlmruvV] directory STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: cpio: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
A hyphen (-) is required before the -i, -I, -o, -O, and -p options; all other options follow -i, -o, or -p without leading spaces and with- out a hyphen. [Tru64 UNIX] The following two options are preceded by a hyphen and must be used separately from the other options. [Tru64 UNIX] Speci- fies the input device containing the archive. This argument must be present to import data from a device. [Tru64 UNIX] Specifies the output device to store the archive. This argument must be present to export data to a device. Not all of the following options can be used with each of the -o, -i, and -p options. Resets the access times of copied files to the cur- rent time. (When the l option is also specified, the access times of the linked files are not reset.) [Tru64 UNIX] Swaps both bytes and halfwords. (See also the s and S options.) If there is an odd number of bytes or halfwords in the file being processed, data can be lost. This option can only be used with cpio -i. Performs block input/output, 5120 bytes to a record. This option cannot be used with cpio -p. It is meaningful only with data directed to or from /dev/rmt/*. This option does not work with certain magnetic tape drives. The C and B options are mutually exclusive. If you specify both, the last one on the command line is used. Writes header information in ASCII charac- ter form. Specify this option when POSIX compliance is required and when you are creating or restoring archives for or from another system. [Tru64 UNIX] Performs block input/output using value as the record size. The C and B options are mutually exclusive. If you specify both, the last one on the command line is used. Creates directories as needed. [Tru64 UNIX] Read or write cpio header information in extended cpio header format. Use this option to read or write block special or character special files. Any cpio archives created with the e option of Tru64 UNIX Version 4.0 are not backward compatible with earlier versions of Tru64 UNIX. Copies all files except those matching pattern (cpio -i only). [Tru64 UNIX] Forces cpio to follow symbolic links as if they were normal files or directories. The cpio command does not follow symbolic links, but instead saves the link text in the archive. Links files rather than copying them, whenever possible. Hard links are created rather than symbolic (soft) links. This option can be used only with cpio -p. Retains the previous file modification time. This option cannot be used when copying directories. [Tru64 UNIX] Specifies the End-of-Media message. This option is used to customize the message that appears when it is time to change archive volumes. The -M option is valid only when -I or -O is also specified. Causes cpio to ask whether or not to rename each file before copying it. If you do not want to change the file name, enter the current file name. You can press <Return> only to have cpio skip copying the file. [Tru64 UNIX] Swaps bytes. This option can be used only with cpio -i. If there is an odd number of bytes in the file being processed, data can be lost. [Tru64 UNIX] Swaps halfwords. This option can be used only with cpio -i. If there is an odd number of halfwords in the file being processed, data can be lost. Creates a ta- ble of contents of the input. This option does not copy any files. Copies unconditionally. Otherwise, a file from the archive with the same name as an existing file in the file system is copied only if the archived file is the newer one. Lists file names. If you use this option with the t option, the output looks similar to that of the ls -l command. [Tru64 UNIX] Prevents any extended attributes from being archived with associated files. This option is particularly useful for archiving files that are to be restored with previous versions of tar and cpio. [Tru64 UNIX] Positions the tape after the EOF marker on extraction or listing. The z option lets the user extract or list tapes that have multiple archives on them one after the other without error as a result of the tape not being positioned correctly for the next extraction or listing. [Tru64 UNIX] Processes an old file (one written in UNIX Sixth Edition format). This option can be used only with cpio -i. OPERANDS
A pathname of an existing directory to be used as the target of cpio -p. Expressions making use of a pattern-matching notation similar to that used by the shell for file name pattern matching, and similar to regular expressions. The following metacharacters are defined: Matches any string, including the empty string. Matches any single character. Matches any one of the enclosed characters. A pair of char- acters separated by `-' matches any symbol between the pair (inclusive), as defined by the system default collating sequence. In pattern, the special characters ?, *, and [ also match the / character. Multiple cases of pattern can be specified and if no pattern is specified, the default for pattern is * (that is, select all files). DESCRIPTION
The cpio command copies files between archive storage and the file system. It is used to save and restore data from traditional format cpio archives. There are three versions of the cpio command: cpio -o (copy out) This command reads file pathnames from standard input and copies these files to standard output along with pathnames and status informa- tion. Output is padded to a 512-byte boundary. cpio -i (copy in) This command reads from standard input an archive file created by the cpio -o command and copies from it the files with names that match pattern. These files are copied into the current directory tree. The file permissions are the same as the permissions associated with the files copied out using cpio -o but if umask is used it sets the permissions as per umask. The owner and group of the files are those of the current user unless the user is superuser, in which case cpio retains the owner and group of the files of the previous cpio -o. You can list more than one pattern using the file name notation described. The default pattern is *, selecting all files in the archive. In an expression such as [a-z], the hyphen means "through" according to the current collating sequence. The collating sequence is deter- mined by the LC_COLLATE environment variable. cpio -p (directory copy) This command reads file pathnames from standard input and copies these files into the named directory. The specified directory must already exist. If these pathnames include directory names and if these directories do not already exist, you must use the -d option to cause the directories to be created. [Tru64 UNIX] Special files are not supported. Pathnames cannot exceed 128 bytes. Avoid giving cpio pathnames made up of many uniquely linked files because cpio might not have enough memory to keep track of them and could lose linking information. NOTES
The cpio command is marked as LEGACY in XCU Issue 5. [Tru64 UNIX] Archives created with extended attributes cannot be read by Version 2.0 of the cpio command. The following describes the results of restoring archived files and directories when you use Version 2.0 of the cpio command: [Tru64 UNIX] You cannot restore an ar- chive directory with extended attributes. The extended attributes are restored as a regular file that cannot be overwritten; the original directory cannot be recreated. In addition, the cpio command restores the archived files containing extended attributes as regular files. When the cpio command restores the original file with the extended attributes, the command fails with errno:20. [Tru64 UNIX] You cannot archive files with extended attributes. [Tru64 UNIX] Archives created with the new pax utility and having cpio format, can be restored using only the new pax or cpio commands even if none of the archived files have extended attributes. To achieve backward compatibility of archived files, use the following suggestions: Archive only files that do not have extended attributes. Use the old cpio command at /usr/opt/obsolete/usr/bin/cpio. CAUTIONS
[Tru64 UNIX] When redirecting the output from cpio to a special file (device), redirect it to the raw device and not the block device. Because writing to a block device is done asynchronously, there is no way to know if the end of the device has been reached. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To copy files to magnetic tape, enter: cpio -ov < file-list -O/dev/rmt12 This command copies the files with pathnames that are listed in the file specification in a compact form to the magnetic tape (/dev/rmt12). The -v option causes cpio to display the name of each file as it is copied. This command is useful for making backup copies of files. To copy files in the current directory whose names end with onto magnetic tape, enter: ls *.c | cpio -ov -O/dev/rmt12 To copy the current directory and all subdirectories onto magnetic tape, enter: find . -print | cpio -ov -O/dev/rmt12 This command saves the directory tree that starts with the current directory (.) and includes all of its subdirectories and files. Another way to do the same thing is by entering the following command: find . -cpio /dev/rmt12 -print The -print option displays the name of each file as it is copied. To list the files that have been saved onto a magnetic tape with cpio, enter: cpio -itv -I/dev/rmt12 This command displays the table of contents of the data previously saved onto /dev/rmt12 in cpio format. To list only the file pathnames, use only the -it options. To copy the files previously saved with cpio from a magnetic tape, enter: cpio -idmv -I/dev/rmt12 This command copies the files previously saved onto /dev/rmt12 by cpio back into the file system (specified by the -i option). The -d option lets cpio create the appropriate directories if a directory tree was saved. The -m option maintains the last modification time that was in effect when the files were saved. The -v option causes cpio to display the name of each file as it is copied. To copy selected files from magnetic tape, enter: cpio -i -I/dev/rmt12 "*.c" "*.o" This command copies the files that end with or from magnetic tape. The patterns *.c and *.o must be enclosed in double quotation marks (" ") to prevent the shell from treating the * (asterisk) as a pattern-matching character. In this special case, cpio itself decodes the pattern-matching characters. To rename files as they are copied from magnetic tape, enter: cpio -ir -I/dev/rmt12 The -r option causes cpio to ask you whether or not to rename each file before copying it from magnetic tape. For example, the fol- lowing message asks you whether you want to give the file saved as prog.c a new name as it is being copied: Rename <prog.c> To rename the file, type the new name and press <Return>. To keep the same name, you must enter the old name at the prompt. To avoid copying the file at all, press <Return> alone. To copy a directory and all of its subdirectories, enter: mkdir /u/jim/newdir find . -print | cpio -pdl /u/jim/newdir This command duplicates the current directory tree, including the current directory and all of its subdirectories and files. The duplicate is placed in the new /u/jim/newdir directory. The -l option causes cpio to link files instead of copying them, when pos- sible. ENVIRONMENT VARIABLES
The following environment variables affect the execution of cpio: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files) and the behavior of character classes within bracketed file name patterns. Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the format of date and time strings output when listing the contents of an archive with the -v option. Deter- mines the location of message catalogues for the processing of LC_MESSAGES. Determines the time zone used with date and time strings. SEE ALSO
Commands: ar(1), find(1), ls(1), ksh(1), pax(1), Bourne shell sh(1b), POSIX shell sh(1p), tar(1) Files: tar(4) Standards: standards(5) cpio(1)
All times are GMT -4. The time now is 05:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy