2

I have done a listing of the device folder two times, one time without the sd-card in the slot and one time inserted, the system automatically adds one file in the device folder.

$ ls /dev | wc -l
205
$ ls /dev | wc -l
206

I could put each listing into a separate file: ls /dev > foo. But how can I determine from this point the device file that was added?

1

You could run this before adding the device to store the inital list in a file:

ls /dev >~/a

And then this after adding the device:

ls /dev | diff -u ~/a -

This should show you in what way the two lists of files differ. diff shows the differences between two text files, and flag -u changes its output format: lines added will be prefixed with a + sign. For example, if you get the following output (I omitted the diff header):

 sdc
 sdd
 sde
+sdf
 sg0
 sg1
 sg2

then it means that the new device that got created is /dev/sdf.

You can then delete the temporary file ~/a.

Another way to get the information you are looking for would be to tail -f /var/log/messages: you should see kernel messages mentioning the new device's appearance and disappearance.

  • a is here just another name for the file like foo, right ? – Abdul Al Hazred Mar 20 '15 at 18:53
  • Yes, you can call the file anything you like, as long as you use the same name in both commands. – dhag Mar 20 '15 at 19:00
  • I do not understand this diff command and the -u option at all, but I opened a new question about it. – Abdul Al Hazred Mar 20 '15 at 19:02
  • I will edit my answer to explain this use of diff. – dhag Mar 20 '15 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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