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 05-14-2011, 12:52 PM   #1
andy.l
Member
 
Registered: Feb 2007
Location: Scandinavia
Distribution: Fedora Core 6/Ubuntu 6.10
Posts: 93

Rep: Reputation: 15
Question moving files


Hi
I have some files that start with Uppercase. How can I easily move those files to a dedicated folder based on that the first character us uppercase?

/Andy
 
Old 05-14-2011, 01:15 PM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Something like this might work:
Code:
find . -maxdepth 1 | grep [[:upper:]].* | xargs mv -t /yourdir/
Searches in the current directory only, no subdirs, for all files, then greps the ones that begin with an Uppercase and passes each one found to the mv command with xargs. Hope it helps.

Kind regards,

Eric
 
Old 05-14-2011, 04:40 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
How about this:

Code:
find . -maxdepth 1 -regex '^[A-Z].*' -exec mv '{}' /path/to/destination/dir ';'
 
Old 05-14-2011, 05:48 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by MTK358 View Post
How about this:

Code:
find . -maxdepth 1 -regex '^[A-Z].*' -exec mv '{}' /path/to/destination/dir ';'
Your regex doesn't work, in fact it will never work on a Linux file-system; try
Code:
'.*/[A-Z].*'
instead.


Cheers,
Tink
 
Old 05-14-2011, 07:07 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Tinkster View Post
Your regex doesn't work, in fact it will never work on a Linux file-system; try
I understand now, but what does it have to do with the Linux file system?
 
Old 05-14-2011, 07:09 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by MTK358 View Post
I understand now, but what does it have to do with the Linux file system?
It may work on other OSes/file-systems, where find won't be
returning leading "/" ...



Cheers,
Tink
 
Old 05-14-2011, 08:13 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Tinkster View Post
It may work on other OSes/file-systems, where find won't be
returning leading "/" ...
I thought that that's just the way find prints the filenames. ls, for example, doesn't print "./" before every filename.
 
Old 05-14-2011, 09:34 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
If we're only concerned with the current directory, is there a reason we don't just use mv?
Code:
mv [A-Z]* dir/
Unless of course we have directories that might be affected, although none of the finds allow for this either.
 
Old 05-15-2011, 01:39 AM   #9
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by MTK358 View Post
How about this:

Code:
find . -maxdepth 1 -regex '^[A-Z].*' -exec mv '{}' /path/to/destination/dir ';'
Hi,

I was thinking about something along that line too but when testing the regex, couldn't get it to work, so I used grep instead which gave me the result I was looking for.

Kind regards,

Eric
 
Old 05-15-2011, 01:41 AM   #10
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by Tinkster View Post
Your regex doesn't work, in fact it will never work on a Linux file-system; try
Code:
'.*/[A-Z].*'
instead.


Cheers,
Tink
Hi,

Doesn't work on my LMDE, it returns all files in the directory instead of only the ones that begin with Uppercase. I've been playing around with this yesterday and the only one I got working on my system is the one using grep.

Kind regards,

Eric

Last edited by EricTRA; 05-15-2011 at 01:48 AM.
 
Old 05-15-2011, 01:56 AM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by EricTRA View Post
Hi,

Doesn't work on my LMDE, it returns all files in the directory instead of only the ones that begin with Uppercase. I've been playing around with this yesterday and the only one I got working on my system is the one using grep.

Kind regards,

Eric

Makes me wonder about your locale, and it's collation; it certainly
works as designed here.



Cheers,
Tink
 
Old 05-15-2011, 02:04 AM   #12
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi Tink,

This is output from locale:
Code:
eric@ericvs-laptop ~ $ locale
LANG=en_US.utf8
LANGUAGE=
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
Don't know exactly to what you refer when mentioning the collation of locale. How do I check that?

Kind regards,

Eric
 
Old 05-15-2011, 02:08 AM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by EricTRA View Post
Hi Tink,

This is output from locale:
Code:
eric@ericvs-laptop ~ $ locale
LANG=en_US.utf8
LANGUAGE=
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
Don't know exactly to what you refer when mentioning the collation of locale. How do I check that?

Kind regards,

Eric
There it is - and it should "just work". Very odd, I must say.
I don't understand how the find matches everything for you. You
don't have an alias using -iregex by any chance? =o)


Cheers,
Tink
 
Old 05-15-2011, 02:13 AM   #14
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Didn't even see that one and no I don't have any aliases using iregex:
Code:
eric@ericvs-laptop ~ $ alias
alias grep='grep --colour=auto'
alias ls='ls --color=auto'
Using:
Code:
ii  findutils        4.4.2-1+b1       utilities for finding files--find, xargs
and
Code:
eric@ericvs-laptop ~ $ bash --version
GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
I've encountered the same issue when trying to help LQ users, forcing me to use piping into grep when I could be using find itself. Never paid it much attention though except now.

Kind regards,

Eric
 
  


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
After moving PHP files to /var/www they no longer are seen as hosted php files scheidel21 Linux - Server 9 03-01-2010 08:16 AM
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
Moving files madwac Linux - Newbie 15 08-22-2007 10:28 AM
Moving Files arockia Linare 3 09-08-2004 09:14 AM


All times are GMT -5. The time now is 02:38 AM.

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