Python | os.symlink() method

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.symlink() method in Python is used to create symbolic link. This method creates symbolic link pointing to source named destination.
To read about symbolic links/soft links, please refer to this article.

Syntax: os.symlink(src, dst, target_is_directory = False, *, dir_fd = None)



Parameters:
src: A path-like object representing the file system path. This is the source file path for which the symbolic link will be created.
dst: A path-like object representing the file system path. This is the target file path where symbolic link will be created.
target_is_directory (optional): The default value of this parameter is False. If the specified target path is directory then its value should be True.
dir_fd (optional): A file descriptor referring to a directory.

Return type: This method does not return any value.

Code: Use of os.symlink() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to explain os.symlink() method 
    
# importing os module 
import os
  
  
# Source file path
src = '/home/ihritik/file.txt'
  
# Destination file path
dst = '/home/ihritik/Desktop/file(symlink).txt'
  
# Create a symbolic link
# pointing to src named dst
# using os.symlink() method
os.symlink(src, dst)
  
print("Symbolic link created successfully")

chevron_right


Output:

Symbolic link created successfully

Reference: https://docs.python.org/3/library/os.html#os.link



My Personal Notes arrow_drop_up

self motivated and passionate programmer

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.