Create shortcut to a file in Linux

To create a shortcut to a file in Linux, we can use ln command with -s option.

The complete command to create a shortcut to a file using ln command is

ln -s path/to/your/file short/cut
  • Option -s creates a soft link.
  • path/to/your/file is the path to the file for which you would like to create the shortcut to.
  • short/cut is the path to the shortcut file.

Example

In this example, we create a shortcut to logs/my-log.txt. We shall keep the name of the shortcut same as the original file name my-log.txt.

my-log.txt displayed in green is the short to the file logs/my-log.txt.

List out the files and directories in the current directory.

root@tutorialkart# ls
info.txt logs

There is a file in locks folder named my-log.txt.

Run the ln command to create the shortcut.

root@tutorialkart# ln -s logs/my-log.txt my-log.txt

Now, list out the files and directories.

root@tutorialkart# ls
info.txt logs my-log.txt

A shortcut has been created in the current working directory as specified in the command.

ADVERTISEMENT

Conclusion

In this Linux Tutorial, we learned how to create a shortcut to your file, using ln command.