

This flag is used to create any directories in this path if they don’t exist. You can see that we are passing the -p flag to the mkdir command. Let’s see an example of how we can create a symbolic link to a Linux directory.Ĭreate a new directory under /opt/scripts/: mkdir -p /opt/scripts/this/is/a/complex/path/ Makes sense? Symbolic Link to a Directory in Linux

Lrwxrwxrwx 1 ec2-user ec2-user 17 Sep 1 14:50 last_report -> report_August2020

Our script has to repoint the symlink from report_July2020 to report_August2020 using the unlink and ln commands: reports]$ unlink reports]$ ln -s report_August2020 reports]$ ls -ltr What happens when the report for the next month is generated? In this way I can see the content of the most recent report simply using the command: cat last_report With the ls command we can see the symlink created: lrwxrwxrwx 1 ec2-user ec2-user 15 Aug 1 14:57 last_report -> report_July2020 In this specific case the script that generates the report for July would also execute the following command: ln -s report_July2020 last_report I can update the script that generates the monthly report to also create a symlink called last_report that points to the most recent report generated. Let’s say I want to have an automated way to access the latest report without knowing its name (that changes from month to month). One reason is to refer to files on our Linux system in a more generic way.įor example, I have created the reports directory in which every month an automated script (not part of this tutorial) creates a report of the monthly expenses for my business.īelow you can see the content of the reports directory: reports]$ ls -ltr Why would you create a symlink to a file in Linux?
