mv three letter long folders


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers mv three letter long folders
# 1  
Old 01-19-2011
Question mv three letter long folders

Hi,
Quick question: My directory has folders such as 001, 002, ... till 99999.

I would like to move all three digit folders into one folder, say /three, all four digit folder into /four, and five digit folders into /five. What is the easiest way to use mv to achieve this?

mv 00% /three does not work. (what should be the regex syntax to replace one character alone)?

I use Ubuntu 10.10 64bit. Thanks in advance!
# 2  
Old 01-19-2011
simple shell interpretation use the question mark :

Code:
# ls ??
f1  f2  in  ml
# ls ???
com  ref  tab  ts1  ts2  tst
# ls ????
atst  mtst  tst2

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 01-19-2011
works

Okay, square brackets match a character class eh... so this works:

Code:
mv -iv [0-9][0-9][0-9] /three
mv -iv [0-9][0-9][0-9][0-9] /four
mv -iv [0-9][0-9][0-9][0-9][0-9] /five

---------- Post updated at 01:41 PM ---------- Previous update was at 01:36 PM ----------

Thanks ctsgnb.

Code:
mv -iv ??? /three

# 4  
Old 01-19-2011
All by one line command, it will automatical generate the folder (name as 1,2,3...)

If the awk command is successful, then run the command with red part.
Code:
ls -l |awk '/^d/ {s="/abc/xyz/" length($NF);print "mkdir", s, "; mv",$NF,s}' |sh


Last edited by rdcwayx; 01-19-2011 at 11:02 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies

3. UNIX for Dummies Questions & Answers

Archive folders and sub folders

Hi Can i archive folder and folders in with the tar command My files are located in subfolders Eg: Folder1/Folder1_1/*.pdf Folder1/Folder1_2/*.pdf Folder1/Folder1_3/*.pdf so i would like to tar all the files in Folder1_1 and Folder1_2 only not Folder1_3 that should be done next... (2 Replies)
Discussion started by: cnrj
2 Replies

4. Shell Programming and Scripting

Copy between two different folders containing same sub-folders

I have a folder like this ls input1 dir1 dir2 dir3 file1 file2 file3 dir1, dir2 and dir3 are sub-folders inside the folder input1 ls input2 dir1 dir2 dir3 file1 file2 file3 My dir1 in input1 folder has files f1, f2, f3 and f4. My dir1 in input2 folder has file f4 and f5. ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

6. Shell Programming and Scripting

Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and... (18 Replies)
Discussion started by: YukonAppleGeek
18 Replies

7. UNIX for Dummies Questions & Answers

If first letter of name is a-m do this if n-x do something else

so if I run echo $USER and the name is smithr i want to run command B to run because s is after m in the alphabet, but if the user is aldap I want command A to run because their first initial in the user name is in the first half of alphabet. how please? (2 Replies)
Discussion started by: glev2005
2 Replies

8. UNIX for Dummies Questions & Answers

SORT by letter

Hello again, Since I am UNIX new user I have this question: I have this file: 1 A A 1 A A 1 A A 1 B B 1 B B 1 X X 1 X X 1 C C Could anyone of you help me to sort this file like this: (I need all A and X together) 1 A A 1 A A (1 Reply)
Discussion started by: murbina
1 Replies

9. UNIX for Dummies Questions & Answers

Copying Folders without some folders... ;-)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (5 Replies)
Discussion started by: chimpu
5 Replies

10. Shell Programming and Scripting

Backing up Folders without some folders...;)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (1 Reply)
Discussion started by: chimpu
1 Replies
Login or Register to Ask a Question