Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-24-2017, 06:27 AM   #1
Registered: Apr 2017
Posts: 33

Rep: Reputation: Disabled
Creating folders and moving files in shell script


I want to create folders and move the files into folder using shell script. For example, I have 50,000 files (choose only the specific extnsion), I want to create 50 folders, each having 1000 files. The files are named like 1.txt, 2.txt ... , 50000.txt. So 1.txt-1000.txt should be in folder 1, 1001.txt-2000.txt should be in folder 2 and so on...

My test code that runs on only 10 sample txt files is below:

for i in {1..5}
	mkdir "$i"
	for file in *.txt:
		mv "{$begin..$end}.txt" "$i"

It gives error,'mv: cannot stat '{1..10}.txt': No such file or directory'. I am able to create directories but cannot move the files into specified folders.

Thanks in advance.
Old 05-24-2017, 07:38 AM   #2
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 382Reputation: 382Reputation: 382Reputation: 382
Debug advice: use echo in place of your mv; use shell -vx switches.

p.s. Please mark your prior thread resolved, via ThreadTools, at top.
Thanks and best wishes for success. Welcome to LQ

Last edited by !!!; 05-24-2017 at 07:43 AM.
1 members found this post helpful.
Old 05-24-2017, 08:48 AM   #3
Registered: Apr 2017
Posts: 33

Original Poster
Rep: Reputation: Disabled
Thank you for the reply.

I used "eval" and it worked.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help creating script to process files in folders jkellogg Linux - General 4 08-01-2016 08:45 AM
Using rm in Bash shell script on files/folders with spaces in for loop array kayasaman Programming 18 05-16-2013 07:34 AM
Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders unix_72427 Programming 8 08-08-2012 03:51 PM
Shell script on copying files and folders from a linux server to a windows server nithin6034 General 6 07-20-2011 08:59 AM
Shell script to delete folders and files dynamically and recursively rjbaca Linux - General 1 06-21-2010 12:26 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration