How to tell quickly if a file is in a directory that is linked? - symlink

When I am working inside an IPython notebook, I sometimes do !pwd and of course it will show the directory that I am working in. But sometimes these files are inside a directory that is linked.
e.g., when I do !pwd I'll see /a/b/c/, and when use the find command to actually find this file, I see that it is at /a/d/e/file_name.ipynb.
But when I follow the links, I see that /a/b/c/ -> /a/d/e/. What is annoying about this, is that I don't know where along the path it is linked. It could have been /a/b/ -> /a/d/ or something.
When I find out where a file exists, how do I find out where along the path it is linked?
Thanks.

Related

Bash: Find which symbolic links exists to a specific file

Given a file somewhere in the file system, can I find out which symbolic links exists that point to that file?
The purpose of this would be to determine if a file can be successfully deleted, or if deleting the file would leave behind a bunch of dead symbolic links.
If you do an "ls -l" in a directory that contains a file which is a symbolic link, the ls command will show you where the link goes. I'm looking for the reverse of that, which is getting a list of symbolic links around the file system which point to a specific file.
For example:
$ ls --optionToFindSymLinks? ./thefile.txt
/home/user/dir/file.txt -> ./thefile.txt
/home/otheruser/dir/file2.txt -> ./thefile.txt
2 symbolic links found
I realise that unmounted file systems might contain links that I won't be able to find, but this would not be a problem in my case.
Edit: Attempt at clarification
There is no reverse search. You have to do the work yourself. Get a list of all the symbolic links in your system and check which of them point to the file you are interested in.

Can't see files with Symlink

I need my client to be able to see the file in the directory they are allowed on. So I soft link the directory they are allowed on but can't see the files inside even tho they have the right (rwx).
ex:
/home/user1/project1.link/(couple of files)**
/clients/client_shamwow/project1/(couples of files)
**: Can't see the files.
This is the line I used:
ln -s /clients/client_shamwow/projet_prod /home/user1/projet_prod
is there something wrong that I am doing so they can't see the files in project_prod or I should use something else?
Your command doesn't match your example, but I assume you mean /home/user1/project1.link is a soft (symbolic) link, and when you run ls it lists just that name, rather than the contents of the directory the link points to. If that's the case, add the -L option to your ls command.
ls -lL /home/user1/project1.link
The man page says:
-L, --dereference
when showing file information for a symbolic link, show information
for the file the link references rather than for the link itself
Another way is simply to append /. to the end of your command, as in
ls -l /home/user1/project1.link/.
If that doesn't answer your question, I think you need to be more clear, and perhaps clean up the inconsistencies in your question. Even show some real output and the commands you ran.
Solved. No idea what happend. I just recreated the link the exact same way I did before and now I am able to see AND modify the files as the user1 w/o him being able to go anywhere else than what is in the folder project_prod. Thx for your time :)

Setting a path in OSX for Matlab

I just shifted from a windows machine to a apple machine at work. I have no experience with apple and this is the first time I am using OSX.
I have a matlab script that I have to run on this machine but I cannot seem to get the path to my files.
My files are on a network drive. In windows its as simple as U:\Matlab Now I can access my files in the explorer but cannot seem to set them in Matlab using cd
To get the path of my files I right clicked on the folder and copied the where It provided me with this:
Volumes/home9/MATLAB/
Now to set these paths in Matlab I did this:
cd('Volumes/home9/MATLAB/')
But am provided with the error:
Cannot CD to Volumes/home9/MATLAB/ (Name is nonexistent or not a directory).
As you can tell I have no idea what I am doing. Some guidance would be appreciated.
Thank you
I think you meant to use which, not where. where doesn't exist in MATLAB! Now, your problem is probably due to the fact that you need to prepend your path with /. Therefore, your path should be: /Volumes/home9/MATLAB/. If you don't include the /, it assumes that the directory is local or where MATLAB has currently defined the working directory to be. Judging from the context, you want the absolute path of the directory, and that's why you need the / character as there is a Volumes directory in your root directory.
Try that and see if that works!

