|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Move parent folder if contents match a parameter
Hi all,
Hoping someone can help. I'm looking to be able to search a particular folder path for folders that contain certain files / formats and then move the parent folder. eg. /foo/bar/folder1/file.exe /foo/bar/folder2/file.exe and then move the folder1/2 tp another folder. So if the contents of the folder contain say a file format of .exe it will move it otherwise ignore it Thanks |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
You can move a folder like you move a file: with the "mv" command: Code:
mv /path/to/old/folder /path/to/new/folder You just have to search for the files/folders or whatever triggers the moving action (look at the man page of "find" for this) and then cut off the last part(s) of the resulting path as parameter for "mv". You can do that with shell parameter expansion. For instance: suppose you found a file "/path/we/indend/to/move/file.exe" and you want to move everything from "/path/we/intend/to" to "/somewhere/else": Code:
foundfile="/path/we/intend/to/move/file.exe" # this would have been found
target=""
destination="/somewhere/else"
target="${foundfile%/*}" # chops off the filename -> "/path/we/intend/to/move"
target="${foundfile%/*/*}" # chops off filename plus one dir -> "/path/we/intend/to"
target="${foundfile%/*/*/*}" # chops off filename plus two dirs -> "/path/we/intend"
mv "$target" "$destination" # carry out the moving actionI hope this helps. bakunin |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep with parent folder | OmarKN | UNIX for Dummies Questions & Answers | 9 | 07-11-2012 09:27 AM |
| copy folder and its contents to another folder | amvarma77 | Shell Programming and Scripting | 1 | 06-06-2012 08:50 AM |
| want to move set of file from one folder to another folder | natraj005 | Shell Programming and Scripting | 6 | 08-23-2011 08:30 AM |
| Pass parameter from a child make to a parent | marina_lmv | Programming | 4 | 10-04-2010 10:24 AM |
| File Management: How do I move all JPGS in a folder structure to a single folder? | guptaxpn | Shell Programming and Scripting | 4 | 06-11-2009 02:41 AM |
|
|