DEV Community

Cover image for The Linux App Structure Explained: Working with /opt, Desktop Entries, and sudo tee
Rijul Rajesh
Rijul Rajesh

Posted on

The Linux App Structure Explained: Working with /opt, Desktop Entries, and sudo tee

If you have ever downloaded a portable Linux application or needed to create a custom launcher, you might have come across directories like /opt, files ending in .desktop, or the sudo tee command. Many users run into these concepts without knowing what they mean or how they fit into a normal Linux workflow. This article explains these three topics in a clear and beginner friendly way so you can confidently manage third party applications on your system.

What the /opt Directory Is Used For

The /opt directory is a standard location in Unix based systems. Its name stands for "optional". It is used for installing software that is not part of the core operating system and not managed by your package manager.

Here is why software is placed in /opt:

  1. It keeps third party applications separate from system installed packages.
  2. It prevents files from interfering with /usr/bin, /usr/lib, or other system directories.
  3. It makes uninstalling easier. You can remove the entire application by deleting its folder.

A typical application stored in /opt looks like this:

/opt
  application-name
    application-binary
    resources/
    icons/
Enter fullscreen mode Exit fullscreen mode

To move an extracted application to /opt, you usually run:

sudo mv extracted-folder /opt/application-name
Enter fullscreen mode Exit fullscreen mode

This keeps your system clean and helps avoid permission related problems.

What a .desktop File Does

A .desktop file is what makes an application appear in your Linux system menu or launcher. It serves the same purpose as a shortcut on Windows or a dock item on macOS. Without a .desktop file, the system has no way of knowing how to start your application or what icon to display.

A .desktop file contains metadata and instructions, such as:

  • The name shown in the application menu
  • The command used to launch the program
  • The icon image to use
  • The type of application
  • Optional categories to help organize menu entries

Here is a simple example:

[Desktop Entry]
Name=Sample Application
Exec=/opt/sample-app/start.sh
Icon=/opt/sample-app/icon.png
Type=Application
Terminal=false
Categories=Utility
Enter fullscreen mode Exit fullscreen mode

Once this file is placed in /usr/share/applications/, it becomes available in the system launcher for all users. If you only want it for your user account, place it in ~/.local/share/applications/.


Why the sudo tee Command Is Useful

Most system directories are write protected. If you try using a normal redirection like:

echo "content" > /usr/share/applications/app.desktop
Enter fullscreen mode Exit fullscreen mode

the operation fails because the redirection happens before sudo is applied.

This is where sudo tee helps. The tee command reads input and writes it to a file. When combined with sudo, it writes with elevated permissions, making it perfect for creating system files such as .desktop entries.

Example:

sudo tee /usr/share/applications/sample-app.desktop > /dev/null <<EOF
[Desktop Entry]
Name=Sample Application
Exec=/opt/sample-app/start.sh
Icon=/opt/sample-app/icon.png
Type=Application
Terminal=false
Categories=Utility
EOF
Enter fullscreen mode Exit fullscreen mode

Why this works:

  • sudo runs tee with root privileges.
  • tee writes to the protected file.
  • The <<EOF syntax feeds the file content directly from your terminal.
  • Redirecting output to /dev/null keeps the terminal clean.

This approach avoids opening a text editor and is useful when providing installation instructions or automating setup steps.

Summary

The /opt directory is a safe place for storing third party or portable applications.
.desktop files integrate these applications into your desktop environment so they appear in your system menu.
The sudo tee command allows you to create system level files even when normal redirection is blocked by permissions.

If you’ve ever struggled with repetitive tasks, obscure commands, or debugging headaches, this platform is here to make your life easier. It’s free, open-source, and built with developers in mind.

👉 Explore the tools: FreeDevTools

👉 Star the repo: freedevtools

Top comments (0)