DEV Community

Cover image for Order-agnostic symbolic links
cerico
cerico

Posted on • Edited on

Order-agnostic symbolic links

Order-agnostic symbolic links

I don't use symbolic links a whole bunch, but when I do use them I always forget the order of arguments in the ln command. So I wrote a function that allows you to create a symbolic link in any order so I never have to think about it again.

isym () { # Make symbolic link in any order # ➜ isym cats dogs
  [[ -e $1 ]] && ln -s $1 $2 || ln -s $2 $1
}
Enter fullscreen mode Exit fullscreen mode

Here's a breakdown of what happens within this function:

  • [[-e $1]]

Initially, the function checks whether $1, the first parameter, is a valid file or directory (-e). This safety check prevents creating symbolic links to non-existent files or directories.

  • && ln -s $1 $2

If $1 is indeed a file or directory, the function creates a symbolic link to $1 named $2.

  • || ln -s $2 $1

If the first condition fails (i.e., $1 doesn't exist), the function attempts to create a symbolic link to $2, named $1.

Usage

➜ isym <file> <link>
➜ isym <link> <file>
➜ isym /etc/asda.conf ~/asda.conf
➜ isym ~/asda.conf /etc/asda.conf
Enter fullscreen mode Exit fullscreen mode

Now this can be used in any order without worrying about the order of the arguments.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️