LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-11-2021, 10:45 AM   #1
centguy
Member
 
Registered: Feb 2008
Posts: 627
Blog Entries: 1

Rep: Reputation: 48
ln -s syntax


Are these two commands equivalent?

Quote:
ln -s /path-to-somewhere/a-file .
and

Quote:
ln -s /path-to-somewhere/a-file
The first one has a dot. at the end. It seems they are the same but I cannot be sure.
 
Old 11-11-2021, 11:06 AM   #2
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
No they are not the same the second is a failed command. The first no clue why it would be linked to . it is usually short for one level of the directory structure your current directory the .. the directory above. Normally you link the real file to the file to be linked ln -s /path/to/real/file /path/to/linked/file

Code:
zeus@bullseye-raspi:~$ touch test.txt
zeus@bullseye-raspi:~$ ln -s test.txt 
ln: failed to create symbolic link './test.txt': File exists
zeus@bullseye-raspi:~$ ln -s test.txt test2.txt
zeus@bullseye-raspi:~$ ls -l test*
lrwxrwxrwx 1 zeus zeus 8 Nov 11 12:59 test2.txt -> test.txt
-rw-r--r-- 1 zeus zeus 0 Nov 11 12:58 test.txt
zeus@bullseye-raspi:~$ cd .
zeus@bullseye-raspi:~$ cd ..
zeus@bullseye-raspi:/home$
Edit: Now it popped into my head the second command links to a file that is not there only a link.

Code:
zeus@bullseye-raspi:~$ rm test*
zeus@bullseye-raspi:~$ ln -s test.txt 
zeus@bullseye-raspi:~$ ls -l test*
lrwxrwxrwx 1 zeus zeus 8 Nov 11 13:16 test.txt -> test.txt
Not of any use I can see except as a method of have that name in place as there will be no contents in the link, the usual idea with a link is to have the same contents in two differently named files without using the space for the duplicate being linked.

Last edited by HappyTux; 11-11-2021 at 11:21 AM.
 
Old 11-11-2021, 11:24 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Quote:
zeus@bullseye-raspi:~$ touch test.txt
zeus@bullseye-raspi:~$ ln -s test.txt
ln: failed to create symbolic link './test.txt': File exists
Your example fails because your trying to create a link in the same directory as the source. since the OP specified the path to the file I would assume the current working directory is not the same.

From the man page it should be the same since ln will create a link of the same name in the current working directory or the specified directory which by the . is the current working directory.

Last edited by michaelk; 11-11-2021 at 11:25 AM.
 
1 members found this post helpful.
Old 11-11-2021, 11:27 AM   #4
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by michaelk View Post
Your example fails because your trying to create a link in the same directory as the source. since the OP specified the path to the file I would assume the current working directory is not the same.

From the man page it should be the same since ln will create a link of the same name in the current working directory or the specified directory which by the . is the current working directory.
Yes I seen this when it popped into my head about me having created the file first and tried it as my edit shows.
 
Old 11-11-2021, 01:20 PM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
yes, that is an ugly exception (so no other tools - like cp, mv - will take current dir as default like this). That's why I don't use it, but actually it works.
 
Old 11-11-2021, 09:15 PM   #6
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
Cool. Thanks!
 
Old 11-12-2021, 09:27 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,781

Rep: Reputation: 1199Reputation: 1199Reputation: 1199Reputation: 1199Reputation: 1199Reputation: 1199Reputation: 1199Reputation: 1199Reputation: 1199
Quote:
Originally Posted by centguy View Post
Are these two commands equivalent?
...
The first one has a dot. at the end. It seems they are the same but I cannot be sure.
Yes they are equivalent.
The dot is needed in case there are two or more link targets.
Code:
ln -s /path-to-somewhere/a-file /path-to-somewhere/b-file .
Or
Code:
ln -s /path-to-somewhere/*.txt .
 
1 members found this post helpful.
Old 11-13-2021, 01:18 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by centguy View Post
Cool. Thanks!
Please mark your thread SOLVED (see my signature).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
httpd: Syntax error on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 iswarya Linux - Newbie 1 01-25-2012 01:28 PM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
[SOLVED] "Error: syntax before '@' token and Error: syntax at 'OTHER' token" bullrider Programming 2 07-27-2009 08:00 AM
Starting httpd: httpd: Syntax error on line 209 of /etc/httpd/conf/httpd.conf: Syntax sethukpathi Linux - Networking 6 04-12-2008 11:26 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration