LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Moving some files (https://www.linuxquestions.org/questions/linux-newbie-8/moving-some-files-935612/)

Raakh5 03-21-2012 01:37 AM

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

deep27ak 03-21-2012 02:15 AM

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?

Raakh5 03-21-2012 03:29 AM

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

deep27ak 03-21-2012 06:01 AM

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

Raakh5 03-21-2012 12:07 PM

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

TB0ne 03-21-2012 12:22 PM

Quote:

Originally Posted by Raakh5 (Post 4632708)
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

Raakh5 03-21-2012 12:46 PM

Sorry!!

suicidaleggroll 03-21-2012 02:35 PM

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

Raakh5 03-21-2012 03:29 PM

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?

TB0ne 03-21-2012 03:37 PM

Quote:

Originally Posted by Raakh5 (Post 4632748)
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.

Raakh5 03-21-2012 03:47 PM

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

suicidaleggroll 03-21-2012 03:48 PM

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.

Raakh5 03-21-2012 04:07 PM

Thanks to all from the bottom of my heart particularly TB0ne and suicidaleggroll

Best regards

TB0ne 03-21-2012 04:08 PM

Quote:

Originally Posted by suicidaleggroll (Post 4632941)
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.


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