How to invoke a text file as a list of commands
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
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.
echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov
echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov
echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov
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
add a comment |Â
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.
echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov
echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov
echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov
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
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 pathbash ./newlist.txt
(so it finds it in your current directory; assuming you $PWD isn't in path)
â guiverc
Feb 28 at 0:38
add a comment |Â
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.
echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov
echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov
echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov
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
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.
echo !(recov1/recup_dir.1033/f340010.jpg)| xargs mv -t /disks/Keep/new-s1-recov
echo !recov1/recup_dir.1034/f3442050jpg| xargs mv -t /disks/Keep/new-s1-recov
echo recov1/recup_dir.1034/f344208.jpg| xargs mv -t /disks/Keep/new-s1-recov
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
command-line bash scripts
edited Feb 28 at 1:02
muru
130k19274467
130k19274467
asked Feb 28 at 0:14
![](https://lh4.googleusercontent.com/-FGyZKaaBQiA/AAAAAAAAAAI/AAAAAAAAAB8/8rub1u4IjhY/photo.jpg?sz=32)
![](https://lh4.googleusercontent.com/-FGyZKaaBQiA/AAAAAAAAAAI/AAAAAAAAAB8/8rub1u4IjhY/photo.jpg?sz=32)
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 pathbash ./newlist.txt
(so it finds it in your current directory; assuming you $PWD isn't in path)
â guiverc
Feb 28 at 0:38
add a comment |Â
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 pathbash ./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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 pathbash ./newlist.txt
(so it finds it in your current directory; assuming you $PWD isn't in path)â guiverc
Feb 28 at 0:38