0

I'm new to Linux, so... apologies. I have researched this for literal hours and I can't the solution to my problem.

I'm following a course where the individual is creating a file in the usr/bin directory vim usr/bin testfile - regardless of what I try I can't write here, and I get the "E212: Can't open file for writing" error. Whether i'm just the normal user or root it won't let me. I've tried chmod 777 for the directory. If I navigate to usr/bin I can create a file while i'm in there, but aside from that it won't let me if i'm anywhere else, root or not. I've tried CentOS 9 stream and the redhat download from RH's site.

2
  • /usr/bin is for OS and vendor-supplied programs, /usr/local/bin are for downloads and self-written programs, so you almost certainly want to write to the latter.
    – marshki
    Commented Dec 12, 2022 at 20:50
  • @marshki - thank you, I will remember this from now on.
    – John
    Commented Dec 12, 2022 at 21:04

1 Answer 1

4

usr/bin is a relative path. It means the file called bin inside the subdirectory called usr inside the current working directory. Most directories don't have a subdirectory called usr. So for most choices of working directory, usr/bin doesn't exist.

Unix systems have a directory /usr/bin. This is an absolute path, since it begins with a slash. It's the subdirectory called bin inside the subdirectory called usr inside the root directory.

The command vim /usr/bin testfile would first try to edit /usr/bin (Vim will see that this is an existing directory and will show its contents), then testfile in the current directory.

The command that is meant is presumably vim /usr/bin/testfile. This command edits a file called testfile inside the directory /usr/bin (which exists on all typical Unix-like systems). This command works whether testfile exists or not. If it doesn't, you'll get the opportunity to (try to) create the file by saving it from Vim. Saving will only work if you have permission, which requires being the root user.

Editing test files in a system directory is bad practice for a course. You should learn how to edit files on your account, and not start editing system files until you're comfortable with the basics. A file called testfile has no business being in /usr/bin.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .