Hi,
I need to copy all files from this statement to another folder:
ls �l ./apps | grep �E �^l|^v�
How can i do that?
best regards!
Hi,
I need to copy all files from this statement to another folder:
ls �l ./apps | grep �E �^l|^v�
How can i do that?
best regards!
ls -l ./apps | grep -E �^l|^v� | awk '{ print $NF }' | xargs cp {} destination_folder_path
thank you that nearly works.
The only problem now is that he tries to copy he says the file i want to copy is a directory?
best regards
Why do you need either ls or grep for that?
cp apps/[lv]* /some/new/dir 2>/dev/null
That won't work on files with spaces in the names, but that aside, you could just throw the "errors" away:
$ ls -l ...... 2> /dev/null
(and, incidentally, what ls -l output begins with a v?, and how can an ls -l output grepping for l return a directory - or anything but a symbolic link, for that?)
This command sequence looks unlikely to produce any output. I can't think of a circumstance where lines output by "ls -l" would start with character "v" ... and those starting with character "l" would be links. Also the type of quotes is wrong - looks like they have come from a Windows word processor.
What are you trying to do?
Can you post a sample "ls -l" and somehow show which files you are trying to copy and to where.
this just prints out all names of files within the folder apps which start either with an v or an l.
so i have the names of the files i want to copy now. and now i just need to copy the files with that names to another folder.
beste regards
No it doesn't!
ls -l will produce a long listing.
If all you want is filenames, why use ls or grep at all?
I undeleted my earlier-deleted post (#4).
See also useless use of ls. The shell's perfectly capable of creating its own lists of files without ls | grep | awk | sed | millions | of | waseful | pipes.
When you have ls | stuff
You can just do
for FILE in *
do
...
done
to do it all in one step, avoiding running ls and grep at all.
There is a situation where you might want ls though -- when there's millions of files. In that case there might be too many to fit into *. In that case you would need to do something like
ls | while read FILENAME
do
...
done
Again, as scottn says, the "-l" is pointless when you're not using the long listing: Just do ls by itself into a pipe and it will list the exact same files, one per line, without all the garbage that'd otherwise trouble you.