How to invoke a text file as a list of commands

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












Problem: 245,000 plus files residing in multiple recup_dir folders (output from photo_rec run) needing to be moved to a centralized folder for further recovery operations. All files are *.jpg files.



I have a text file named newlist1.txt that I have formatted in the following 4 ways. And to change to each variety, a good find/replace editor is essential. these script files are in a folder /disks/Keep/new-s1-recov. I know, I could have used just . to indicate where to mv the files, but initially, the scripts were in another folder, and the period would not have sufficed.



  1. echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov


  2. echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov


  3. echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


  4. ls recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


the last two examples, 3 & 4, work correctly when executed from the command line.
None of the examples work when I type



sh newlist1.txt


or



bash newlist1.txt


The thing is, I have over 245000 files that need to be moved. Why don't I use the file manager and do groups of several hundred at a time? Because the file manager is possibly the worst piece of software in Ubuntu 16.04.3. So, the command line is the preferable way of accomplishing this task. If I spend several days figuring out how to get it done like this, I'll consider it time well spent. I have wasted more than that on the file manager, waiting for the screen to come out of its seeming daze and finally show that the movement of several files has finally been accomplished.



The formatting above was taken from other examples I found at various times. I tried to adapt my problem to someone else's solution.



So, the question is: How do I format the 245000 lines (using nano texteditor which has a find/replace without having to add some additional software to gedit) and get it into a file which can be invoked by whatever command so that Ubuntu doesn't give me "TOO MANY ARGUMENTS" and die. It will submit each line as a command, and when it's done, it will execute the next line and so on until it's finished.










share|improve this question























  • I don't quite understand what you're trying to do. Are you trying to move all the files from the recup_dir folders into the centralized folder? Which ones, if any, are you trying to filter out?
    – dsstorefile1
    Feb 28 at 0:36










  • I'm skipping what you are trying to do (why not mv with globbing? (f3442*), but with your scripts, did you make them executable (chmod +x) and you might want to try giving a path bash ./newlist.txt (so it finds it in your current directory; assuming you $PWD isn't in path)
    – guiverc
    Feb 28 at 0:38















up vote
0
down vote

favorite












Problem: 245,000 plus files residing in multiple recup_dir folders (output from photo_rec run) needing to be moved to a centralized folder for further recovery operations. All files are *.jpg files.



I have a text file named newlist1.txt that I have formatted in the following 4 ways. And to change to each variety, a good find/replace editor is essential. these script files are in a folder /disks/Keep/new-s1-recov. I know, I could have used just . to indicate where to mv the files, but initially, the scripts were in another folder, and the period would not have sufficed.



  1. echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov


  2. echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov


  3. echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


  4. ls recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


the last two examples, 3 & 4, work correctly when executed from the command line.
None of the examples work when I type



sh newlist1.txt


or



bash newlist1.txt


The thing is, I have over 245000 files that need to be moved. Why don't I use the file manager and do groups of several hundred at a time? Because the file manager is possibly the worst piece of software in Ubuntu 16.04.3. So, the command line is the preferable way of accomplishing this task. If I spend several days figuring out how to get it done like this, I'll consider it time well spent. I have wasted more than that on the file manager, waiting for the screen to come out of its seeming daze and finally show that the movement of several files has finally been accomplished.



The formatting above was taken from other examples I found at various times. I tried to adapt my problem to someone else's solution.



So, the question is: How do I format the 245000 lines (using nano texteditor which has a find/replace without having to add some additional software to gedit) and get it into a file which can be invoked by whatever command so that Ubuntu doesn't give me "TOO MANY ARGUMENTS" and die. It will submit each line as a command, and when it's done, it will execute the next line and so on until it's finished.










share|improve this question























  • I don't quite understand what you're trying to do. Are you trying to move all the files from the recup_dir folders into the centralized folder? Which ones, if any, are you trying to filter out?
    – dsstorefile1
    Feb 28 at 0:36










  • I'm skipping what you are trying to do (why not mv with globbing? (f3442*), but with your scripts, did you make them executable (chmod +x) and you might want to try giving a path bash ./newlist.txt (so it finds it in your current directory; assuming you $PWD isn't in path)
    – guiverc
    Feb 28 at 0:38













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Problem: 245,000 plus files residing in multiple recup_dir folders (output from photo_rec run) needing to be moved to a centralized folder for further recovery operations. All files are *.jpg files.



