The ln
command in Bash is used to create links between files. It allows users to create both hard links and symbolic (soft) links, enabling multiple references to a single file in the filesystem.
The basic syntax of the ln
command is as follows:
ln [options] [source_file] [link_name]
-s
: Create a symbolic link instead of a hard link.-f
: Force the creation of the link by removing any existing destination files.-n
: Treat the destination as a normal file if it is a symbolic link to a directory.-v
: Verbosely show what is being done, providing feedback during the link creation process.To create a hard link named link_to_file
that points to original_file.txt
, use:
ln original_file.txt link_to_file
To create a symbolic link named link_to_file
that points to original_file.txt
, use:
ln -s original_file.txt link_to_file
If you want to force the creation of a link and overwrite any existing file named link_to_file
, use:
ln -f original_file.txt link_to_file
To see detailed output while creating a link, you can use the verbose option:
ln -v original_file.txt link_to_file
ls -l
to ensure it points to the correct target.