Moving files to folders and rename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving files to folders and rename
# 1  
Old 11-06-2012
Moving files to folders and rename

Hello!

I am new to this. I have many files from b_ap00 to b_ap80, and I need to move them to folder 00 to 80 respectively, where b_ap00 is in folder 00, b_ap01 is in folder 01.

On top of this, I need to rename the file once they are inside the folder to b_ot, and subsequently run it (ifort -o b-i.x b_ot followed by ./b-i.x)

Could someone please guide me along? I managed to create the folders somehow but moving them in has problems.
# 2  
Old 11-06-2012
What OS and shell are you using?
Please post the output of:
Code:
uname -a
echo $SHELL

# 3  
Old 11-06-2012
Linux atlas5-c01 2.6.18-238.19.1.el5 #1 SMP Sun Jul 10 08:43:41 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

/bin/svush

Sorry what does this mean?
# 4  
Old 11-06-2012
try something like this..

Code:
for i in {0..80}
do
name=$(printf "%02d" $i)
file_name="b_ap$name"
mv $file_name /$name
mv /$name/$file_name #what you want to do
#do your operations here
done

# 5  
Old 11-06-2012
Hi!

Thank you so much. But I have this error:
mv: cannot create directory `/080': Permission denied
mv: missing destination file operand after `/80/b_ap80 #for all my files from 00

Basically this is what I did:
Code:
split -d -l 98 a01 b_ap

printf "%03d\n" $(seq 0 80) | xargs -I{} mkdir {}

for i in {0..80}
do
name=$(printf "%03d" $i)
file_name="$name"
mv $file_name /$name
mv /$name/$file_name/ #what you want to do
#do your operations here
done

# 6  
Old 11-06-2012
Quote:
Originally Posted by krustytherusty
mv: cannot create directory `/080': Permission denied
#Do you have create directory rights..?

mv: missing destination file operand after `/80/b_ap80 #for all my files from 00
# there is no directory so that's why it is showing this error.
# 7  
Old 11-06-2012
But when I checked the files, they are there. I used ls.

Or did I understand you wrongly?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recursivly rename folders removing characters as required

HI guys here's hoping some on pout the can help I have a large library of epub and mobi file creates some what by calibre. Output of tree listing below I would like to recursively rename the directories removing the brackets and numbers I have been scratching my head over... (4 Replies)
Discussion started by: dunryc
4 Replies

2. Shell Programming and Scripting

Moving files and folders to another folder

I recently bought Synology server and realised it can run scripts. I would need fairly simple script which moves all files and folders from ARCHIVE folder to WORKING folder. I would also need to maintain folder structure as each of the folders may contain subfolders. How would I go about it as I am... (1 Reply)
Discussion started by: ###
1 Replies

3. Shell Programming and Scripting

Script for moving series of sub folders

Hello, I'm new to this forum. Did a search but I didn't quite find what I was looking for. This is probably a fairly easy request but I'm just not sure how to accomplish this. I have a folder structure that looks something like this:/names/company1/archive /names/company1/newarchive ... (4 Replies)
Discussion started by: vipertech
4 Replies

4. UNIX for Dummies Questions & Answers

moving mail between IMAP folders

Hello all, I have a Cyrus IMAP server running on HP-UX. I have a requirement to run a script every night at midnight, which will take all the mail (read and unread mail) from one IMAP folder, and move it into a different IMAP folder. Both the source and destination IMAP folders belong to the... (1 Reply)
Discussion started by: lupin..the..3rd
1 Replies

5. Shell Programming and Scripting

moving files from one folder to many folders

I have a more than 10 K files in a folder. They are accumulated in a period of more than an year (Say from 13th July 2010 to 4th June 2011). I need to perform housekeeping on this. The requirement is to create a folder like 13Jul2010,14July2010,......3June2011,4June2010 and then from the main... (2 Replies)
Discussion started by: realspirituals
2 Replies

6. Red Hat

Moving folders

I'm new at this, so bare with me. I'm looking to move some folders, but keep the tree intact. Example: I have hundreds of folders in one directory (parent directory). In each folder there is a one folder called "source" and about 10 files. I want to move all the "Source" directories... (4 Replies)
Discussion started by: gnpower
4 Replies

7. UNIX for Dummies Questions & Answers

Rename files to indexnumber in multiple folders

I have multiple subfolders with multiple jpg I want the group of files in each subfolder renamed to their index number (3 digits) in the folder, so: folder/a.jpg = folder/001.jpg folder/b.jpg = folder/002.jpg folder/c.jpg = folder/003.jpg folder2/1.jpg = folder2/001.jpg folder2/2.jpg =... (2 Replies)
Discussion started by: cmanniche
2 Replies

8. Ubuntu

Moving folders with script

Hi All, I am new to Forums, as i am struggling for one script i am launched here. I need to move more than 60,000+ folders in 1,00,000 folders to another server. I have the list of folders which should be moved. can anybody help me in sharing with the script for the above requirement. ... (4 Replies)
Discussion started by: ghimakiran
4 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Find and rename all folders with name X.

Is there a command I can use to rename all directories with a certain name to a new name. For instance from my root directory I want to change all folders named '123' to '321' that are in the root directory or any subdirectory. Thanks in advance! (6 Replies)
Discussion started by: mkingrey
6 Replies
Login or Register to Ask a Question