LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-22-2023, 10:57 AM   #1
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Rep: Reputation: Disabled
One file of every type that is guaranteed to be in every distro?


Hello everyone! I was wondering if anyone could give me one filetype of EVERY type that is guaranteed to exist in EVERY Linux distro. I would like the path to be an absolute path if possible.

For regular files, I have used:
Code:
/lib/libc.so
For directory files, I have used:
Code:
/tmp
For system links, I have used:
Code:
/dev/fd
Now I want one Block, Character, Pipe and Socket file, and I'm good to go! Any ideas? Also, if you are not 100% sure that it is present in every single distro, but it's present in the most popular ones from what you know, it will be ok for now! I can do more research later! And well, someone may find and report it!

Thanks in advance!

EDIT:

Thank you everyone for your help! The final solution has been provided by @boughtonp in message #18! I wish you all to have an amazing day!

Last edited by rempas; 09-23-2023 at 08:04 AM. Reason: Solution message
 
Old 09-22-2023, 11:07 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,604

Rep: Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547

Why?

 
Old 09-22-2023, 11:11 AM   #3
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,498

Rep: Reputation: Disabled
Just run a distro 'live' & take a look - most general purpose distros will have basically the same....
 
Old 09-22-2023, 11:12 AM   #4
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
Does it matter? Well, I do write tests suits for my functions and I want to make sure that low level code works.
 
Old 09-22-2023, 11:39 AM   #5
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fatmac View Post
Just run a distro 'live' & take a look - most general purpose distros will have basically the same....
Good idea! I will run something minimal like Debian or Arch. Thank you and have a great day!
 
Old 09-22-2023, 11:43 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,604

Rep: Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547
Quote:
Originally Posted by rempas View Post
Does it matter?
As per the first example at that link: If file extensions were always three letters, it doesn't matter. When they're not, it matters.


Quote:
Well, I do write tests suits for my functions and I want to make sure that low level code works.
Tests should use controlled resources: i.e. ones you have explicitly created yourself for the purposes of the tests.

That's the best way to guarantee they will exist, even if someone arbitrarily decides to move/change a whole tree.

 
Old 09-22-2023, 12:25 PM   #7
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
As per the first example at that link: If file extensions were always three letters, it doesn't matter. When they're not, it matters.
Extensions does not matter. Extensions can be whatever (at least on Unix). When I talk about filetypes I mean about REAL filetypes. E.g. Regular files, Directory types, Block files, Links etc.

Of course, not anybody knows that, and I'm aware of that. I know the support would be limited, but it's still better than nothing, and I'm very grateful to anyone who wants to help!

Quote:
Originally Posted by boughtonp View Post
Tests should use controlled resources: i.e. ones you have explicitly created yourself for the purposes of the tests.

That's the best way to guarantee they will exist, even if someone arbitrarily decides to move/change a whole tree.
Thank you for the advice! Unfortunately, I cannot do that in that case as, I first need to make sure that the functions (if you don't know what's that, let's say a block of code that does a specific job) that check if a file exists and what type is it first work in order to create a file and then been able to make sure that the latter functions work. In other words, the latter functions depend on the first ones.
 
Old 09-22-2023, 01:06 PM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by rempas View Post
Block, Character
Surely you can come up with a /dev/ node for each of these yourself?

Give up on pipes and sockets; they're created as needed.

Last edited by dugan; 09-22-2023 at 01:07 PM.
 
Old 09-22-2023, 01:40 PM   #9
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Surely you can come up with a /dev/ node for each of these yourself?

Give up on pipes and sockets; they're created as needed.
I don't think that I'm getting through. I cannot "give up" on them or "come up" (I suppose you mean create them myself? If not, I'm sorry, but I don't understand) for them myself.

For my task, I want these files to be present in every (or at least, the most popular ones) disto by default. Sorry if I wasn't very clear in the original post.
 
Old 09-22-2023, 03:06 PM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Oh, so English is not your first language.

“Come up with” means “think of”.

To “give up on” something means to acknowledge that it’s impossible.

Neither means “create”.

Last edited by dugan; 09-22-2023 at 03:08 PM.
 
Old 09-22-2023, 03:06 PM   #11
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,604

Rep: Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547

Again, based on the limited explanation that you've given so far: you've got the wrong approach/mindset.

The point of unit tests is to be self-contained - that means stubbing/mocking external interfaces, so that a success or failure is dependent solely on the unit of functionality being tested.

If code needs to react differently when a path points to a directory or a regular file or a special file, don't rely on external paths, have a simple setup script that creates them.

If you try to depend on arbitrary locations external to your code, the code becomes brittle and will break when one of those locations either doesn't exist, or currently exists but later gets moved, or exists as a different type, or has unexpected permissions.

 
Old 09-22-2023, 03:29 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,714

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Block devices are typically some type of storage medium i.e. PATA, USB, SATA and SCSI drives are /dev/sdx but you also have NVMe technology so this is more hardware dependent then software. Blindly writing to a block device could corrupt the filesystem(s). To write to a filesystem or check if a file exists does not need block level access.

Standard on any linux distribution are character devices like /dev/null, /dev/random, /dev/zero or /dev/ttyX. You usually read from /dev/random but you can write as well.

pipes and sockets depend on the distribution, how it was configured at installation and what services are currently running. You can find pipes and sockets via the find command i.e.

find / -type s,p

If you try to write to an existing socket or pipe I would expect you would need to know the service communication protocol otherwise nothing is going to happen, you might not get a response or you might "crash" the service.

As posted your going about it the wrong way.
 
Old 09-23-2023, 03:27 AM   #13
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Oh, so English is not your first language.

“Come up with” means “think of”.

To “give up on” something means to acknowledge that it’s impossible.

Neither means “create”.
Oh, I understand, thank you for the explanation! Indeed, English is not my first language.

If what I want to do is impossible, then I'll go with plan B. I want to be sure that this is the case however before I proceed with that!

Thanks a lot for your time, I wish you to have a beautiful day!
 
Old 09-23-2023, 03:37 AM   #14
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
Again, based on the limited explanation that you've given so far: you've got the wrong approach/mindset.

The point of unit tests is to be self-contained - that means stubbing/mocking external interfaces, so that a success or failure is dependent solely on the unit of functionality being tested.

If code needs to react differently when a path points to a directory or a regular file or a special file, don't rely on external paths, have a simple setup script that creates them.

If you try to depend on arbitrary locations external to your code, the code becomes brittle and will break when one of those locations either doesn't exist, or currently exists but later gets moved, or exists as a different type, or has unexpected permissions.

I do understand your point and it is true. However, in my case, I NEED to depend on external files and there is no other way. I mean, as my functions will just be "system call", one could say that I don't even have to test them and that they'll always work and be stable (they'll never change in the future) but I don't want to go with that logic and I want to test them anyway. I first need to be able to check the type of file successfully, and then make sure that I can create the files with the given types that I want. So like I said, I cannot create the files first and then test their file type because I first need to make sure that the functions that check the file types work. For every other type of application, I wouldn't have to require to anything external but for this library, I have too...

The reason I asked for files that exists in every distro is, exactly, so my tests don't fail because these files doesn't exist in some distros. As for the case they are moved in the future, the test suit will be updated as needed! However, things like "lib/libc.so" and "/dev/fd" will probably never move, so I'm fine. But again, if they do, I can always update the test suit.

If you are a programmer (which, based on your knowledge about test-suits, I suppose you are), I can give you detailed information about what I'm trying to do (even give you a link to my repo if you are so much curious) if you are curious to know.
 
Old 09-23-2023, 03:42 AM   #15
rempas
Member
 
Registered: Apr 2021
Distribution: Arch (btw)
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Block devices are typically some type of storage medium i.e. PATA, USB, SATA and SCSI drives are /dev/sdx but you also have NVMe technology so this is more hardware dependent then software. Blindly writing to a block device could corrupt the filesystem(s). To write to a filesystem or check if a file exists does not need block level access.

Standard on any linux distribution are character devices like /dev/null, /dev/random, /dev/zero or /dev/ttyX. You usually read from /dev/random but you can write as well.

pipes and sockets depend on the distribution, how it was configured at installation and what services are currently running. You can find pipes and sockets via the find command i.e.

find / -type s,p

If you try to write to an existing socket or pipe I would expect you would need to know the service communication protocol otherwise nothing is going to happen, you might not get a response or you might "crash" the service.

As posted your going about it the wrong way.
Thank you for the information, that will come in handy! I don't want to either read or write to any of these files. I just want to use them to guarantee that my functions work.
 
  


Reply

Tags
file, file type



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Asterisk: Guaranteed Peace of Mind? LXer Syndicated Linux News 0 02-12-2008 07:41 PM
Guaranteed filesystem corruption on unclean shutdown? pigsa Linux - Software 7 12-10-2006 06:41 AM
UK noob: guaranteed working modem/router ? woody100 Linux - Hardware 6 04-01-2006 10:10 AM
Almost guaranteed distro and wire less card antisocialiting Linux - Networking 1 07-27-2005 08:46 PM
guaranteed scheduled job execution Xstack Programming 4 02-15-2005 10:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration