LinuxQuestions.org
Review your favorite Linux distribution.
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 03-21-2012, 02:37 AM   #1
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Rep: Reputation: Disabled
Moving some files


Hello,

There are 4750 files in one of my folder whereas I want to move only 491 files or x number of files.

Thanks in anticipation
 
Old 03-21-2012, 03:15 AM   #2
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,194
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
I don't think the information you provided is adequate

do you want to move files according to some name convention or the first or last x no. of files?
which distro are you using?
 
Old 03-21-2012, 04:29 AM   #3
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for your reply

I am using the mv -f /myFiles/* destinationDir/

All files (4K+) are doc extensions. The task is to move <500 files and then to process them i.e. inserting into database

RHE is my OS

Best regards
 
Old 03-21-2012, 07:01 AM   #4
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,194
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
this will require some sort of script and I am not so good with that but as per my level of knowledge you can try this

Code:
#find /source/directory -type f -size +4K -iname "*.doc"  -exec mv {} /destination/ \;
This will search for all the files with ".doc" extension and size more than 4K and move to your destination directory but if you want to copy a limited no. of files, I don't know if that can be done through single command. You can wait for some senior advise

Last edited by deep27ak; 03-21-2012 at 07:45 AM.
 
Old 03-21-2012, 01:07 PM   #5
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
Thanks for giving me your precious time but not works in my case. Actually your script is looking for 2k or 4k file size whereas I want to move number of files not specific size files.

The problem is all files are same extension i.e. *.doc and the quantity of files is 4K+

Thanks again
 
Old 03-21-2012, 01:22 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by Raakh5 View Post
Thanks for giving me your precious time but not works in my case. Actually your script is looking for 2k or 4k file size whereas I want to move number of files not specific size files.

The problem is all files are same extension i.e. *.doc and the quantity of files is 4K+

Thanks again
deep27ak gave you a good start. If you looked into the solution a bit more, you'd find solutions:
Code:
ls| sort -n | head -500| xargs -i mv "{}" /destination
 
1 members found this post helpful.
Old 03-21-2012, 01:46 PM   #7
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
Sorry!!

Last edited by Raakh5; 03-21-2012 at 04:46 PM.
 
Old 03-21-2012, 03:35 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
The command he wrote won't delete anything, it simply moves. Your missing files are located wherever you set the destination, in his example that was /destination
 
1 members found this post helpful.
Old 03-21-2012, 04:29 PM   #9
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
Thanks God!! this was really heart attack to loss 5 years data. I found the files but not understand where is the source folder path to move? I can see the destination folder but where I put source folder path?
 
Old 03-21-2012, 04:37 PM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by Raakh5 View Post
UFFFFFFFFFF what command you written to me. My all directories deleted. To hell with you there was very precious data that I lost
...and...
Quote:
Originally Posted by Raakh5
Thanks God!! this was really heart attack to loss 5 years data. I found the files but not understand where is the source folder path to move? I can see the destination folder but where I put source folder path?
The source is, very obviously, is where the files you want to move are currently located. You put it after the "ls" since that's where the directory listing will come from, or you can run the command FROM the source directory. The /destination is whatever you tell it. You can easily look up each bit of the command I gave you, and figure out what they do. You asked about how to MOVE files...that means, take them from one place, and put them in another, removing them from the original location. If you want them in BOTH places, that's called a "copy".

And I'm not sure how 'precious' that data is, if you haven't bothered to back it up, so you won't lose any of it. Before you start spouting off about "to hell with you", try putting some effort into looking things up on Google, or coming up with your OWN solution.

Last edited by TB0ne; 03-21-2012 at 04:38 PM.
 
Old 03-21-2012, 04:47 PM   #11
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
I believed this is beginners forum and I am really sorry for the words I wrote earlier. Anyways I removed.

Furthermore, Thanks for your cooperation
 
Old 03-21-2012, 04:48 PM   #12
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Before running any script in which you don't have 100% confidence, you should stick an "echo" in front of any command that actually does something potentially dangerous, eg:
Code:
ls| sort -n | head -500| xargs -i echo mv "{}" /destination
Rather than actually running the mv on each file, it will instead print out on the terminal exactly what it would normally run. If this doesn't look like what you're expecting, modify the code until it does, then remove the echo to actually do it.
 
4 members found this post helpful.
Old 03-21-2012, 05:07 PM   #13
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
Thanks to all from the bottom of my heart particularly TB0ne and suicidaleggroll

Best regards
 
Old 03-21-2012, 05:08 PM   #14
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by suicidaleggroll View Post
Before running any script in which you don't have 100% confidence, you should stick an "echo" in front of any command that actually does something potentially dangerous, eg:
Code:
ls| sort -n | head -500| xargs -i echo mv "{}" /destination
Rather than actually running the mv on each file, it will instead print out on the terminal exactly what it would normally run. If this doesn't look like what you're expecting, modify the code until it does, then remove the echo to actually do it.
Nice one, suicidaleggroll...didn't think of that.
 
  


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 except a few pccdrussell Linux - General 7 07-22-2007 12:03 AM
Moving Files arockia Linare 3 09-08-2004 09:14 AM


All times are GMT -5. The time now is 08:28 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