Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The subject is UNIX Please answer questions and include the Exercise number. Exe

ID: 3740505 • Letter: T

Question

The subject is UNIX

Please answer questions and include the Exercise number.

Exercises:

8.9 (i and iii), Frame aliases to show (i) only the hidden filenames in the current directory, (ii) the listing of all symbolic links in the current directory and below, (iii) the absolute pathname of a filename specified as argument to the alias.

8.15, Why do shells use a profile as well as an rc file? What types of entries do you place in each?

8.18, How can you make all of your aliases placed in ~/.alias available in all sub-shells? Will the aliases be available in a shell script in (i) Korn, (ii) Bash?

8.19 Devise a system which allows you to use an alias named current to display recursively only the ordinary files in the current directory tree which have been modified since you logged in.

9.17 Assuming that a user may be logged in more than once, how do you (i) list only those users, (ii) mail root a sorted list of all users currently logged in, where a user is listed only once?

Thank You!

Explanation / Answer

8.15 Login Shells

First, let me elucidate what I denote by authenticate shells. You've probably descried that sometimes in order to get to a terminal shell, you're prompted for a utilizer name and password. Other times, you just click on the terminal icon, and you're presented with a terminal already authenticated in. You'll most often experience this when utilizing a GUI desktop environment. Fundamentally, if you're already authenticated in to your Linux desktop, and you open a terminal window, it's an interactive shell.

It doesn't have to be inside a graphical desktop environment, however. If you ssh in to a remote server, you're prompted for a utilizer name and password (thus, a authenticate shell). If you then type bash from inside that SSH session, you're commencing a pristinely incipient terminal, but this time, it's an interactive shell (notice you're not prompted for a password). Why it matters is something I'll verbalize about a little later, but for comprehension sake, just recollect that if you're prompted for a utilizer name and password, it's most likely a authenticate shell. If you go directly to a bash prompt, it's most likely an interactive shell. The one fairly prevalent exception to this is if you've established SSH keys to authenticate automatically. In that case, albeit you aren't prompted for a utilizer name and password, it's still a authenticate shell. It's a pretty safe bet that if you're utilizing SSH to authenticate, it's a authenticate shell.
The Authenticate Shell Process

The authenticate shell process is far more perplexed than interactive shells, so I am going to go over that process first. I'm surmising your users have a bash shell assigned in their /etc/passwd files. It's the most prevalent shell for users to have, so it makes sense to be habituated with its nuances.

Step 1: when you authenticate in to a authenticate shell, the system probes for a file called /etc/profile. That file is a shell script that assigns a few environment variables all users should have set.

Step 2: the /etc/profile script conventionally ends by calling any shell scripts in the /etc/profile.d folder and executing them as well. Often it will run only shell scripts in /etc/profile.d that end with a .sh extension, so optically canvass the /etc/profile script to visually perceive how files should be formatted to run opportunely. Having a folder to integrate custom scripts is consequential, because if you have system-wide transmutes you'd relish integrated to everyone's authenticate shell, integrating commands to the /etc/profile file is hazardous. Any system updates affecting /etc/profile will overwrite your vicissitudes. If you simply integrate a custom file into the /etc/profile.d folder, it will be read by the updated /etc/profile script even if it's updated.

Step 3: the /etc/profile script additionally executes the utilizer's personal profile. This component is a little messy, as the utilizer profile might be called different things depending on distribution and/or utilizer customization. In general, the system will endeavor loading the profile by name in this order:

    .bash_profile

    .bash_login

    .profile

What Do Profiles Do?

First, a disclaimer: I can spell out only what is generally done with profiles and bashrc scripts. It's certainly possible for a person to transmute what is done by customizing either profiles or bashrc scripts. Generally, it's good practice to stick to the standards.

Profiles mainly are habituated to load environment variables. Since profiles are loaded by authenticate shells, and authenticate shells are the initial ingression point into a system, that's the time when establishing the environment makes the most sense. One of the most astronomically immense environment variables is the PATH variable. When a authenticate shell is initiated, the PATH is set. Other environment variables additionally can be set in the system-wide profile or individual utilizer profiles, but just ken that the profile system is where most variables are set.

The order with which profile information is loaded is very consequential, because if you optate to override the system-wide default profile information, you can do so by designating environment variables in your personal utilizer profile script. For instance, the PATH variable is conventionally modified by the utilizer's profile script on authenticate. Conventionally, the .profile (or .bash_profile, etc., optically discern above) script will integrate ~/bin to the PATH variable if users have their own bin folder inside their domicile directory. Because utilizer profiles are loaded after the system-wide profile, utilizer settings take precedent and override system-wide settings.
What Do RC Files Do?

Again, this is a generalization, but the system-wide bashrc file and then the individual utilizer's .bashrc script conventionally set personal predilections for the command line. If you optate a custom prompt, or prefer a concrete color scheme, the bashrc system is where that would be set. Much akin to the profile system, the utilizer's .bashrc file overrides the system-wide bashrc (or bash.bashrc, again visually perceive above) settings. That signifies you can customize the demeanor of the command line however you like without affecting other users on the system.

The most prevalent customization inside the .bashrc file is to integrate aliases. An alias is scarcely like text expansion, in that it supersedes your defined alias with whatever command you designate. For example, here's a snippet from a .bashrc file in the utilizer's folder:

The aliases make it so that if the user types ll on the command line, the system will execute ls -alF instead. It's a great way to make shortcuts for commands with cryptic options or shortcuts for commands you type often.

Although I'm not suggesting tomfoolery, .bashrc aliases are also a great way to prank your fellow users if they leave their system logged in. Say you create an alias like this:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote