<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[onecolumn,letterpaper,11pt]{article}

%===================================================================
\input{common_latex/common_latex_packages}
\input{common_latex/common_latex_definitions}
\input{common_latex/common_latex_help_format}
%===================================================================

\begin{document}

\begin{labcover}
\labtitle{Help Topic: Enable Interactive Modes}
\vspace{0.1in}
\labdate{Spring 2020}
\vspace{0.1in}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\labline
\end{labcover}

\wikidoc{file=Help.CMDInteractive}
\wikidoc{auth=mikerb@mit.edu}

%====================================================================
\section*{Don't Shoot Yourself in the Foot - Enable Interactive Modes}
%====================================================================

\noindent
A couple notes of caution. The \cmd{rm}, \cmd{mv}, and \cmd{cp}
commands can be brutally powerful. They are neither merciful nor
merciless. If used with a bit care they are as reliable as an old
friend. It turns out, you can easily tweak their default behavior to
make them a bit more merciful to handle common mistakes. Having used
these tools for about 20 years, I still use them in this way. If
you're a {\em new} user, I highly recommend this practice.

\pskip

Each of these three tools gives you the power to either remove or
overwrite an existing file. By default, they will just do as told
without prompting the user for further confirmation of intention.  For
example, suppose you want to rename \var{file1} to \var{file2}, but
you forgot that you already have a file by the name of \var{file2}:

\vspace{0.15in}
\begin{consoleverb}
 $ ls
 file1 file2 
 $ mv file1 file2
 $ ls
 file2              (Yikes!)
\end{consoleverb}
\vspace{0.15in}

\noindent
The \cmd{mv}, \cmd{rm}, and \cmd{cp} commands all take an option
argument \cmd{-i}, which prompts the user when there is a possibility
of overwriting or removing a file. That's wonderful, but if we're
trying to prevent silly mistakes, what about the silly mistake of 
forgetting to use the \cmd{-i} command line option? 

\pskip

None of these three commands have any way to modify them to
use \cmd{-i} by default. However, the same effect can be achieved by
creating an alias for them and putting the aliases in your shell
configuration file.

%---------------------------------------------------------------------
\subsection*{Creating an alias for the \cmd{rm}, \cmd{mv}, and \cmd{cp} commands}

\noindent
Our goal is to make the \cmd{-i}, interactive mode, the default
behavior used by \cmd{rm}, \cmd{mv}, and \cmd{cp}. To do this, we us
an {\em alias}.  If you haven't encountered aliases, they are an
absolute must-have tool in your command line toolbox. If you're
reading this page, the page on aliases shouldn't be too far off on
your list of things to learn:

\urlx{http://oceanai.mit.edu/ivpman/help/cmdline_aliases}

\vspace{0.1in}
\noindent
You can create an alias for the \cmd{rm} command right now by typing
the following on the command line. Similar syntax is used for
the \cmd{mv} and the \cmd{cp} commands.

\vspace{0.15in}
\begin{consoleverb}
 $ alias rm 'rm -i'       (if using tcsh)
 $ alias rm='rm -i'       (if using bash)
\end{consoleverb}
\vspace{0.15in}

\noindent
However, this alias will only hold as long as you are using this shell
(Terminal) session. If you open a new window, or log in and log out,
\cmd{rm} will revert back to its old self and not prompt you for
confirmation. To ensure \cmd{rm} always prompts for recommendation,
you'll need to put that alias in your shell configuration file.

%---------------------------------------------------------------------
\subsection*{Permanently adding \cmd{rm}, \cmd{mv}, and \cmd{cp} aliases to your shell}

Customizing your shell environment may also be a topic you haven't hit
yet, but it is super important and comes with the territory of using
aliases. More can be found here:

\urlxx{http://oceanai.mit.edu/ivpman/help/cmdline_shell_environment}

\noindent
If you're a tcsh user, add the following lines in your shell
configuration file which is typically, \var{~/.cshrc}:

\vspace{0.15in}
\begin{fileverb}
 alias  rm  'rm -i'
 alias  cp  'cp -i'
 alias  mv  'mv -i'
\end{fileverb}
\vspace{0.15in}

\noindent
If you're a bash user, add the following lines in your shell configuration file
which is typically, \var{~/.bashrc}:

\vspace{0.15in}
\begin{fileverb}
 alias  rm='rm -i'
 alias  cp='cp -i'
 alias  mv='mv -i'
\end{fileverb}
\vspace{0.15in}

\noindent
Finally, sometimes the default behavior (no prompting for confirmation)
really is what you want. The prompting may be annoying if operating on
several files. If the operation is part of a script, it can hold up
the script. In these cases, the \cmd{-f}, or {\em force} option, can 
be used to override the interactive option.

\end{document}

</pre></body></html>