Browse Source

Added section on bash aliases

Kenneth John Odle 2 years ago
  1. 123


@ -1,7 +1,6 @@
@ -63,6 +62,12 @@
% Use strikethrough
% Style a blockquote
% See
\usepackage{setspace} % for \onehalfspacing and \singlespacing macros
% See also
% Make things neater. Thanks /u/-LeopardShark-
@ -153,9 +158,123 @@ And let's face it: the menu at McDonald's has not really changed in years. Yes,
Of course, if you are thinking about outcomes, chances are you don't eat fast food very often anyway, because the long term outcomes are obesity, heart disease, and hypertension. But damn, those fries are good!
\chapter{What's to Like About Linux?}
\section{A GUI Solution}
For what it's worth, there is a GUI for \texttt{pdftk}. It's called PDF Chain and you can find it at \href{}{\texttt{}}.
Despite all my prattling on about the many advantages the command line has for your brain, I'm not opposed to using a GUI, actually. (I mean, I have Ubuntu installed on two machines and Kubuntu on a third.) A GUI does make life easier in many ways, and what I like about one in a case like this is that if you're someone who has to manipulate pdf files rarely or only once, it's probably easier to just use a GUI than it is to learn the command line. Efficiency plays a role here, as well. If I'm going to use this all the time, it's definitely more efficient for me to learn the command line approach. But once or twice a year? Or only once? A GUI is much more efficient.
\chapter{Make Life Easier with bash Aliases}
I'm not going to get into the difference between the command line, the terminal, and bash (the Bourne Again Shell, if you are interested\footnote{You may not be, but after all, you are reading \textit{this} so you very well may be. I'll talk about that in a future issue.}) For now, let's just assume that you know about \texttt{ctrl alt t} opening a terminal window to get you access to the command line.
If you are used to using the command line, chances are that you have a certain set of commands that you use a lot. For example, if you're pushing to your Github repos all the time, you probably are typing \verb=git push origin main= quite often. You can create a bash alias that makes your life a lot easier.
Chances are, you will open the terminal in the root of your \texttt{Home} directory. You can tell by typing
$ pwd
\texttt{pwd} stands for ``Print Working Directory'' and shows you where you are. If you're in the home directory, you'll get something that looks like this:
\noindent{}where ``\texttt{username}'' is your login name. If you're \textit{not} in your home directory, you can get there with this command:
$ cd ~
\noindent{}The \verb|~| is shorthand for your home directory. We are looking for an invisible file, so execute this command:
$ ls -a
\noindent{}The \texttt{ls} command will list visible files, the \texttt{-a} option shows all files, including the invisible ones.
We are looking for a file called \texttt{.bashrc}. If you have a lot of stuff installed, you may have to scroll around to find it. Once you find it, open it in a text editor. This is in your home directory, so you can use whatever text editor you want and no \texttt{sudo} privileges should be required.
If you want, scroll through it. There is some interesting stuff there. But we want to create aliases, so go to the end, and type
# my aliases
\noindent{}The \verb=#= means that this line is a comment. We'll add our aliases beneath this line.\footnote{Let's stop and reflect for a moment on how important it is to add comments to whatever we work on. When you come back to this file in six months or two years and ask yourself ``Why is this here? Who wrote this?'' your comment will tell you. I often find it handy to include the date as well, and any url where I found something useful. Check the source code of the preamble to this document for examples.}
Let's use our Github example. Add the following line:
alias gpush="git push origin main"
\noindent{}Save the file, and then go to one of your git repos, make some changes, and commit them. Then, when you want to push the changes to the remote repository, instead of typing \texttt{git push origin main} just type \texttt{gpush}. Your terminal will do the rest for you.
You can also execute bash scripts as well. In addition to a local backup on an external drive, I also backup the directories in my home drive to a remote storage location. To make life easy, I created a script (called, naturally, \texttt{}) in each of those directories to back them up. To execute those backup scripts, I just need to go to that directory, open the directory in a terminal and type \texttt{./}.
The problem here is that a lot of times, I'm not even in those directories when I'm saving files to them. I'm somewhere else. And to open the directory in my GUI and then open it in a terminal, or to open a terminal and then navigate to that directory, is a little \textit{too} much when I want to run that backup script. Remember, you want to back up soon, and you want to back up often. Backing up on that basis is a good habit to have. So let's remove as many obstacles to that habit as possible. In this case, we'll add an alias to run those backup scripts.
This is what I have in my \texttt{.bashrc} aliases:
alias kdoc="bash $HOME/Documents/"
alias kdow="bash $HOME/Downloads/"
alias kpic="bash $HOME/Pictures/"
alias krec="bash $HOME/Recordings/"
alias ktem="bash $HOME/Templates/"
alias kvid="bash $HOME/Videos/"
Let's look at the first one. \texttt{kdoc} is the name of the alias. Since my first name is Ken, I prefix these with the letter \texttt{k} so I don't get them mixed up with something else. \texttt{bash} means to run this as a bash script. \texttt{\$HOME/Documents/} means ``go to the home directory, then go to the Documents directory, and run this script called \texttt{}''.
We can do other things as well. Log into your webhost via ssh a lot? Try this one:
alias kssh="ssh"
\noindent{}Type this, and it will ask for your password. You've now typed four characters instead of 24.
This is probably my favorite, though:
alias kls="ls -Ahl"
\noindent{}This gives us a directory listing, but with this flags:
\item \texttt{A} lists all files and directories, including invisible ones (but excluding the . and .. directories).
\item \texttt{h} gives us file sizes in human readable sizes (i.e., ``4.0K'') instead of bytes.
\item \texttt{l} gives us the listing as a list, because I find that's more readable, especially with a directory that contains a lot of stuff.
And that's it. Just about anything you type often on the command line can be turned into a bash alias to save you time.
\chapter{What Have I Installed?}
\chapter{What's to Like About Linux?}
I have an app on my phone called ``The Stoic'' that shows quotations from various Stoic philosophers. As I was working on this issue, this popped up:
Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
---\textbf{Marcus Aurelius}