Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, I'm new to linux and didn't know about the -m option. However, without the '-m' you will not get the commas. Is that ok, or maybe I am misunderstanding.
Okay, but that produces too much space between the files. Let's say I want to apply the command sudo chmod 700 to all the files, the files must become one single line with exactly one space between the files.
That can be done in a text-browser of course, but is there a way on the commandline?
Man, it's so late and I was bored, waiting for something to compile. Meanwhile I made a test directry, added a couple of files and experimented with commands like:
ls | mv /* /.* ..whatever, without realising I was in the root directory! Almost made a very big disaster.
Okay, but that produces too much space between the files. Let's say I want to apply the command sudo chmod 700 to all the files, the files must become one single line with exactly one space between the files.
That can be done in a text-browser of course, but is there a way on the commandline?
As descendant_command says, find is probably your best option for that use case.
man find, and look at the exec option. You might also want to look at xargs for some use cases as well.
Okay, but that produces too much space between the files. Let's say I want to apply the command sudo chmod 700 to all the files, the files must become one single line with exactly one space between the files.
That can be done in a text-browser of course, but is there a way on the commandline?
Maybe there is a reason I don't see ATM, but why don't you go with the classic for loop to handle one file after the other??
I just created a bunch of files, some with '.JPG' and just did
Code:
chmod 600 *.JPG
worked a treat, no need for ls or anything else ....
I'd also say that even if DO you need to pipe the list into another cmd, *nix doesn't care about the num of spaces between the filenames (filenames containing spaces are a special case)
wenn, the example you gace was to use this file list with a command like chmod, hence our minds started working this direction. It should be easy enough to substitute the actual commands.
If you just want to put them out on screen you could start with my 1line from above in a way like
Code:
for i in *; do echo -n $i; echo -n " "; done; echo
this reads out all the files specified and prints them on screen, add another space in between and does a "carriags return" or "newline" and the end.
if you need this output in a file, feel free to redirect output to wherever needed.
My mistake, pan64. What I meant is one space in between. E.g.: how to move many files of a directory to another directory.
So: sudo mv file1 file2 file3 file4 file5 file6 ~/images/wallpapers/shared.
What you can do is open nano or vim or even geany. Then to take the ouput of ls -m and remove the "," and make it one line. Then to copy/paste it after the command. Done. That is how I have done it all this time.
My question was: can you use the ls-command in such a way that you don't have to use an editor. Using the grep-command will do the trick.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.