Use accsupp package. This way you can copy regarless of visual line breaks.
\documentclass{article}
\usepackage{accsupp}
\usepackage{listings}
\begin{document}
\BeginAccSupp{method=plain,ActualText=long long long command long long long command long long long command long long long command}
\begin{lstlisting}[breaklines=true]
long long long command long long long command long long long command long long long command
\end{lstlisting}
\EndAccSupp{}
\end{document}
If the code includes special characters you need something more fancy (method=pdfstringdef and hyperref):
\documentclass{article}
\usepackage[pdfencoding=auto]{hyperref}
\usepackage{accsupp}
\usepackage{listings}
\begin{document}
\BeginAccSupp{method=pdfstringdef,ActualText=
grep -rw --include \unichar{"005C}*.h --include \unichar{"005C}*e.c* "Write()" . |sed -e 's/Write/Read/g'}
\begin{lstlisting}[breaklines=true]
grep -rw --include \*.h --include \*e.c* "Write()" . |sed -e 's/Write/Read/g'
\end{lstlisting}
\EndAccSupp{}
\end{document}
accsup– alfC Aug 19 '15 at 20:55accsuppmight be reader-dependent. – Werner Aug 19 '15 at 21:04listingsusage will give different copy behavior. In my Evince the copied code includes random spaces (I need to useaccsupto make it behave the same in Acrobat and Evince, even if I don't mind the line breaks). – alfC Aug 19 '15 at 22:57