Find and Locate Current .profile - unix

How can I find and/or locate the file and directory of the currently loaded .profile in a bash shell. I made modifications to the current .profile on my machine, and would like to update it some more. I had created the current version in vi and couldn't tell where it was creating the file.
I am hoping that there is a command similar to "whoami"...

Bash executes startup scripts in the following order if you start a login shell:
/etc/profile
.bash_profile under you home directory
.bash_login under you home directory
.profile under you home directory
And .bashrc under your home dir in case of non-login shell.
So, probably, you just have to run vi ~/.profile

Related

Rstudio Server Run from specific directory

I am spinning up an instance of rstudio server and I need the working directory of R to be a specific directory. I would also like the file pane in the bottom right corner to be pointing to the same directory. Is there a way to do this? Currently it runs from the home directory of whichever user is running the program. I have tried the --server-working-dir flag, and it does not seem to work. Here is the command I am using:
/usr/lib/rstudio-server/bin/rserver \
--server-daemonize=0 \
--server-user=user \
--server-working-dir=/some/path \
--auth-none=1 \
--auth-minimum-user-id=0
Any help would be useful here.
[edit] Just wanted to clarify that I would like the server to start in this directory. I am building a container that will be deployed multiple times, and I don't want the users to have to set their directories every time it is deployed.
If you want to modify the file pane in the right, you should edit /etc/rstudio/rsession.conf.
And add two lines in below:
session-default-working-dir=/some/path
session-default-new-project-dir=/some/path
You can do this by edditing the (global) R profile startup script. Here's a step by step guide:
1) Run Rscript -e "R.home()" -- this will tell you the location of your R directory home. In my case (Mac) it is /Library/Frameworks/R.framework/Resources
2) Go to /Library/Frameworks/R.framework/Resources/etc -- e.g., $R_HOME/etc
3) sudo touch Rprofile.site if it doesn't exist, then sudo nano Rprofile.site
4) Add the following lines and save:
cat("hi\n")
setwd("/some/path/")
You should avoid overwriting the users home directory.
Amongs the [.Rprofile] files you should only edit the Rprofile.site as a last resort since it acts globally.
Suggested solution:
R read the "initialization file" at start, in the following order:
.Rprofile.site
.Rprofile (located in the current directory).
.Rprofile (in the users home directory).
In your case if you are planning to login to R-Studio server you will end up in the users home directory, so I would suggest you to just edit the [.Rprofile] in the home directory. In case the [.Rprofile] is missing you need to create it.
Add this line in your .Rprofile [in your home directory]:
setwd ('/your/path/')
Logout/login to your R-studio server session and you will notice that the "file pane to the right location" has changed accordingly to what you specified in your .Rprofile.

How can I save the path to a frequently used directory in UNIX?

Is there a way to save the path to a frequently used directory in UNIX, so instead of having to manually cd /path/to/directory I can just enter a shortcut cd myFavoritePath ??
Define your favorite directories in CDPATH environment variable. It's a colon-separated list of search paths available to the cd command. You should specify not a directory you want to switch but parent directory.
Here is brief info about it: http://docstore.mik.ua/orelly/unix/upt/ch14_05.htm
For example you have three directories you work with frequently:
/home/user/scripts/favorite/
/var/log/
/var/lib/
add to your ~/.bash_profile (or another shell profile file you use) the next line:
export CDPATH=.:/home/user/scripts:/var
In the example below I just redefine CDPATH in shell for the current session
[user#server lib]$ CDPATH=.:/var:/home/user/scripts
[user#server lib]$ cd log
/var/log
[user#server log]$ cd lib
/var/lib
[user#server lib]$ cd favorite
/home/user/scripts/favorite
If you want use tab while execute cd you can install bash-completion http://bash-completion.alioth.debian.org/ but it's optional
Also do not forget cd - command for quick switching to previous working dir
You can always add the directory path in ~/.bashrc
vi ~/.bashrc
export FAV_DIR1=''
The variables in .bashrc load into the environment on new session. So make sure to reboot.
Then you can visit the directory by something like:
cd $FAV_DIR1

Added Alias to .bashrc but no results

I added an alias (alias homedir='cd /export/home/file/myNmae'
) to .bashrc in my home directory and restarted the session. When I run the alias it says homedir: command not found.
Please advice.
This is because .bashrc is not sourced everytime, only for interactive non login shells .bashrc is sourced.
From the bash man page.
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/pro-
file, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the
first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the files ~/.bash_logout and /etc/bash.bash_logout, if the files exists.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the
--norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
i found the solution - i added it to the .profile file and restarted the session - it worked

How to run a program automatically on my terminal login in unix

Is it possible to write a shell script that automatically starts running whenever i login to my unix terminal? Please provide any reference material
Add your script inside your .profile . .profile is executed whenever you log in. If a .profile currently doesn't exist in your home directory, create one!
Depends on your shell. Assuming you are using bash, you can add the command to .bash_profile in your home directory.

Unix: Getting Export PATH to "Stick"

When setting the export path in Unix, example:
export PATH=$PATH: $EC2_HOME/bin
If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can set the path and have it "stick" so my system knows where to find everything the next time I open terminal without having to do it all over again.
Thanks!
Open ~/.bashrc. This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like ~/.shrc.
Add the line you need to the bottom of the file:
export PATH=$PATH:$EC2_HOME/bi
Other info rolled up from elsewhere in the thread:
There are multiple places to put this, depending on your shell and your needs. All of these files are in your home directory:
For Bash:
.bashrc (executed when you shart a shell)
OR
.bash_profile (executed when you log in)
For csh and tcsh:
.cshrc
For sh and ksh:
.profile
Add it to your .cshrc file (for csh and tcsh), .profile file (for sh and ksh), or .bash_profile file (for bash)
You need to find your profile file and put that line in there. Suppose you use bash, the profile files are .bashrc and .bash_profile, found in ~. These files will vary depending on which shell you use.
You have to put those commands into one of the "autostart" files of your shell.
For bash this would be .bashrc in your homedirectory (create it if necessary)
add it to your .bashrc or another .bash startup file.
... and for ksh edit .profile.

Resources