I have a text file named newlist1.txt that I have formatted in the following 4 ways. And to change to each variety, a good find/replace editor is essential. these script files are in a folder /disks/Keep/new-s1-recov. I know, I could have used just . to indicate where to mv the files, but initially, the scripts were in another folder, and the period would not have sufficed.



  1. echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov


  2. echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov


  3. echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


  4. ls recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


the last two examples, 3 & 4, work correctly when executed from the command line.
None of the examples work when I type



sh newlist1.txt


or



bash newlist1.txt


The thing is, I have over 245000 files that need to be moved. Why don't I use the file manager and do groups of several hundred at a time? Because the file manager is possibly the worst piece of software in Ubuntu 16.04.3. So, the command line is the preferable way of accomplishing this task. If I spend several days figuring out how to get it done like this, I'll consider it time well spent. I have wasted more than that on the file manager, waiting for the screen to come out of its seeming daze and finally show that the movement of several files has finally been accomplished.



The formatting above was taken from other examples I found at various times. I tried to adapt my problem to someone else's solution.



So, the question is: How do I format the 245000 lines (using nano texteditor which has a find/replace without having to add some additional software to gedit) and get it into a file which can be invoked by whatever command so that Ubuntu doesn't give me "TOO MANY ARGUMENTS" and die. It will submit each line as a command, and when it's done, it will execute the next line and so on until it's finished.










share|improve this question















Problem: 245,000 plus files residing in multiple recup_dir folders (output from photo_rec run) needing to be moved to a centralized folder for further recovery operations. All files are *.jpg files.



I have a text file named newlist1.txt that I have formatted in the following 4 ways. And to change to each variety, a good find/replace editor is essential. these script files are in a folder /disks/Keep/new-s1-recov. I know, I could have used just . to indicate where to mv the files, but initially, the scripts were in another folder, and the period would not have sufficed.



  1. echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov


  2. echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov


  3. echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


  4. ls recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov


the last two examples, 3 & 4, work correctly when executed from the command line.
None of the examples work when I type



sh newlist1.txt


or



bash newlist1.txt


The thing is, I have over 245000 files that need to be moved. Why don't I use the file manager and do groups of several hundred at a time? Because the file manager is possibly the worst piece of software in Ubuntu 16.04.3. So, the command line is the preferable way of accomplishing this task. If I spend several days figuring out how to get it done like this, I'll consider it time well spent. I have wasted more than that on the file manager, waiting for the screen to come out of its seeming daze and finally show that the movement of several files has finally been accomplished.



The formatting above was taken from other examples I found at various times. I tried to adapt my problem to someone else's solution.



So, the question is: How do I format the 245000 lines (using nano texteditor which has a find/replace without having to add some additional software to gedit) and get it into a file which can be invoked by whatever command so that Ubuntu doesn't give me "TOO MANY ARGUMENTS" and die. It will submit each line as a command, and when it's done, it will execute the next line and so on until it's finished.







command-line bash scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 28 at 1:02









muru

130k19274467




130k19274467










asked Feb 28 at 0:14









Hal Hackney

112




112











  • I don't quite understand what you're trying to do. Are you trying to move all the files from the recup_dir folders into the centralized folder? Which ones, if any, are you trying to filter out?
    – dsstorefile1
    Feb 28 at 0:36










  • I'm skipping what you are trying to do (why not mv with globbing? (f3442*), but with your scripts, did you make them executable (chmod +x) and you might want to try giving a path bash ./newlist.txt (so it finds it in your current directory; assuming you $PWD isn't in path)
    – guiverc
    Feb 28 at 0:38

















  • I don't quite understand what you're trying to do. Are you trying to move all the files from the recup_dir folders into the centralized folder? Which ones, if any, are you trying to filter out?
    – dsstorefile1
    Feb 28 at 0:36










  • I'm skipping what you are trying to do (why not mv with globbing? (f3442*), but with your scripts, did you make them executable (chmod +x) and you might want to try giving a path bash ./newlist.txt (so it finds it in your current directory; assuming you $PWD isn't in path)
    – guiverc
    Feb 28 at 0:38
















I don't quite understand what you're trying to do. Are you trying to move all the files from the recup_dir folders into the centralized folder? Which ones, if any, are you trying to filter out?
– dsstorefile1
Feb 28 at 0:36




I don't quite understand what you're trying to do. Are you trying to move all the files from the recup_dir folders into the centralized folder? Which ones, if any, are you trying to filter out?
– dsstorefile1
Feb 28 at 0:36