Bash: cannot execute binary file (followed directions from online)

I am having difficulty installing something, and wanted to write a detailed list of what I did (including all paths, because I am new to Linux, and have problems reading things unless the full path is listed)
1) I am trying to run a program called "pslToBed". I downloaded it from here (http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/).
2) It downloaded a single file called "pslToBed". It looks like a binary file (all jibberish at least), and I saved to the directory /Users/MacOwner/Desktop/rnaseq/pslToBed
3) I did echo $PATH, and got the following
/usr/local/bin:/Users/MacOwner/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin:/usr/X11/bin:/opt/local/bin:~/bin:/Users/MacOwner/Desktop/bedtools2-2.19.1
4) I selected one path from step (3), namely /usr/local/bin
5) I did: cp /Users/MacOwner/Desktop/rnaseq/pslToBed /usr/local/bin/
6) I added the same line to the bottom of both ~/.bashrc and ~./bash_profile:
export PATH=$PATH:/usr/local/bin/pslToBed
Then, I returned to /Users/MacOwner/Desktop/rnaseq/ and tried to run pslToBed but got an error -bash: /usr/local/bin/pslToBed: cannot execute binary file
I know this may be straightforward to experienced users, but I am stuck, even after searching the internet for several hours now. Do my paths and ideas look correct? And if not, what should I do to get this program running?
First, see what kind of file you have:
file plsToBed
This will print the kind of file (including details about the target architecture).
Next, there's no need to copy the file anywhere before trying to run it. If it's in a particular location and you have cd to that location, then simply:
./plsToBed
will execute it from the current directory.
You shouldn't have been able to copy to /usr/local/bin without being root (I hope you're not doing all this as root).
You don't want to add the name of the file itself to the PATH environment variable; the PATH is a list of directories, not files.

How do you get your path in Octave (on Windows)?

I used addpath(pwd) to get my .m files working in my projects directory. When I close the window and start a new window, the path I just added is gone. But the files still run.
Is it in my path or not? How do I see the directories I have added to my path?
Also, . is the first entry I see from path. Does that mean I don't need to add any directories because it will always search the current directory first?
Thanks.
Basically, yes.
You can add a directory to the search path using addpath(), but as you know, it only exists for the current session and is reset when you restart Octave. If you want a path to survive between sessions, add it to your octaverc, a script file that gets run whenever a new session gets started. Example path to octaverc file is:
C:\Octave\3.2.4_gcc-4.4.0\share\octave\site\m\startup
Since . is in your path by default, Octave will search your current directory for any function files that it needs. Using addpath(pwd) is somewhat useless if you're just going to stay in the same directory. However, there are some cases where it'd be useful, if for example you have a directory that contains your functions, and another one that has the data that you're working on: you could start in the functions directory, do addpath(pwd), and then cd to the data directory while still being able to use your functions.
You can create batch file, which will start Octave with your directory path. Please see example below:
octave-3.6.4.exe -p "C:\MyOctaveDiretory"
-p means addpath()
addpath(pwd); savepath();
Done.
I think there is a bug in Octave (I use version 4.0.3 on Windows). When I create a new file in current path, this can't be called by Octave ("error: 'foo' undefined near line 1 column 1"). If I restart Octave, it works. This addpath(pwd) trick helps me a lot (before I unsuccessfully tried rehash() and cd elsewhere and back again).
If you had the same problem, the reason for the symptom might be:
Start Octave.
Create newfile.m.
Call newfile - fails since Octave did not register its existence.
addpath(pwd) - causes Octave to register it.
Close Octave
Start Octave - now pwd is gone from path, but newfile.m is registered at startup.
call newfile - works
I faced a similar problem in adding path where the path was added by using addpath command directly in Octave GUI (Command Window). The path added was being shown in console window but none of the functions worked.
The problem was solved by changing the path directory from Windows directory to some other direction where OS is not installed.

Resources