Find and Move Files up One Level


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and Move Files up One Level
# 1  
Old 04-20-2012
Find and Move Files up One Level

Hi All,

So I have another question. I'm trying to search for files with a certain extension and then move all of them up one level in the folder hierarchy.

So something like this:
original: /path/to/file/test.txt
after: /path/to/test.txt

I had some great help recently with another issue here: and its very related

https://www.unix.com/shell-programmin...uppercase.html

Could someone maybe point me in the right direction?

Thank You

edit: I always forget: Solaris 10

Moderator's Comments:
Mod Comment Title corrected...

Last edited by ideal2545; 04-20-2012 at 01:32 PM..
# 2  
Old 04-20-2012
Anything wrong with just:
Code:
 mv *.<ext> ../.

?
# 3  
Old 04-20-2012
Hi vbe, thanks for the quick response, I have about a thousand directories that I need to apply it recursively to.


Basically I have something like

/path/to/application/files/and/stuff/a1/nolongerneededirectory/*.*
/path/to/application/files/and/stuff/a2/nolongerneededirectory/*.*
/path/to/application/files/and/stuff/a3/nolongerneededirectory/*.*


So Im trying to move them up like this:

/path/to/application/files/and/stuff/a1/*.*
/path/to/application/files/and/stuff/a2/*.*
/path/to/application/files/and/stuff/a3/*.*

---------- Post updated at 10:15 AM ---------- Previous update was at 09:43 AM ----------

I thought maybe it would be easier to do a find and then whatever it finds based on extenstion, to move it up one level.

I ran across this:

find A -type f -exec sh -c 'mv -i "$1" "${1%/*}"' sh {} \;

but I get a "bad substitution" if I try this. I also not sure if it would actually accomplish the task.

Ideally it would do something like:


-bash-3.2$ find /path/to/ -name '*.txt'
output:
/path/to/directories1/test1/test1.txt
/path/to/directories2/test2/test2.txt
/path/to/directories3/test3/test3.txt

then
mv /path/to/directories1/test1/test1.txt /path/to/directories1/test1.txt
mv /path/to/directories2/test2/test2.txt /path/to/directories2/test2.txt
mv /path/to/directories3/test3/test3.txt /path/to/directories3/test3.txt

Last edited by ideal2545; 04-20-2012 at 02:21 PM..
# 4  
Old 04-20-2012
Please define the problem clearly.
How do you define files which need to move? Are there any files in the directories containing these selected files which do not move? Are there any files anywhere in the directory tree other than at the bottom of the tree? i.e. is it sufficient to just rename the bottom level directory rather than work on individual files?
# 5  
Old 04-20-2012
Hi Methyl,

I had a lead one how to do this so I asked another question in the newbie area about the MV command and I was very graciously helped by Corona. I will post the solution here for future reference.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Move all files one directory level up

I want to move all the files in a given directory up one level. For example: Dir1 Subdir1 I want to move all the files in Subdir1 up to Dir1 (then I want to ultimately delete Subdir1) Thanks, Ted (10 Replies)
Discussion started by: ftrobaugh
10 Replies

2. Shell Programming and Scripting

Find and Move files

I have the below command to delete all .xml files older than 90 days find . -type f -name '*.xml' -mtime +90 -exec rm {} \; What will be the command to move all the .xml files older than 90 days to this folder -> "/tmp/my_bk" My OS: SunOS my-pc 5.10 Generic_150400-17 sun4v sparc... (4 Replies)
Discussion started by: mohtashims
4 Replies

3. UNIX for Dummies Questions & Answers

Find a list of files in directory, move to new, allow duplicates

Greetings. I know enough Unix to be dangerous (!) and know that there is a clever way to do the following and it will save me about a day of agony (this time) and I will use it forever after! (many days of agony saved in the future)! Basically I need to find any image files (JPGs, PSDs etc)... (5 Replies)
Discussion started by: Clyde Lovett
5 Replies

4. Shell Programming and Scripting

Please help list/find files greater 1G move to different directory

I have have 6 empty directory below. I would like write bash scipt if any files less "1000000000" bytes then move to "/export/home/mytmp/final" folder first and any files greater than "1000000000" bytes then move to final1, final2, final3, final4, final4, final5 and that depend see how many files,... (6 Replies)
Discussion started by: dotran
6 Replies

5. Shell Programming and Scripting

Find and move files parsed from cvs file

I need help with a bash script. We have a directory of files which need to be renamed and moved to another directory based on filename information in a cvs file. The contents of the cvs file are as follows: A102345,abc123 A102347,dfg475 Where dfg475 is the basename without extension Our... (8 Replies)
Discussion started by: Lloyd Boyette
8 Replies

6. Shell Programming and Scripting

move directories up one level

hi , could you help me with shell scripting in a shell script i have these commands a=`ls -R $dir | grep ./ ` cp -R ./$a/* ./$output/ with the first command i have all the directories with the second command i want to copy them in a new directory something like this... (2 Replies)
Discussion started by: faethon
2 Replies

7. Shell Programming and Scripting

Recursively move a subfolder to one upper level

Hi, all: My folder structure is like: What I'm expecting to realize is to have my folders look like: How to realize it? Cheers Pei (0 Replies)
Discussion started by: jiapei100
0 Replies

8. UNIX for Dummies Questions & Answers

find files on first level folder

Hi: I have: folderA |----folderB |----folder1 |----folder2 |----folder3 |----folder3.1 Question: How can I find *.txt ONLY from /folderA/folderB/ and not the others folder1,2,3?? I tried: find... (8 Replies)
Discussion started by: iga3725
8 Replies

9. Red Hat

Find a word from multiple level files on Linux

To find a word from multiple level files: "find . -type f -exec grep {} +" is working on UNIX machines but not working on Linux machine. What is the equivalent command on Linux to find the word from multiple level files? Input is appreciated. (3 Replies)
Discussion started by: ywu081006
3 Replies

10. Shell Programming and Scripting

find top 100 files and move them

i have some 1000 files in my dir and i want to find top 100 files and move them to some other location: below the 2 commands i used, but it is not working ls -ltr | grep ^- | head -100 | xargs mv destination - _________>not working ls -ltr | grep ^- | head -100 | xargs mv {}... (3 Replies)
Discussion started by: ali560045
3 Replies
Login or Register to Ask a Question