Sponsored Content
Top Forums UNIX for Advanced & Expert Users moving multiple files --recursively using BSD Post 82260 by moxxx68 on Tuesday 30th of August 2005 08:38:44 AM
Old 08-30-2005
Tools moving multiple files --recursively using BSD

i am using a FreeBSD remote account and I have directory that holds a number of
other directories most of which posses *.tgz *.tar.bz2 *.gz files... on a linux system
i would use a find format such as this to locate and mv *.tgz and *.tar.bz2 files
find ./dir -type f -iname "*.t[argz]*[bz2]" -print | xargs mv --target-directory=dir

on bsd this doesn't work since the mv options are slightly differenr than gnu linux..

i used "find ./dir -depth -print | cpio -ov > tree.cpio" and mv the file to a said dir and
extracted the filesystem but i could not find a way to extract just the files using find,
xargs or cpio on the BSD system... what I had to do was ftp the file to my linux system
do all operations and scp the whole directory of extracted files back to the account..
how would i go about extracting just the files using find and xargs or cpio on BSD
without having to go through the rigmarole of ftping back forth between my linux
system and the remote account...
thanx moxxx68 Smilie


excuse the grievance: i have a small typo that would make difference to anyone looking at
my post;;
find ./dir -type f -iname "*.t[arg]*[bz]2" -depth -print0 | cpio --null -pvd ./target-dir
without the print0 expression you might get a slightly different result.. unfortunately on some
bsd systems i am pretty sure that it doesn't exist ... i could be wrong though.. Smilie

Last edited by moxxx68; 09-12-2005 at 09:16 AM.. Reason: typo ...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving and renaming multiple files

Greetings, I know i can use the mv command to move and rename one file. How can I do this with multiple files? example pic01.bmp to pic0001.bmp how can i perform this function on an entire directory of sequential files and keep them in sequence? Hints, suggestions are most welcome:) ... (1 Reply)
Discussion started by: rocinante
1 Replies

2. Shell Programming and Scripting

Moving multiple files and renaming them on the fly

Hi All, Being new to scripting I am facing a new situation. We have an application that generates a file lets say dumpfile for each user under the users home directory when they execute the application. This is quite a huge file and imagine having that for over 40 users on a daily basis. The... (1 Reply)
Discussion started by: daemongk
1 Replies

3. Shell Programming and Scripting

using mv command for moving multiple files in a folder

Hi, I have a requirement where I need to move Bunch of folders containing multiple files to another archive location. i want to use mv command .I am thinking when we use mv command to move directory does it create directory 1st and then move all the files ? e.g source... (4 Replies)
Discussion started by: rkmbcbs
4 Replies

4. UNIX for Dummies Questions & Answers

Need help in moving files recursively

