简体   繁体   中英

I'm trying to use grep command

I'm new to Linux so it may sound silly.

I'm trying to execute a command

sudo arp-scan -l | grep DEVICEMACADDRESS
  1. where does the output of this command gets saved. ? ?
  2. How I can append time once the given mac address is found. ? ?

Thank you.

Ad 1: Grep by default prints output to STDOUT (standart output), which is, in your case, terminal.

If you want to save the output to the file, use output redirection:

some command > file #this will write file anew (any file will be overwritten)
another command >> file #this will append to file, (file will be created, if doesn't exist)

If you want to save the output to variable, use following syntax:

NAMEOFVARINUPPERCASE=$(whole command)

Please note there are NO spaces around =. Also note, that this variable is available only to current terminal session. However, you can always export it, or save it to file.

Ad 2:

Use following syntax:

(command_to_find_mac && echo $(date)) >> file

where does the output of this command gets saved. ? ?

Ans: Your just piping here this will direct to STD_OUT that is your terminal in this case.

If you want to save redirect this to file.

How I can append time once the given mac address is found. ? ?

Ans: just use this while redirecting to file, echo $(date) .

for example :

ls  | echo $(date)
tor 13 apr 2017 10:30:02 CEST

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM