Urgent.News

What's breaking now, across thousands of outlets.

Tech

Linux mkdir: Create Directories, Build Paths, and Fix Common Errors

Creating a directory from the Linux command line is simple; choosing the right path and understanding why a command fails are the parts that tend to trip people up. The basic command is: mkdir project That creates project inside your current working directory. To check where you are first, run pwd . Choose a path that matches the task You can pass mkdir a relative or absolute path. A relative…

Creating directories on the Linux command line is straightforward, but it can be frustrating when things go wrong. To create a single directory named "project" in the current working directory, simply use the command "mkdir project". To verify your current location, run "pwd" before executing the mkdir command.

You can specify either a relative or absolute path when using mkdir. A relative path is based on your current directory, while an absolute path begins with a forward slash and remains consistent regardless of your current directory. For example, "mkdir projects/demo" will create a directory named "demo" inside a folder called "projects", but only if "projects" already exists.

An absolute path, like "mkdir /home/alex/projects/demo", offers more predictability in scripts, as the current working directory may be unknown. If you need to create multiple directories simultaneously, separate their names with spaces, like "mkdir logs backups temp". These directories become siblings rather than nested within each other.

To create a directory tree that includes missing parent directories, use the "-p" option. For instance, "mkdir -p projects/app/logs" will generate "projects", "app", and "logs" if they don't exist already. It also works if the target directory is already there, which can be useful in scripts that might run multiple times.

When dealing with spaces in directory names, quote them with quotation marks to ensure they're treated as a single argument. For a hidden directory, such as ".local-data", run "ls -a" to reveal it with "ls", but note that the leading dot signifies a naming convention, not a special permission.

Permissions on new directories are typically determined by your shell's umask. A standard umask of 022 will yield permissions of 755, granting read, write, and execute access to the owner while providing read and execute access to group and other users. To create a directory with specific permissions, like 700 (owner-only access), use the "-m" option: "mkdir -m 700 private-data". The specified mode applies to the final directory in both -m and -p combinations.

If you encounter an error stating "file exists", check whether it's a directory or a file using "ls -ld path/to/name". If it's a file, you can't use mkdir again, but if it's a directory, you might reuse it. Permission denied errors arise when the shell lacks write or execute permission on the parent directory. Check the parent directory with "ls -ld path/to/parent" before attempting creation. Using "sudo mkdir" might create the directory under root ownership, limiting your ability to write within it.

Running "mkdir -p" on a missing parent directory will attempt to create it alongside the target directory. If you hit a "Read-only file system" error, the issue lies in the filesystem's write permissions, not a missing directory. Lastly, to verify that you've successfully created a directory, use "ls -ld project" to display its details, including permissions and owner. To automatically enter the newly created directory, chain the commands with "&&", like "mkdir project && cd project".

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Fixing “sudo: command not found” on Linux

Seeing sudo: command not found doesn’t necessarily mean you need to install anything. You might already be root, your shell might not be able to find the sudo program, or you may be working in a…

  • "sudo: command not found" errors may not always require sudo installation.
  • Check user identity with whoami or id -u; examine /usr/bin/sudo and PATH.
  • Install sudo as root using distribution-specific package manager, then add user to sudo group.

Find the Right IP Address on Linux (Without Guessing)

If hostname -I prints three addresses and you’re not sure which one to use, the problem isn’t finding an IP—it’s identifying what each address is for.

  • Use hostname -I for quick IP overview
  • Employ ip -br addr show for interface-specific details
  • Check public IP with curl ifconfig.me

Copying Directories in Linux: Choose Between cp -r, cp -a, and rsync

Copying a directory in Linux is easy; copying it to the right shape is where mistakes happen. The destination may end up with an unexpected nested folder, hidden files may be skipped by a wildcard, or…

  • Use cp -r for basic directory copy, preserving directory tree structure
  • Include dot for hidden files in source path when copying with cp -r
  • Use cp -a for metadata preservation, symbolic link handling in cp

What Nginx Does in a Web App: Static Server, Reverse Proxy, and More

When a browser requests your app, which process actually handles the request? In many deployments, it’s Nginx at the public edge—and an application process behind it doing the app-specific work.

  • Nginx serves as a static server, delivering HTML, JavaScript, CSS, and images directly from disk.
  • Handles TLS encryption, routing, and static file delivery, complementing application server's role.

More from Friday 2 October →