Skip to content
Advertisement

how to send output of ‘ls-l’ to cp command using pipes?

i want to copy the output of ls -l command into a file say “xyz”. i know i have to take the output of ls -l and then send it to cp command using pipe i.e output of ls-l will be used as an input for cp command

$ls-l

-rw-r--r-- 1 1030082 oinstall  167 Mar 27 10:36 
-rw-r--r-- 1 1030082 oinstall  167 Mar 27 10:36 a1
-rw-r--r-- 1 1030082 oinstall  103 Mar 27 12:40 a2
-rw-r--r-- 1 1030082 oinstall   30 Mar 27 12:43 a3
-rw-r--r-- 1 1030082 oinstall   21 Mar 27 13:47 a4 
drwxr-xr-x 3 1030082 oinstall 4096 Mar 27 16:54 dir1
-rw-r--r-- 1 1030082 oinstall   94 Mar 27 13:53 unix
-rw-r--r-- 1 1030082 oinstall  105 Mar 27 10:33 xyz

Advertisement

Answer

Output to file “test.txt”:

ls -l > text.txt

Sumary of pipes:

  • > Save output to a file.

  • >> Append output to a file.

  • < Read input from a file.

  • 2> Redirect error messages.

  • | Send the output from one program as input to another program.

Advertisement