Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create file from output on single line

I am currently stuck on a question which asks:

A ‘file’ in the /proc directory contains information about the processor. Use commands to search this file for information about the processor cache, and save the output in a file cache.txt

I have managed to get to the output part but cannot get the output to save to a file. Here is my sample code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cat /proc/cpuinfo | grep -i 'cache' 

This display the desired output on the terminal

cat /proc/cpuinfo | grep -i 'cache' > cache.txt

This is my modified command to save the output to a file called cache.txt but it says the file is not there. My only thoughts could be as I am running the command from inside /proc, do I need to specify the file path for the file cache.txt I want to create?

Sample code:

/proc $ cat /proc/cpuinfo | grep -i cache > cache.txt
bash: cache.txt: No such file or directory

>Solution :

You’re doing it in /proc directory which is a virtual filesystem,
you cannot create new files in it. You have to save output cache.txt
in a different directory. For example, to save it in your home
directory type cd with no arguments and then do:

grep -i cache /proc/cpuinfo > cache.txt

cache.txt will look like that:

$ cat cache.txt
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
cache size      : 8192 KB
cache_alignment : 64
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading