LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-09-2010, 09:22 PM   #1
Ronin-8
LQ Newbie
 
Registered: Apr 2010
Distribution: Ubuntu 9.04
Posts: 13

Rep: Reputation: 0
Moving files by specifying a range


Hello all, I'm new here and this is my first time posting.

I'm trying to move files from one directory to another. I only want the files that start with a capital and within a certain range. Say all files that start with a capital between A-K. I've googled this and they all say to use: [A-M]*. But it moves all files A-M regardless if they are uppercase or lowercase.

Can someone please help me out? Thanks.
 
Old 04-09-2010, 10:29 PM   #2
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 96
Quote:
ay all files that start with a capital between A-K. I've googled this and they all say to use: [A-M]*.
Shold be ^[A-K]{1}.*
^[A-K]{1} - first character between A-K
Quote:
I'm trying to move files from one directory to another.
How? Where you use the regular expression?
 
Old 04-09-2010, 10:55 PM   #3
Ronin-8
LQ Newbie
 
Registered: Apr 2010
Distribution: Ubuntu 9.04
Posts: 13

Original Poster
Rep: Reputation: 0
Hi Troop,

Sorry but I'm unsure of what a regular expression is.

Before I ran into this problem I was moving files that started with an uppercase letter into a directory and moving files that started with a lowercase letter into a seperate directory and how I did this was with:

mv [[:upper:]]* directory
mv [[:lower:]]* directory

When I wanted to specify only files that begin with an uppercase from A-M and lowercase a-m I tried it with:

mv [A-M]* directory
mv [a-m]* directory

but it just moves all the files (A-M or a-m) regardless of whether they are capitalized or not.

Sorry I wasn't clearer in the first post.
 
Old 04-09-2010, 11:04 PM   #4
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 96
Code:
$ ls
atest  Atest  Btest  Ztes
$ mv [A-M]* /tmp/test2
$ ls
atest  Ztest
$ ls /tmp/test2
Atest  Btest
look at http://stackoverflow.com/questions/5...t-respect-case
 
Old 04-10-2010, 12:31 AM   #5
Ronin-8
LQ Newbie
 
Registered: Apr 2010
Distribution: Ubuntu 9.04
Posts: 13

Original Poster
Rep: Reputation: 0
Okay so I read the link, does bash have an environment variable for IGNORECASE and if so would you be able to tell me how I could see if it's value has been changed?

Last edited by Ronin-8; 04-10-2010 at 12:32 AM.
 
Old 04-10-2010, 01:54 AM   #6
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
great question

I never realized of this regular expression expansion until now, great to know.
Quote:
Shold be ^[A-K]{1}.*
^[A-K]{1} - first character between A-K
This code is a regular expression, but not a bash valid one, which is what the OP is looking for.

Code:
man bash
/Pathname Expansion
There are two factors which are responsible for this behavior. The shopt option "nocaseglob", and the LC_COLLATE locale variable. If you don't have LC_COLLATE set to C, (you probably have your locale set on it, something like "en_US.utf8") then letters of other case will be included too.

Just to put it clear:
Code:
nocaseglob
                      If  set,  bash  matches  filenames in a case-insensitive
                      fashion when performing pathname expansion (see Pathname
                      Expansion above).
(from the manual).
To set it,
Code:
shopt -s nocaseglob
To unset it,
Code:
shopt -u nocaseglob
So, for the desired behavior, you must do the following
Code:
export LC_COLLATE=C
shopt -u nocaseglob #it's probably unset by default too, but just in case
If you wanted to ignore the case, just set nocaseglob again.
 
1 members found this post helpful.
Old 04-10-2010, 06:09 PM   #7
Ronin-8
LQ Newbie
 
Registered: Apr 2010
Distribution: Ubuntu 9.04
Posts: 13

Original Poster
Rep: Reputation: 0
Thank you rikijpn, it works now.
 
Old 04-11-2010, 01:27 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,565

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Please mark as SOLVED when you ave your solution.
 
  


Reply


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
Question about moving a range of files with a Bash script surfrock66 Linux - Newbie 6 11-22-2009 04:37 PM
moving files from a location to other, preventing to move incomplete files pogo123 Programming 8 11-14-2008 07:21 AM
moving files from a location to other, preventing to move incomplete files pogo123 Linux - Newbie 2 11-13-2008 02:57 PM
selecting a range of files.... mjh Programming 0 03-12-2008 10:02 AM
copying a range of files maginotjr Linux - General 3 07-27-2005 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:23 PM.

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