Symbolic Link to folder not working as expected - linux

so i want to start tomcat server, to do this i have to run a script whose path is the following:
/usr/local/Cellar/tomcat/9.0.6/libexec/bin/strartup.sh
Since it is tedious to remember this, i made a simbolic link:
tomcatsh/startup.sh
so with the ln command tomcatsh points to /usr/local/Cellar/tomcat/9.0.6/libexec/bin
There is a problem when i run the shortened version, it yelds an error saying that the startup.sh script couldn't find setclasspath.sh .
this other script is in the same folder, and it is not missing, why doesn't startup find that script? What can i do to solve this problem?

If previously that symlink is defined for the folder of the file, you have to call command with update parameter
ln -sf <file> <symlink>
rather than creation parameter
ln -s <file> <symlink>

Related

softlink to binary always use home folder path (instead of current folder)

kdevelop provides this AppImage binary:
wget -O KDevelop.AppImage https://download.kde.org/stable/kdevelop/5.1.1/bin/linux/KDevelop-5.1.1-x86_64.AppImage
chmod +x KDevelop.AppImage
./KDevelop.AppImage
It works well. So I want to make a soft link called kd to that binary in /usr/bin, eg:
/usr/bin/sudo ln -s KDevelop-5.1.1-x86_64.AppImage kd
Now if I run kd file1, I'd expect that it would open a file name file1 in the current folder, but it always tries to open a file name file1 in my home folder - which is not where it should be.
Is there some way to fix this issue?
Some possible causes:
The application always assumes that you want to open files in your home directory, effectively or literally prepending $HOME to the path. This would be a bug in any *nix program, and should be reported.
The application behaves differently when $(basename "$0") is not KDevelop.AppImage (what #Scheff said).
You are actually running a different kd.
Possible workarounds/investigations:
Pass the full path to the file on the command line. If it tries to open /home/you//full/path/you/provided it is obviously buggy, and you have a test case. If it does not, then there might be some gotcha to what your $PWD actually is. Try checking its value before running.
Symlink with the same name, using sudo ln -s KDevelop-5.1.1-x86_64.AppImage /usr/bin, and try running that. If it behaves the same, you've at least proven that the symlink is not the problem.
Run type -a kd and verify that your /usr/bin/kd comes up first. If not there might be an alias or shell built-in which takes precedence.
That said, what is the actual error message?

linux source a symbolic link

I have a bash script which i want to call from any directory, but i don't want to add the directory it is in to PATH as it is filled with lots of other scripts which will just clutter.
The script in question manipulates environment variables, so i have to source it.
I tried creating an alias
alias aliastoscript="/path/to/script"
source aliastoscript #This does not work says no such file
I also can't copy the script itself to a different location as it depends on the directory structure and other scripts in the directory.
So i tried a symlink to a location already in path:
ln -s /path/to/script /directory/already/in/path/myscript
But this does not work either:
source myscript #says no such file exists
Can anyone suggest how i achieve this? And why does the symlink approach not work?
If it makes any difference, i am using a zsh shell on ubuntu 14.04
EDIT:
The answer given below works, but i also wanted to know why the symlink approach was not working.
Here is the sequence of commands
ln -s /path/to/script /directory/already/in/path/myscript
#Now there is a symlink called myscript in a directory which is in PATH
source myscript arg1 #This throws an error saying no such file myscript,
#but it is not supposed to happen because myscript resides in a directory which is in PATH
EDIT 2:
I just figured what i was doing wrong, the symlink i created, i had used relative paths, totally stupid of me, using absolute paths it worked like a charm.
Try replacing:
alias aliastoscript="/path/to/script"
with:
export aliastoscript="/path/to/script"
You have a $ missing in front of the variable name.
source $aliastoscript
You do not need soft link for the source. The complete file name should work. Better is
source /path/to/script

Recycle bin Script in Linux

In my production server, somebody executed rm -rf and my important files are removed permanently. So, I thought of having a recycle bin, so if a user do rmthe file will move to RecycleBin rather than deleting from server. And i've made the below script for it. But I'm getting some error while it executed.
alias rm='/root/remove.sh'
#rm test_file
Now below script will trigger when you type the rm command
#!/bin/bash
dir=$(pwd)
mv $dir/$1 /root/Recyclebin
when the above script is triggered i'm getting the following error.
mv:cannot move '/root/test_file' to '/root/Recyclebin': Not a directory
Now, please suggest is there anyother way to make a recycle bin concept other than this or please help to resolve the error. Thanks in advance.
I'm using CentOS 5.6
Try This
At first create a folder named as MyTrash under /root ie: /root/MyTrash
Then open .bashrc file and write the below line at the bottom of the file.
alias rm='mv -t /root/MyTrash/'
Here -t means
-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY
update .bashrc file by running this command source .bashrc
Now if you delete any file using rm command that file will be moved to /root/MyTrash directory

command not found in bash-3.2$

I tried running a script file using bash but it showed an error
bash-3.2$ example.sh : command not found
I also tried
ls -l example.sh
I found that it was not executable, so I used
sudo chmod 777 example.sh
I again tried running it but same error was coming. I double checked that I am in the same folder as the file using ls. But still I am not able to execute the script file.
I finally tried making a dummy script file and running it , and found the same error
I think there is some problem with BASH. Can some one help me with what is the problem?
I am working on redhat, bash was already installed in my system
Since I am newbie on linux any help would be appreciated
bash search for commands in your $PATH. Apparently the current directory, ., is not in your $PATH. (This is a good thing; having . in your $PATH is insecure.)
You'll need to specify a directory name. Just type:
./example.sh
Incidentally, doing:
sudo chmod 777 example.sh
is two kinds of overkill. First, you don't need to use sudo; use sudo only when you actually need to. Presumably your personal account owns the file, so you can just use chmod directly.
Second, 777 is way too permissive. It allows anyone on the system to read, execute, or modify example.sh. (If you're the only person on the system it may not matter much, but it's still a bad habit.) Typically you should use 755 for directories and for files that need to be executable, and 644 for files that don't need to be executable.
Or just use
chmod +x example.sh
to set execute permission (your umask will prevent that from setting the permissions too loosely).
. (the current directory) is probably not on your path. Try ./example.sh or bash example.sh. You could also add . to your PATH environment variable, but that's generally frowned upon.
Your bash PATH probably doesn't include ., try running it by typing:
./example.sh
When you type a command, your shell searches your path to try to find the command, if the current directory (e.g. .) isn't part of the path, the script that you are trying to run won't be found. You'd have to explicitly give it the path to where this command is. And since it's in your current directory, you can just add ./ in front of the command.
first confirm the bash path
to check the path of bash use:
which bash
if you get "/bin/bash"
then add
#!/bin/bash
...
...
or whatever is the path on first line of your bash script

Linux SoftLink to applications and execution

I have created a softlink to an application using the following command:
ln -s sourcedir/Application somedir/ApplicationSoftLink
But I do not know how to start the application using the softlink. My understanding of a softlink is that it is the same as a shortcut in Windows, you just double-click the shortcut and the application will launch. However, when I tried to ./ApplicationSoftLink the application would not start.
Could someone please provide some assistance?
ln -s sourcedir/Application somedir/ApplicationSoftLink probably puts the wrong path in your symbolic link.
Try:
ln -s $PWD/sourcedir/Application somedir/ApplicationSoftLink
Were you in somedir when you tried running ./ApplicationSoftLink?
I think what you want to do is create the link in some directory in your path, so you don't have to say where the file is at all. You can type
echo $PATH
to find out what's in your path. /usr/local/bin is a good choice for things like this.
is sourcedir/Application executable?
when I tried to "./ApplicationSoftLink" the application would not
start.
Is there any error message?
were you typing ./ApplicationSoftLink under "somedir"?
or try ln -s /absolute/path/sourcedir /absolute/path/you/want/somedir/myApp
then under somedir/myApp/ run ./Application

Resources