Ls-command question
Example: ls -m on the map fujifilm110 gives me:
DSCF1457.JPG, DSCF1458.JPG, DSCF1459.JPG, DSCF1460.JPG, DSCF1461.JPG, DSCF1462.JPG, DSCF1463.JPG, DSCF1464.JPG, DSCF1465.JPG, DSCF1466.JPG, DSCF1467.JPG, DSCF1468.JPG, DSCF1469.JPG, DSCF1470.JPG, DSCF1472.JPG, DSCF1473.JPG, DSCF1474_a.JPG, DSCF1474.JPG, DSCF1475.JPG, DSCF1476.JPG, DSCF1477_a.JPG, DSCF1477.JPG, DSCF1478.JPG, DSCF1479.JPG, DSCF1489.JPG, DSCF1490.JPG, DSCF1491.JPG, DSCF1492.JPG, DSCF1494.JPG, DSCF1495.JPG, DSCF1496.JPG, DSCF1497_a.JPG, DSCF1497.JPG, DSCF1501.JPG, DSCF1502.JPG, DSCF1503.JPG, DSCF1504.JPG, DSCF1505.JPG Question: Can I get an output of ls equal to this one but without the commas? This comes in handy when I want to apply one command to many files at once (but not an entire directory). It is a recurring irritation to me. |
Pass that output through sed...
Code:
ls -m fujifilm110 | sed 's/,//g' I have taken a guess at your directory name too, adjust to your uses. |
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? |
Probably better to use find with the -exec option, rather than piping output from ls.
|
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. |
Quote:
man find, and look at the exec option. You might also want to look at xargs for some use cases as well. |
Okay, thank you for your answers. I will look into it.
|
This looks promising.
Folder contents: Code:
~/test$ ls Code:
~/test$ echo $(ls | grep .jpg$) |
Quote:
e.g. in a script Code:
#!/bin/bash Code:
for i in *; do sudo chmod 700 $i; done |
I just created a bunch of files, some with '.JPG' and just did
Code:
chmod 600 *.JPG 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) |
My question was about listing all the files in a specific order (one space in between).
Not how to apply the chmod-command to a large amount of files. |
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 if you need this output in a file, feel free to redirect output to wherever needed. |
*.JPG (or *.jpg) will list those files. and you can do a chmod or whatever command using this syntax. but why do you need a specific order?
|
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. |
All times are GMT -5. The time now is 05:39 AM. |