Skip to main content
added 64 characters in body
Source Link

watch by design updates the terminal. It "watch"es for changesan object, and displays themthe current version of that object (or changes to that object with -d). An example of where watch is useful, is if you wanted to monitor the temperature of the cpu you can open a new terminal, and run the below command, the output would update every 2 seconds with the temp recorded by the sensor.

watch -x cat /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon0/temp1_input

I am unsure why you would want to watch "ls -l" You could create a shell script that logs the output?

#!/bin/bash

while :
do 
   date +"%H:%M:%S" >> /var/log/ls.log
   ls -l >> /var/log/ls.log   
   sleep 2
done

if you are wanting to log new files, or modified files then:

 #!/bin/bash
    
    while :
    do 
       find -newer /var/log/ls.log >> /var/log/ls.log
       date +"%H:%M:%S" >> /var/log/ls.log  
       sleep 2
    done

You may want to increase the sleep time, I made it 2, as that is the default for watch.

The reason that the output is indented, and you can not see characters you type after the output, is due to your terminal not Bash.

Check your settings on your terminal program and also check termtype to ensure they match encoding (eg: utf8, ANSII etc) the terminal is only moving the cursor down a line (\n), and not resetting the cursor back to the start of the line (\r). This can also occur if the file was created in windows then moved to linux, or created in linux and moved to windows.

The characters you type are being displayed behind the last line of the output. Therefore you can not see it.

watch by design updates the terminal. It "watch"es for changes, and displays them. An example of where watch is useful, is if you wanted to monitor the temperature of the cpu you can open a new terminal, and run the below command, the output would update every 2 seconds with the temp recorded by the sensor.

watch -x cat /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon0/temp1_input

I am unsure why you would want to watch "ls -l" You could create a shell script that logs the output?

#!/bin/bash

while :
do 
   date +"%H:%M:%S" >> /var/log/ls.log
   ls -l >> /var/log/ls.log   
   sleep 2
done

if you are wanting to log new files, or modified files then:

 #!/bin/bash
    
    while :
    do 
       find -newer /var/log/ls.log >> /var/log/ls.log
       date +"%H:%M:%S" >> /var/log/ls.log  
       sleep 2
    done

You may want to increase the sleep time, I made it 2, as that is the default for watch.

The reason that the output is indented, and you can not see characters you type after the output, is due to your terminal not Bash.

Check your settings on your terminal program and also check termtype to ensure they match encoding (eg: utf8, ANSII etc) the terminal is only moving the cursor down a line (\n), and not resetting the cursor back to the start of the line (\r). This can also occur if the file was created in windows then moved to linux, or created in linux and moved to windows.

The characters you type are being displayed behind the last line of the output. Therefore you can not see it.

watch by design updates the terminal. It "watch"es an object, and displays the current version of that object (or changes to that object with -d). An example of where watch is useful, is if you wanted to monitor the temperature of the cpu you can open a new terminal, and run the below command, the output would update every 2 seconds with the temp recorded by the sensor.

watch -x cat /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon0/temp1_input

I am unsure why you would want to watch "ls -l" You could create a shell script that logs the output?

#!/bin/bash

while :
do 
   date +"%H:%M:%S" >> /var/log/ls.log
   ls -l >> /var/log/ls.log   
   sleep 2
done

if you are wanting to log new files, or modified files then:

 #!/bin/bash
    
    while :
    do 
       find -newer /var/log/ls.log >> /var/log/ls.log
       date +"%H:%M:%S" >> /var/log/ls.log  
       sleep 2
    done

You may want to increase the sleep time, I made it 2, as that is the default for watch.

The reason that the output is indented, and you can not see characters you type after the output, is due to your terminal not Bash.

Check your settings on your terminal program and also check termtype to ensure they match encoding (eg: utf8, ANSII etc) the terminal is only moving the cursor down a line (\n), and not resetting the cursor back to the start of the line (\r). This can also occur if the file was created in windows then moved to linux, or created in linux and moved to windows.

The characters you type are being displayed behind the last line of the output. Therefore you can not see it.

Source Link

watch by design updates the terminal. It "watch"es for changes, and displays them. An example of where watch is useful, is if you wanted to monitor the temperature of the cpu you can open a new terminal, and run the below command, the output would update every 2 seconds with the temp recorded by the sensor.

watch -x cat /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon0/temp1_input

I am unsure why you would want to watch "ls -l" You could create a shell script that logs the output?

#!/bin/bash

while :
do 
   date +"%H:%M:%S" >> /var/log/ls.log
   ls -l >> /var/log/ls.log   
   sleep 2
done

if you are wanting to log new files, or modified files then:

 #!/bin/bash
    
    while :
    do 
       find -newer /var/log/ls.log >> /var/log/ls.log
       date +"%H:%M:%S" >> /var/log/ls.log  
       sleep 2
    done

You may want to increase the sleep time, I made it 2, as that is the default for watch.

The reason that the output is indented, and you can not see characters you type after the output, is due to your terminal not Bash.

Check your settings on your terminal program and also check termtype to ensure they match encoding (eg: utf8, ANSII etc) the terminal is only moving the cursor down a line (\n), and not resetting the cursor back to the start of the line (\r). This can also occur if the file was created in windows then moved to linux, or created in linux and moved to windows.

The characters you type are being displayed behind the last line of the output. Therefore you can not see it.