LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-20-2010, 11:38 AM   #1
dave247
Member
 
Registered: May 2004
Posts: 204

Rep: Reputation: 30
Trying to write a command line script that will make symbolic links


Hey I am trying to figure something out as part of something else I am going to do. I was just wondering the easiest and quickest way to run a loop at the Linux command line which will make x amount of symbolic links when I need them.

I am using Debian 5.

I figure its something as easy as ~# foreach statement, then I just do a loop with the command to make a sym link.

thanks for any input. I am also googling it now too. thanks

Last edited by dave247; 10-21-2010 at 12:21 PM.
 
Old 10-20-2010, 08:30 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,516

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
Well on such a vague question it is difficult to assist. Are we looking for specific names? Do we not care and just a for loop counting from 1 to x is enough?

Perhaps you could flesh out more of what you require and also some examples would be nice
 
Old 10-20-2010, 09:46 PM   #3
dave247
Member
 
Registered: May 2004
Posts: 204

Original Poster
Rep: Reputation: 30
sorry, I didnt mean to be so vague. Say I want to make a sym link for a program or file in my home directory. Say I have 10 files like pics and documents in there. I want to run a script to go through and simply make a sym link for each file within my /home and have all the links be on my desktop.

thanks
 
Old 10-21-2010, 02:58 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,516

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
Well a while or a for loop could do the job. The choice of which to go for, in my opinion, is dependent on how many different types of files there are, ie the
extensions.
So if all files or only a couple:
Code:
for files in ~/*
do
    ln -sfv "$files" "/path/to/link"
done
If you change * to *.txt you get all txt files. The other downside here is that if you have a subfolder in the folder then it will get renamed to unless you
test that item is a file (will leave to you to find the test)

The other option would be a while loop and a find. This has the power of being able to use find's abilities to limit what items are found.
Example:
Code:
while read -r files
do
    ln -sfv "$files" "/path/to/link"
done< <(find $HOME -maxdepth 1 -type f)
Again I will leave you to do man find and see what options you have
 
Old 10-21-2010, 12:21 PM   #5
dave247
Member
 
Registered: May 2004
Posts: 204

Original Poster
Rep: Reputation: 30
grail: PERFECT dude thanks. I guess I was really wondering how to do that for loop think which is obvious now... thats part of bash, correct?

thanks again
 
Old 10-21-2010, 12:24 PM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,516

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
Quote:
thats part of bash, correct?
Yes both are bash constructs.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how ls command finds symbolic links venmugil Linux - General 6 12-01-2008 12:58 PM
make a copy of a directorystructure and his files as symbolic links Byenary Linux - General 4 04-25-2008 08:18 PM
KDE Random wallpaper or script to create symbolic links to random files cvelasquez Linux - Software 2 02-26-2007 06:48 PM
The command to make a symbolic link Gins Linux - General 10 11-12-2006 01:58 PM
how to use Find Command for Symbolic links nofunyet Linux - Newbie 2 04-08-2005 03:52 AM


All times are GMT -5. The time now is 05:35 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration