PDA

View Full Version : Understanding /dev/null



spacexdragon
2021-08-29, 15:10
I am a beginner with Kali Linux and am learning with a textbook. I have written the following shell script:


#! /bin/bash

# This script is designed to find hosts with Postgres installed

nmap -sT my_IP_address -p 5432 >/dev/null -oG MyPostgresScan

cat MyPostgresScan | grep open > MyPostgresScan2

cat MyPostgresScan2

I try to understand what >/dev/null does. I assumed that the standard nmap output is sent to /dev/null and from what I have learned, this is a place in Linux where output disappears.

When I run my shell script I can see that there are two files written to my pwd: MyPostgresScan and MyPostgresScan2. I expected MyPostgresScan not to be in my pwd. The second file is expected to be there.

Can someone explain me why the file MyPostgresScan is written to my pwd?

Borlog
2021-09-09, 12:36
You can use it to suppress the output in a shell.

for example:

echo "I am not displayed because I am suppressed!" > /dev/null

This is often used when scripting to suppress an output that is not needed.

Hope this helps you!

niamul21
2021-10-26, 17:09
I am a beginner with Kali Linux and am learning with a textbook. I have written the following shell script:


#! /bin/bash

# This script is designed to find hosts with Postgres installed

nmap -sT my_IP_address -p 5432 >/dev/null -oG MyPostgresScan

cat MyPostgresScan | grep open > MyPostgresScan2

cat MyPostgresScan2

I try to understand what >/dev/null does. I assumed that the standard nmap output is sent to /dev/null and from what I have learned, this is a place in Linux where output disappears.

When I run my shell script I can see that there are two files written to my pwd: MyPostgresScan and MyPostgresScan2. I expected MyPostgresScan not to be in my pwd. The second file is expected to be there.

Can someone explain me why the file MyPostgresScan is written to my pwd?

You can go through it.