Home > Blockchain >  Create file from output on single line
Create file from output on single line

Time:02-13

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:

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

CodePudding user response:

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
  • Related