Hi, I have d1,d2,d3 directories / /home/abc/d1 /home/abc/d2 /home/abc/d3 d1,d2 and d3 also have subdirctories. d1-->d11-->d12 d2-->d22-->d23 d3-->d33-->d34 All these directories have files like date_filename.txt so I want to find the files recusively for a particular date from... (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

5. UNIX for Dummies Questions & Answers

Zip multiple files recursively via UNIX

Hello, After searching, I didn't find any answer to execute my task. Her what I want to achieve on my MAC : Create a ZIP file (not tar.gz or other) from a file I want the ZIP created to have the name of the original file I want to do this on multiple files (314 exactly) So at the end the... (3 Replies)
Discussion started by: anou
3 Replies

6. UNIX for Advanced & Expert Users

Moving multiple files based on the pattern

I want to search for a particular file name patterns and move them to a specific folder, is it possible to do it with awk or sed? (1 Reply)
Discussion started by: rudoraj
1 Replies

7. Shell Programming and Scripting

[SOLVED] moving multiple files? mv

HI I have a list of files that are incorrectely names and I need to move them to new name .. I tried few things that has not worked so far can you help ? I need to rename all thes eifle ( tere are over 100 ) xldn0357bap.orig.new xldn0389bap.orig.new xldn0439bap.orig.new... (12 Replies)
Discussion started by: mnassiri
12 Replies

8. Shell Programming and Scripting

Moving and renaming multiple files in a directory

Hi. I am trying to automate the movement and renaming of a number of files in a directory. I am using the 'mv' command as I do not have access to 'rename'. I have the following scripted FILES=$(ls /transfer/move/sys/mail/20130123/) if ; then for i in ${FILES} ; do mv... (4 Replies)
Discussion started by: jimbojames
4 Replies

9. UNIX for Dummies Questions & Answers

Moving multiple datestamped files (Linux)

Hello all, I'm writing a script that will allow me to move files into a sub-directory for archiving. These files, specifically, are output files that result at the end of a process. The issue I'm having is that while moving files from one place to another is relatively an easy task, grabbing... (2 Replies)
Discussion started by: galileo1
2 Replies

10. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies
CPIO(1) 						    BSD General Commands Manual 						   CPIO(1)

NAME
cpio -- copy files to and from archives SYNOPSIS
cpio {-i} [options] [pattern ...] [< archive] cpio {-o} [options] < name-list [> archive] cpio {-p} [options] dest-dir < name-list DESCRIPTION
cpio copies files between archives and directories. This implementation can extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images and can create tar, pax, cpio, ar, and shar archives. The first option to cpio is a mode indicator from the following list: -i Input. Read an archive from standard input (unless overridden) and extract the contents to disk or (if the -t option is specified) list the contents to standard output. If one or more file patterns are specified, only files matching one of the patterns will be extracted. -o Output. Read a list of filenames from standard input and produce a new archive on standard output (unless overridden) containing the specified items. -p Pass-through. Read a list of filenames from standard input and copy the files to the specified directory. OPTIONS
Unless specifically stated otherwise, options are applicable in all operating modes. -0, --null Read filenames separated by NUL characters instead of newlines. This is necessary if any of the filenames being read might contain newlines. -A (o mode only) Append to the specified archive. (Not yet implemented.) -a (o and p modes) Reset access times on files after they are read. -B (o mode only) Block output to records of 5120 bytes. -C size (o mode only) Block output to records of size bytes. -c (o mode only) Use the old POSIX portable character format. Equivalent to --format odc. -d, --make-directories (i and p modes) Create directories as necessary. -E file (i mode only) Read list of file name patterns from file to list and extract. -F file, --file file Read archive from or write archive to file. -f pattern (i mode only) Ignore files that match pattern. -H format, --format format (o mode only) Produce the output archive in the specified format. Supported formats include: cpio Synonym for odc. newc The SVR4 portable cpio format. odc The old POSIX.1 portable octet-oriented cpio format. pax The POSIX.1 pax format, an extension of the ustar format. ustar The POSIX.1 tar format. The default format is odc. See libarchive-formats(5) for more complete information about the formats currently supported by the underlying libarchive(3) library. -h, --help Print usage information. -I file Read archive from file. -i, --extract Input mode. See above for description. --insecure (i and p mode only) Disable security checks during extraction or copying. This allows extraction via symbolic links and path names containing '..' in the name. -J, --xz (o mode only) Compress the file with xz-compatible compression before writing it. In input mode, this option is ignored; xz compres- sion is recognized automatically on input. -j Synonym for -y. -L (o and p modes) All symbolic links will be followed. Normally, symbolic links are archived and copied as symbolic links. With this option, the target of the link will be archived or copied instead. -l, --link (p mode only) Create links from the target directory to the original files, instead of copying. --lzma (o mode only) Compress the file with lzma-compatible compression before writing it. In input mode, this option is ignored; lzma com- pression is recognized automatically on input. -m, --preserve-modification-time (i and p modes) Set file modification time on created files to match those in the source. -n, --numeric-uid-gid (i mode, only with -t) Display numeric uid and gid. By default, cpio displays the user and group names when they are provided in the archive, or looks up the user and group names in the system password database. --no-preserve-owner (i mode only) Do not attempt to restore file ownership. This is the default when run by non-root users. -O file Write archive to file. -o, --create Output mode. See above for description. -p, --pass-through Pass-through mode. See above for description. --preserve-owner (i mode only) Restore file ownership. This is the default when run by the root user. --quiet Suppress unnecessary messages. -R [user][:][group], --owner [user][:][group] Set the owner and/or group on files in the output. If group is specified with no user (for example, -R :wheel) then the group will be set but not the user. If the user is specified with a trailing colon and no group (for example, -R root:) then the group will be set to the user's default group. If the user is specified with no trailing colon, then the user will be set but not the group. In -i and -p modes, this option can only be used by the super-user. (For compatibility, a period can be used in place of the colon.) -r (All modes.) Rename files interactively. For each file, a prompt is written to /dev/tty containing the name of the file and a line is read from /dev/tty. If the line read is blank, the file is skipped. If the line contains a single period, the file is processed normally. Otherwise, the line is taken to be the new name of the file. -t, --list (i mode only) List the contents of the archive to stdout; do not restore the contents to disk. -u, --unconditional (i and p modes) Unconditionally overwrite existing files. Ordinarily, an older file will not overwrite a newer file on disk. -V, --dot Print a dot to stderr for each file as it is processed. Superseded by -v. -v, --verbose Print the name of each file to stderr as it is processed. With -t, provide a detailed listing of each file. --version Print the program version information and exit. -y (o mode only) Compress the archive with bzip2-compatible compression before writing it. In input mode, this option is ignored; bzip2 compression is recognized automatically on input. -Z (o mode only) Compress the archive with compress-compatible compression before writing it. In input mode, this option is ignored; compression is recognized automatically on input. -z (o mode only) Compress the archive with gzip-compatible compression before writing it. In input mode, this option is ignored; gzip compression is recognized automatically on input. EXIT STATUS
The cpio utility exits 0 on success, and >0 if an error occurs. ENVIRONMENT
The following environment variables affect the execution of cpio: LANG The locale to use. See environ(7) for more information. TZ The timezone to use when displaying dates. See environ(7) for more information. EXAMPLES
The cpio command is traditionally used to copy file hierarchies in conjunction with the find(1) command. The first example here simply copies all files from src to dest: find src | cpio -pmud dest By carefully selecting options to the find(1) command and combining it with other standard utilities, it is possible to exercise very fine control over which files are copied. This next example copies files from src to dest that are more than 2 days old and whose names match a particular pattern: find src -mtime +2 | grep foo[bar] | cpio -pdmu dest This example copies files from src to dest that are more than 2 days old and which contain the word ``foobar'': find src -mtime +2 | xargs grep -l foobar | cpio -pdmu dest COMPATIBILITY
The mode options i, o, and p and the options a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2. The old POSIX.1 standard specified that only -i, -o, and -p were interpreted as command-line options. Each took a single argument of a list of modifier characters. For example, the standard syntax allows -imu but does not support -miu or -i -m -u, since m and u are only modifiers to -i, they are not command-line options in their own right. The syntax supported by this implementation is backwards-compatible with the standard. For best compatibility, scripts should limit themselves to the standard syntax. SEE ALSO
bzip2(1), tar(1), gzip(1), mt(1), pax(1), libarchive(3), cpio(5), libarchive-formats(5), tar(5) STANDARDS
There is no current POSIX standard for the cpio command; it appeared in ISO/IEC 9945-1:1996 (``POSIX.1'') but was dropped from IEEE Std 1003.1-2001 (``POSIX.1''). The cpio, ustar, and pax interchange file formats are defined by IEEE Std 1003.1-2001 (``POSIX.1'') for the pax command. HISTORY
The original cpio and find utilities were written by Dick Haight while working in AT&T's Unix Support Group. They first appeared in 1977 in PWB/UNIX 1.0, the ``Programmer's Work Bench'' system developed for use within AT&T. They were first released outside of AT&T as part of Sys- tem III Unix in 1981. As a result, cpio actually predates tar, even though it was not well-known outside of AT&T until some time later. This is a complete re-implementation based on the libarchive(3) library. BUGS
The cpio archive format has several basic limitations: It does not store user and group names, only numbers. As a result, it cannot be reli- ably used to transfer files between systems with dissimilar user and group numbering. Older cpio formats limit the user and group numbers to 16 or 18 bits, which is insufficient for modern systems. The cpio archive formats cannot support files over 4 gigabytes, except for the ``odc'' variant, which can support files up to 8 gigabytes. BSD
December 24, 2011 BSD
All times are GMT -4. The time now is 07:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy