Hi gud day! Anybody who knows how to save a file to /usr/include in the terminal? Suppose I will save a file named hello.h to the said directory, what would I do in the terminal? thank you very much....

Dani AI

Generated

Short practical choices and a safer workflow.

If the goal is simply to have a header available system-wide, install it into the local area that is meant for locally-built files rather than mixing with distribution files. For a quick one-off you can stage the file somewhere in your project and then install it into the system include tree (example shown for /usr/local/include):

sudo install -Dm644 hello.h /usr/local/include/hello.h

For anything more than a quick test, keep headers in your project (include/), compile with an extra include path, and provide an install target so the project can be packaged or removed cleanly. Example Makefile install rule:

install:
    install -d "$(DESTDIR)/usr/local/include/myproj"
    install -m 644 include/*.h "$(DESTDIR)/usr/local/include/myproj/"

Do not scatter project-specific headers into /usr/include. ’s point about avoiding that place for your own files is important: /usr/include is for distribution-managed headers and can be overwritten by package updates. Use /usr/local/include or an application-specific prefix (or keep headers private and use -I), and if you want system-wide installation, use a proper make install or packaging (deb/rpm) so ownership, permissions, and uninstall are handled.

Troubleshooting and cautions: give headers unique names or a project subdirectory to avoid collisions; remember permissions and SELinux contexts on some systems; use DESTDIR for staged installs during packaging. For the filesystem policy and recommended locations see the Filesystem Hierarchy Standard: Filesystem Hierarchy Standard.

Note: already touched on file placement mechanics, and asked that solved threads be marked — if the original question is resolved, mark it solved so others know.

Recommended Answers

All 4 Replies

>Anybody who knows how to save a file to /usr/include in the terminal?
Uh, yeah. Just use the cp or mv command. With root (administrator) privileges, of course.

>Suppose I will save a file named hello.h to the said directory
If you save it there, then well, it's there.

>what would I do in the terminal?
Nothing. It's already there because you just saved it there.

thanx a lot

If you're doing this (putting your own header files in /usr/include) just to avoid having to specify -I parameters on the compiler command line, then you need to reconsider your approach.

Polluting /usr/include with a bunch of project specific header files will surely come unstuck in a big way at some point.

i thought a rule for posting was not using titles such as this one...

and... could you plz mark it as solved when your question is answered?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.