Tuesday, June 16, 2026
HomeLanguagesPython | os.symlink() method

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




# 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")


Output:

Symbolic link created successfully

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

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS