Sponsored Content
Top Forums Shell Programming and Scripting Moving files from parent path to multiple child path using bash in efficient way Post 302942907 by Don Cragun on Sunday 3rd of May 2015 08:18:38 PM
Old 05-03-2015
Your requirement isn't clear.
  1. Does the file hierarchy you're modifying contain symbolic links matched by the patterns /Path/AdminUser/* and /Path/AdminUser/*/*? Your textual description didn't say anything about symbolic links, but your (non-working) code explicitly ignores them. If symbolic links are found, what do want to have done with them?
  2. Are you trying to move all files in the file hierarchy rooted in /Path/AdminUser/ up one level in that hierarchy to /Path/; or are you just trying to move regular files with pathnames matching the pattern /Path/AdminUser/*/*/Reports/*.txt to the corresponding pathname after removing AdminUser/ from the source pathname?
  3. If a directory in the target pathname does not already exist, should your script report an error and move on, should it create the missing directories, or should it silently ignore that source pathname?
  4. Do you want to leave the (empty) source directories in place after files are moved out of them, or should emptied directories be removed?
  5. Is the entire file hierarchy rooted in /Path in a single filesystem?
Instead of saying "It still threw error, can we also write it in an efficient way?", show us exactly what "error(s) it produces" (in CODE tags).

What do you believe it is doing inefficiently?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Moving files by splitting the path embedded in the filename

Hello All. I am having a directory /tmp/rahul which contains many files in the format @#home@#rahul@#programs@#script.pl where /home/rahul/programs is the directory where the script.pl file is to be placed. I have many files in this format. What i want is a script which read these... (7 Replies)
Discussion started by: rahulrathod
7 Replies

2. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

3. Shell Programming and Scripting

multiple child scripts running in backgroud, how to use grep on the parent?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (5 Replies)
Discussion started by: albertashish
5 Replies

4. Shell Programming and Scripting

moving multiple folders/files in subversion using bash script

Hi, I'm new here an dlearning a lot from this forum. i didnt find any solution for this in the forum. I have already checked in folders in subversion named HTT01,... HTT21.. and have files in each folder like below: HTT01/HTT01_00000.hex HTT01/HTT01_00000_fb_result.hex... (2 Replies)
Discussion started by: ravishan21
2 Replies

5. Emergency UNIX and Linux Support

Find, replace, file path in multiple files for Solaris 10

Guys I have a big issue that I need to get fixed ASAP however I can not seem to find a way to do it. We started to use zones with Solaris 10 at work and we moved a zone from a SIT box to a DEV box. Problem is the software we have installed is looking at a /lcl/sit/apps/ path and it needs to look... (5 Replies)
Discussion started by: LRoberts
5 Replies

6. Homework & Coursework Questions

Problem with path and child shells

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: a) Some Unix tools are at $HOME/mytools directory. Make these tools accessible for use from any directory. b)... (2 Replies)
Discussion started by: justOne21
2 Replies

7. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

8. Shell Programming and Scripting

How to list all Subdirectories and files with its full path in a parent directory?

How to list all Subdirectories and files with its full path in a parent directory? (1 Reply)
Discussion started by: johnveslin
1 Replies

9. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

10. Shell Programming and Scripting

Bash to trim folder and files within a path that share a common file extension

The bash will trim the folder to trim folder. Within each of the folders (there may be more than 1) and the format is always the same, are several .bam and matching .bam.bai files (file structure) and the bashunder that executes and trims the .bam as expected but repeats the.bam.bai extentions... (9 Replies)
Discussion started by: cmccabe
9 Replies
MTREE(8)						    BSD System Manager's Manual 						  MTREE(8)

NAME
mtree -- map a directory hierarchy SYNOPSIS
mtree [-LPUcdeinqruxw] [-f spec] [-f spec] [-K keywords] [-k keywords] [-p path] [-s seed] [-X exclude-list] DESCRIPTION
The mtree utility compares the file hierarchy rooted in the current directory against a specification read from the standard input. Messages are written to the standard output for any files whose characteristics do not match the specifications, or which are missing from either the file hierarchy or the specification. The options are as follows: -c Print a specification for the file hierarchy to the standard output. -d Ignore everything except directory type files. -e Do not complain about files that are in the file hierarchy, but not in the specification. -f file Read the specification from file, instead of from the standard input. If this option is specified twice, the two specifications are compared with each other, rather than to the file hierarchy. The speci- fications be sorted like output generated using -c. The output format in this case is somewhat remniscent of comm(1), having "in first spec only", "in second spec only", and "different" columns, prefixed by zero, one and two TAB characters respectively. Each entry in the "different" column occupies two lines, one from each specification. -i Indent the output 4 spaces each time a directory level is descended when create a specification with the -c option. This does not affect either the /set statements or the comment before each directory. It does however affect the comment before the close of each directory. -K keywords Add the specified (whitespace or comma separated) keywords to the current set of keywords. -k keywords Use the ``type'' keyword plus the specified (whitespace or comma separated) keywords instead of the current set of keywords. -L Follow all symbolic links in the file hierarchy. -n Do not emit pathname comments when creating a specification. Normally a comment is emitted before each directory and before the close of that directory when using the -c option. -P Do not follow symbolic links in the file hierarchy, instead consider the symbolic link itself in any comparisons. This is the default. -p path Use the file hierarchy rooted in path, instead of the current directory. -q Quiet mode. Do not complain when a ``missing'' directory cannot be created because it already exists. This occurs when the directory is a symbolic link. -r Remove any files in the file hierarchy that are not described in the specification. -s seed Display a single checksum to the standard error output that represents all of the files for which the keyword cksum was specified. The checksum is seeded with the specified value. -U Modify the owner, group, permissions, and modification time of existing files to match the specification and create any missing direc- tories or symbolic links. User, group and permissions must all be specified for missing directories to be created. Corrected mis- matches are not considered errors. -u Same as -U except a status of 2 is returned if the file hierarchy did not match the specification. -w Make some error conditions non-fatal warnings. -X exclude-list The specified file contains fnmatch(3) patterns matching files to be excluded from the specification, one to a line. If the pattern contains a '/' character, it will be matched against entire pathnames (relative to the starting directory); otherwise, it will be matched against basenames only. No comments are allowed in the exclude-list file. -x Do not descend below mount points in the file hierarchy. Specifications are mostly composed of ``keywords'', i.e., strings that specify values relating to files. No keywords have default values, and if a keyword has no value set, no checks based on it are performed. Currently supported keywords are as follows: cksum The checksum of the file using the default algorithm specified by the cksum(1) utility. flags The file flags as a symbolic name. See chflags(1) for information on these names. If no flags are to be set the string ``none'' may be used to override the current default. ignore Ignore any file hierarchy below this file. gid The file group as a numeric value. gname The file group as a symbolic name. md5digest The MD5 message digest of the file. sha1digest The FIPS 160-1 (``SHA-1'') message digest of the file. ripemd160digest The RIPEMD160 message digest of the file. mode The current file's permissions as a numeric (octal) or symbolic value. nlink The number of hard links the file is expected to have. nochange Make sure this file or directory exists but otherwise ignore all attributes. uid The file owner as a numeric value. uname The file owner as a symbolic name. size The size, in bytes, of the file. link The file the symbolic link is expected to reference. time The last modification time of the file. type The type of the file; may be set to any one of the following: block block special device char character special device dir directory fifo fifo file regular file link symbolic link socket socket The default set of keywords are flags, gid, mode, nlink, size, link, time, and uid. There are four types of lines in a specification. The first type of line sets a global value for a keyword, and consists of the string ``/set'' followed by whitespace, followed by sets of keyword/value pairs, separated by whitespace. Keyword/value pairs consist of a keyword, followed by an equals sign (``=''), followed by a value, without whitespace characters. Once a keyword has been set, its value remains unchanged until either reset or unset. The second type of line unsets keywords and consists of the string ``/unset'', followed by whitespace, followed by one or more keywords, sep- arated by whitespace. The third type of line is a file specification and consists of a file name, followed by whitespace, followed by zero or more whitespace sepa- rated keyword/value pairs. The file name may be preceded by whitespace characters. The file name may contain any of the standard file name matching characters (``['', ``]'', ``?'' or ``*''), in which case files in the hierarchy will be associated with the first pattern that they match. Each of the keyword/value pairs consist of a keyword, followed by an equals sign (``=''), followed by the keyword's value, without whitespace characters. These values override, without changing, the global value of the corresponding keyword. All paths are relative. Specifying a directory will cause subsequent files to be searched for in that directory hierarchy. Which brings us to the last type of line in a specification: a line containing only the string ``..'' causes the current directory path to ascend one level. Empty lines and lines whose first non-whitespace character is a hash mark (``#'') are ignored. The mtree utility exits with a status of 0 on success, 1 if any error occurred, and 2 if the file hierarchy did not match the specification. A status of 2 is converted to a status of 0 if the -U option is used. FILES
/etc/mtree system specification directory EXIT STATUS
The mtree utility exits 0 on success, and >0 if an error occurs. EXAMPLES
The -d and -u options can be used in combination to create directory hierarchies for distributions and other such things; the files in /etc/mtree were used to create almost all directories in this FreeBSD distribution. SEE ALSO
chflags(1), chgrp(1), chmod(1), cksum(1), md5(1), stat(2), fts(3), md5(3), chown(8) HISTORY
The mtree utility appeared in 4.3BSD-Reno. The MD5 digest capability was added in FreeBSD 2.1, in response to the widespread use of programs which can spoof cksum(1). The SHA-1 and RIPEMD160 digests were added in FreeBSD 4.0, as new attacks have demonstrated weaknesses in MD5. Support for file flags was added in FreeBSD 4.0, and mostly comes from NetBSD. BSD
March 29, 2005 BSD
All times are GMT -4. The time now is 06:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy