✓ Solved

Shell script question

Anyone out there in Linode-land know of a (semi-)foolproof way of determining whether a path is a device file or not? For example:

  • /dev/sda is a device file; and
  • /var/tmp is not a device file.

Socket files (e.g., /var/run/php-fpm.sock) are not device files.

TIA,

-- sw

1 Reply

✓ Best Answer

Never mind… I think I found the answer. From man test (Doh!):

     -b file       True if file exists and is a block special file.

     -c file       True if file exists and is a character special file.

The devices I'm interested in are all character-special files (SATA/USB drives)… I'm working on unifying two shell scripts that do backups -- one to files on USB drives (home use) and the other to files on Linode block storage (Linode use)…so I only have to maintain one.

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct