Behaviour of echo commands used by Linux admins

version info : Fedora 28 (Kernel version: 4.16.12-300)
shell : bash

Using echo command , if I redirect a text like "Chocolate" to a file , all the contents in the file are overwritten as shown below.

[root@john215 ~]# cat /tmp/someTest 
Hello world 
One more Hello world 
myLine3 
 
[root@john215 ~]# echo Chocolate > /tmp/someTest 
[root@john215 ~]# cat /tmp/someTest 
Chocolate 
[root@john215 ~]# file /tmp/someTest 
/tmp/someTest: ASCII text 
 

But, I have seen Linux system admins using echo commands like below to scan for new LUNs.

Why is " /sys/class/scsi_host/host1/scan " file not being overwritten with "- - -" or "1" by the echo commands below ?

 
# echo "1" > /sys/class/fc_host/host/issue_lip 
# echo "- - -" > /sys/class/scsi_host/host1/scan 

Source:

1.8. Scanning Storage Interconnects - Red Hat Customer Portal

# file /sys/class/scsi_host/host1/scan 
/sys/class/scsi_host/host1/scan: writable, regular file, no read permission

This is due sysfs being pseudo filesystem, as procfs is as well.

It's actually an interface from kernel space to user space which allows you to manipulate various options regarding your hardware or operating system values.
Options such as fibre rescan, ip4 forwarding etc are all controlled by user using those pseudo file systems.
A lot of those options have real backed configuration files (such as /etc/sysctl.conf) which will apply those on boot.

That file system is created after system is booted (or on request) and populated with your device files.
For instance, if you add additional fibre card, a sysfs will be populated with additional hierarchy for that card.

An actual echo command is predetermined, if you issue anything else error will be written.

Take the following example from my PC at home :

root# echo "- - -" > /sys/class/scsi_host/host1/scan
root# tail -f  /var/log/messages
kernel: [ 6598.240883] ata2: hard resetting link
kernel: [ 6598.555362] ata2: SATA link down (SStatus 0 SControl 300)
kernel: [ 6598.555382] ata2: EH complete
root# echo "gibberish" > /sys/class/scsi_host/host1/scan
-su: echo: write error: Invalid argument

Hope that helps
Regards
Peasant.

2 Likes

Please cat those two sys files and post the output in reply.

Thanks.

Thank You very much Peasant.
Hi Leo
Will try cat those files when I reach home. If I remember correctly, i couldn't cat those files even as root.
file command's output from my above post says no read permission too.

@kralkic,
You may try below method.

Step 1 : In boot file you can add the option

radeon.runpm=0

in the call to the current kernel (usually after ro quiet splash).
Step 2 :

$echo OFF >/sys/kernel/debug/vgaswitcheroo/switch

Ref: https[://]codeflu[.]blog/2013/04/25/disabling-discrete-amd-graphics-card-in-linux/#comment-280