24wi ver.
Note: this is for the Winter 2024 iteration of CSE 391. Looking for a different quarter? Please visit https://courses.cs.washington.edu/courses/cse391/.
-
What is the difference between
.bashrc
and.bash_profile
?Solutions
The difference concerns the difference between a “login shell” and a “non-login shell”. A shell is a login shell the first time you log in (i.e., when you first
ssh
). You can create non-login shells by running thebash
command from an existing shell.With that background, we can now appreciate the difference between the two files.
.bash_profile
gets run when you start a *login shell.bashrc
gets run when you start a non-login shell
For most people, you don’t care about the difference so a common procedure is to have all of your configuration in your
.bashrc
andsource ~/.bashrc
from your.bash_profile
. -
Say I have a python script (you can run a python script as a bash command by doing
python script.py
).- a) I want to be able to run it as a command from any directory, what do I need to do to accomplish this?
- b) Now I want it to run every time I login to Attu, how would I do this??
Solutions
- a)
alias randomnumber="python script.py"
(note you would likely want to use an absolute path to make sure you can run it from any directory) - b) Add it to your
.bashrc
-
How could I make it so if I type
attu
in a shell on my local machine it will ssh into attu?Solutions
alias attu="ssh username@attu.cs.washington.edu"
-
How could I print all the files in my current directory that belong to the
cse391
group?Solutions
The first solution works generally, but fails in some minor edge cases such as a file named
cse391
. The second solution works more generally:ls -l | grep "cse391" find . -group cse391
-
I have the file
run.sh
, it currently has unknown permissions. Say I want the owner to have read, write, and execute permissions, the group to have only execute permissions, and others to have only execute and read permissions.- a) How can I accomplish this using letter codes?
- b) What is an equivalent command using octal syntax?
Solutions
- a)
chmod u+rwx,g+x,g-rw,o+rx,o-w run.sh
- b)
chmod 715 run.sh