How can I have one script with 2 different names?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How can I have one script with 2 different names?
# 1  
Old 05-14-2010
How can I have one script with 2 different names?

Hi guys,
How can I have one script has 2 different names?
Can you give me some hints?
Thankyou!
# 2  
Old 05-14-2010
Code:
man ln

# 3  
Old 05-14-2010
ln file1 file1_1

but it will create another file with the same content in a different name.
I think should be just only one file1.
# 4  
Old 05-15-2010
then use alias of one file as second

Code:
alias file1="file2"

put this in .profile :-)
# 5  
Old 05-15-2010
Quote:
Originally Posted by lemon_06
ln file1 file1_1

but it will create another file with the same content in a different name.
It's not a different file but the same file which happen to have to different names. You can also use symbolic links:
Code:
ln -s file1 file2


Last edited by jlliagre; 05-15-2010 at 02:48 PM.. Reason: typo
# 6  
Old 05-15-2010
it still creates another file with the same code inside.
like ln -fs a b,
it creates b file.
# 7  
Old 05-15-2010
Hi, lemon_06.

You may be thinking that 2 names in a directory mean 2 separate files. In *nix, the inode is the collection of data about a file. More than one directory entry or link may point to one inode.

Here is an example of 2 filenames pointing to the same inode, hence 2 names for one file:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate two names for one file.

pe() { for i;do printf "%s" "$i";done; printf "\n"; }

# Remove old stuff.

rm -f a b

pe
pe " Created file a, with an inode as noted, one link:"
touch a
ls -ligG a

pe
pe " Created hard link b, same inode pointed to, now two links:"
ln a b
ls -ligG a b

exit 0

producing:
Code:
% ./s1

 Created file a, with an inode as noted, one link:
269437 -rw-r--r-- 1 0 May 15 13:10 a

 Created hard link b, same inode pointed to, now two links:
269437 -rw-r--r-- 2 0 May 15 13:10 a
269437 -rw-r--r-- 2 0 May 15 13:10 b

For more details on inodes, see inode - Wikipedia, the free encyclopedia

Symbolic or soft links do something similar -- 2 names for 1 object, but in a different way. See Symbolic link - Wikipedia, the free encyclopedia

Best wishes ... cheers, drl
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Long file names within shell script

I am downloading a zip file that contain files that are very long. I am trying to process them, but cannot. I can move the files from one directory to another at the shell prompt, but not within a shell script, I get a stat error. The files look somewhat like this; ... (5 Replies)
Discussion started by: trolley
5 Replies

2. Shell Programming and Scripting

Script to change file names

I have a landing directory on my unix (solaris) server, that receives the following files: MLH4301I AAOT-hhslog.610.20150805.txt MLH4301I AAOT-hhslog.611.20150805.txt MLH4301I AAOT-hhslog.612.20150805.txt MLH4301I AAOT-hhslog.613.20150805.txt and I need to add to this files the number 10000... (6 Replies)
Discussion started by: fretagi
6 Replies

3. Shell Programming and Scripting

Selecting/using part of directory names in script

I'm making a shell script to: -copy directories to a new location -perform conversions on the files within the copied directories -move the newly created files to a new directory Please see my super basic script and notes below... and thank you thank you thank you in advance !! ... (1 Reply)
Discussion started by: kayzee
1 Replies

4. Shell Programming and Scripting

Problems with script to find file names

Have a text file "test-array.txt" with contents below a23003 b23406 c23506 Tying to read the above file into an array and search for file-names in a directory TEST_DIR ,recursively with the above names in them. Example: If TEST_DIR has a files named xyxa_a23003_test.sql,... (4 Replies)
Discussion started by: gaurav99
4 Replies

5. UNIX for Advanced & Expert Users

script regarding listing long group names

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

6. Shell Programming and Scripting

input file names to a script

What is a more efficient way to read files into a script? I don't want to hard code the file names like below: for file in file1 \ file2 do ... done I want to execute the script with a variable number for files for input like below: ./scriptname file1 file2 file3 ...... (3 Replies)
Discussion started by: djehresmann
3 Replies

7. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies

8. Shell Programming and Scripting

script to find function names

hi, i am a newbie and have to write a rather complicated script. Assume that i have a variable called x and a C source code file say file1.c (these are the inputs of the script) and i need to find the names of all the functions in the C file containing x.Take the following code as an example: ... (2 Replies)
Discussion started by: samantha grace
2 Replies

9. Shell Programming and Scripting

How to get files names passed to a script

I need to get files names passed to a script. Here number of files passed may vary like MyScript.ksh file1 file2 file3..... so on I am writting script somthing like this set -A Files while (i<=$#) do File=$i let i=i+1 done Is this correct way doing this. Is there any other way.... (5 Replies)
Discussion started by: unishiva
5 Replies

10. Shell Programming and Scripting

Script for file names/sizes

How can I look at a certain directory and list all the file names, locations and sizes of each file in the current directory and all subdirectories? (2 Replies)
Discussion started by: ssmiths001
2 Replies
Login or Register to Ask a Question