0

This question already has an answer here:

ls /proc/
1      10984  11246  131    144    167    2099   31788  4805  5375  6762  7594  8111  8722       consoles
10     10993  11247  1314   14400  168    21     32     4807  5379  6771  76    8112  8738       cpuinfo
100    10998  11248  13163  14403  169    210    32408  4818  5386  6788  7601  8113  8752       crypto
101    11     11249  132    14404  17     211    33     4831  5388  68    7619  8114  8768       devices
102    110    11251  133    14405  170    2111   34     4833  54    6808  7625  8115  8789       diskstats
10202  11012  11252  134    14406  1726   2115   3489   4846  5417  6827  7626  8116  88         dma
cat /proc/10993/root/run_command
/usr/sbin/libvirtd --listen(nova-libvirt)

and I want to get all PID run_command

cd /proc
cat */root/run_command
/etc/barbican/vassals --logto /var/log/kolla/barbican/barbican-api.loguwsgi --master --emperor /etc/barbican/vassals --logto /var/log/kolla/barbican/barbican-api.loguwsgi --master --emperor /etc/barbican/vassals --logto /var/log/kolla/barbican/barbican-api.log/opt/kibana/bin/kibanabarbican-keystone-listenerbarbican-keystone-listenerheat-api-cfnheat-api-cfnneutron-dhcp-agent --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/dhcp_agent.inimistral-server --server executor --config-file /etc/mistral/mistral.confneutron-dhcp-agent --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/dhcp_agent.inimistral-server --server executor --config-file /etc/mistral/mistral.conf/usr/sbin/sshd -Dtacker-server --config-file /etc/tacker/tacker.conf/usr/sbin/sshd -Dtacker-server --config-file /etc/tacker/tacker.conf/usr/sbin/apache2/usr/sbin/td-agent/usr/bin/mysqld_safeglance-registry/usr/sbin/apache2start-ovsdb-server 127.0.0.1/usr/bin/mysqld_safeglance-registrynova-apistart-ovsdb-server 127.0.0.1nova-consoleauthnova-api/usr/sbin/libvirtd --listennova-consoleauth/usr/bin/memcached -v -l 10.60.6.174 -p 11211 -c 5000 -U 0/usr/bin/memcached -v -l 10.60.6.174 -p 11211 -c 5000 -U 0/usr/sbin/libvirtd --listenneutron-metadata-agent --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/metadata_agent.ini/usr/sbin/libvirtd --listenmistral-server --server engine --config-file /etc/mistral/mistral.confneutron-metadata-agent --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/metadata_agent.inimistral-server --server engine --config-file /etc/mistral/mistral.confstart-ovsdb-server 127.0.0.1/usr/share/elasticsearch/bin/elasticsearchsleep infinity/usr/share/elasticsearch/bin/elasticsearchbarbican-workersleep infinitynova-conductorbarbican-worker/opt/kafka/bin/kafka-server-start.sh /etc/kafka/kafka.server.propertiesnova-compute/usr/sbin/libvirtd --listen/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2/usr/sbin/apache2no ...

but it's too messy to read. How do I put each record (content of each file) on a separate line?

run_comand_content1
run_comand_content2
run_comand_content3

or

run_comand_content1

run_comand_content2

run_comand_content3

marked as duplicate by Sparhawk, G-Man, Mr Shunz, Christopher, roaima Jan 22 at 16:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Can do wrap? is not a very clear description of how the output should look .... a simple wrap is also "messy" – jsotola Jan 22 at 2:22
  • sorry, I add the description. – bohan Chen Jan 22 at 3:29
3

You could put it in a loop:

for i in /proc/[0-9]* 
do
    printf "${i}\t"
    cat ${i}/root/run_command
    printf "\n" 
done
0

You can use awk:

awk 'FNR==1{printf ""}1' */root/run_command

or separate by --- or new line:

awk 'FNR==1{print "---"}1' */root/run_command
awk 'FNR==1{printf "\n"}1' */root/run_command

See here for more answers, e.g. using sed:

sed -e '$s/$/\n/' -s */root/run_command

Not the answer you're looking for? Browse other questions tagged or ask your own question.