[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

Concatenate two output in the same line

Hi,  I'd know how  concatenate two output in the same line. And then save to file.
 eg:
$:  ls  || pwd > file.txt
0
mauriff
Asked:
mauriff
  • 4
  • 3
1 Solution
 
agriesserCommented:
(ls || pwd) >file.txt

0
 
mauriffAuthor Commented:
mm.. I want make an file with string concatenate.Eg.
I run "rm -f " locate blabla.bin > rm.txt
and i want the output should be:

rm - rf /etv/bin/blabla.bin
rm - rf /home/audyt/blabla.bin
rm - rf /home/lib/blabla.bin

Is clear?
0
 
agriesserCommented:
No, it's not clear. I'm having a hard time in understanding you, but I try to answer the question in three manners.

First variant: You want to have a file that contains the commands "rm -rf *blabla.bin* listed in it", you can do that using code snippet part 1.

Second variant: Like variant #1, but the output is printed to the console instead of into a file.

Third variant: You want to execute rm -rf *blabla.bin* immediately, but with all the files matching your search query all over the filesystem.


# variant #1
for file in $(locate blabla.bin); do echo "rm -rf $file"; done
 
# variant #2
for file in $(locate blabla.bin); do echo "rm -rf $file" >>/path/to/output-file.txt; done
 
# variant #3
# !!!!! very dangerous if the you make a typo in the keyword to use !!!!!
# !!!!! could delete all the data on your disk without further interaction !!!!!
locate blabla.bin | xargs rm -rf

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
mauriffAuthor Commented:
Thanks! It's just I want run!!

(Sorry for my english, I'm basic level  in this language)
0
 
agriesserCommented:
So you took what variant? #3 I guess, right?
0
 
mauriffAuthor Commented:
yes!
0
 
agriesserCommented:
OK, but _PLEASE_ be careful using this command. If you mistype the search string for the locate command you can easily erase data on your hard disk.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now