I'm skipping what you are trying to do (why not mv with globbing? (f3442*), but with your scripts, did you make them executable (chmod +x) and you might want to try giving a path bash ./newlist.txt (so it finds it in your current directory; assuming you $PWD isn't in path)
– guiverc
Feb 28 at 0:38





I'm skipping what you are trying to do (why not mv with globbing? (f3442*), but with your scripts, did you make them executable (chmod +x) and you might want to try giving a path bash ./newlist.txt (so it finds it in your current directory; assuming you $PWD isn't in path)
– guiverc
Feb 28 at 0:38











1 Answer
1






active

oldest

votes

















up vote
0
down vote













Since 245,000 filenames probably won't fit on a command line, use find and xargs (man find;man xargs), and do something like:



find recov1/ -type f -iname '*.jpg' -print0 | 
xargs -0 --no-run-if-empty mv -t /disks/Keep/new-s1-recov


I always use find ... -print0 and xargs -0 in case filenames contain blanks. You may have to use the xarg switches --max-args= or --max-chars= if xargs fails. You could also replace mv with echo mv for testing.






share|improve this answer




















  • Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
    – Hal Hackney
    Mar 1 at 18:10










  • Thanks also to @guiverc.
    – Hal Hackney
    Mar 1 at 18:11










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1010454%2fhow-to-invoke-a-text-file-as-a-list-of-commands%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Since 245,000 filenames probably won't fit on a command line, use find and xargs (man find;man xargs), and do something like:



find recov1/ -type f -iname '*.jpg' -print0 | 
xargs -0 --no-run-if-empty mv -t /disks/Keep/new-s1-recov


I always use find ... -print0 and xargs -0 in case filenames contain blanks. You may have to use the xarg switches --max-args= or --max-chars= if xargs fails. You could also replace mv with echo mv for testing.






share|improve this answer




















  • Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
    – Hal Hackney
    Mar 1 at 18:10










  • Thanks also to @guiverc.
    – Hal Hackney
    Mar 1 at 18:11














up vote
0
down vote













Since 245,000 filenames probably won't fit on a command line, use find and xargs (man find;man xargs), and do something like:



find recov1/ -type f -iname '*.jpg' -print0 | 
xargs -0 --no-run-if-empty mv -t /disks/Keep/new-s1-recov


I always use find ... -print0 and xargs -0 in case filenames contain blanks. You may have to use the xarg switches --max-args= or --max-chars= if xargs fails. You could also replace mv with echo mv for testing.






share|improve this answer




















  • Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
    – Hal Hackney
    Mar 1 at 18:10










  • Thanks also to @guiverc.
    – Hal Hackney
    Mar 1 at 18:11












up vote
0
down vote










up vote
0
down vote









Since 245,000 filenames probably won't fit on a command line, use find and xargs (man find;man xargs), and do something like:



find recov1/ -type f -iname '*.jpg' -print0 | 
xargs -0 --no-run-if-empty mv -t /disks/Keep/new-s1-recov


I always use find ... -print0 and xargs -0 in case filenames contain blanks. You may have to use the xarg switches --max-args= or --max-chars= if xargs fails. You could also replace mv with echo mv for testing.






share|improve this answer












Since 245,000 filenames probably won't fit on a command line, use find and xargs (man find;man xargs), and do something like:



find recov1/ -type f -iname '*.jpg' -print0 | 
xargs -0 --no-run-if-empty mv -t /disks/Keep/new-s1-recov


I always use find ... -print0 and xargs -0 in case filenames contain blanks. You may have to use the xarg switches --max-args= or --max-chars= if xargs fails. You could also replace mv with echo mv for testing.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 28 at 2:42









waltinator

20.7k74168




20.7k74168











  • Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
    – Hal Hackney
    Mar 1 at 18:10










  • Thanks also to @guiverc.
    – Hal Hackney
    Mar 1 at 18:11
















  • Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
    – Hal Hackney
    Mar 1 at 18:10










  • Thanks also to @guiverc.
    – Hal Hackney
    Mar 1 at 18:11















Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
– Hal Hackney
Mar 1 at 18:10




Thanks to @waltinator. My dumb!, forgot the +x. But Waltinator, I used your example and only needed to type it on the command line once. None of my file names had spaces in them and I was only searching for .jpg files. So the line was pretty long, but one line did the trick. Problem solved. Thanks again.
– Hal Hackney
Mar 1 at 18:10












Thanks also to @guiverc.
– Hal Hackney
Mar 1 at 18:11




Thanks also to @guiverc.
– Hal Hackney
Mar 1 at 18:11

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1010454%2fhow-to-invoke-a-text-file-as-a-list-of-commands%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491