Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine output of two command in unix system

I need to combine output of two commands.

For example:

If I input ls -l && file * it will give me

-rw-rw-r-- 1 user user 1356 2012-01-21 07:45 string.c
-rwxrwxr-x 1 user user 7298 2012-01-21 07:32 string_out
-rw-rw-r-- 1 user user  777 2012-01-18 21:44 test

string.c:   ASCII C program text, with CRLF line terminators
string_out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
test:       POSIX shell script text executable

but what I want is:

-rw-rw-r-- 1 user user 1356 2012-01-21 07:45 string.c string.c:   ASCII C program text, with CRLF line terminators
-rwxrwxr-x 1 user user 7298 2012-01-21 07:32 string_out string_out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
-rw-rw-r-- 1 user user  777 2012-01-18 21:44 test test:       POSIX shell script text executable

Any suggestions how to do this?

like image 397
4d4c Avatar asked Jan 21 '12 19:01

4d4c


People also ask

How do I add two commands in Linux?

Linux allows you to enter multiple commands at one time. The only requirement is that you separate the commands with a semicolon. Running the combination of commands creates the directory and moves the file in one line.

Can 2 commands be used simultaneously in UNIX?

On Linux, there are three ways to run multiple commands in a terminal: The Semicolon (;) operator. The Logical OR (||) operator. The Logical AND (&&) operator.

How do you combine two commands in UNIX?

Concatenate Commands With “&&“ The “&&” or AND operator executes the second command only if the preceding command succeeds.


1 Answers

paste is your friend here. Using bash process substitution:

paste <(ls -l | sed 1d) <(file *)

edit: added sed command to delete first line of ls output ("total: xx")

like image 137
glenn jackman Avatar answered Oct 24 '22 22:10

glenn jackman