Updates to terminal commands; some moved to «include» subdirectory
This commit is contained in:
parent
1fb4a0ab27
commit
5e96b11816
@ -71,15 +71,34 @@ This may not seem like a useful command, but if you start wandering around in th
|
|||||||
|
|
||||||
If you forget who you are, you can also use the \texttt{whoami} command, which simply returns your user name. Again, this may not seem very useful, but sometimes you have to log in as the root user, and if you forget whether you're logged in as the root user or a regular user, this becomes not handy but absolutely necessary. (You can wreak havoc on your system quite easily when logged in as root, so this is a good thing to check.) If you are logged in as the root user, \texttt{whoami} should return ``root'' rather than your regular user name.
|
If you forget who you are, you can also use the \texttt{whoami} command, which simply returns your user name. Again, this may not seem very useful, but sometimes you have to log in as the root user, and if you forget whether you're logged in as the root user or a regular user, this becomes not handy but absolutely necessary. (You can wreak havoc on your system quite easily when logged in as root, so this is a good thing to check.) If you are logged in as the root user, \texttt{whoami} should return ``root'' rather than your regular user name.
|
||||||
|
|
||||||
|
\subsection{Arguments and Switches}
|
||||||
|
|
||||||
|
Bash commands follow the Unix principle (``Do one thing and do it well'') but that doesn't mean that they are simple. I mean, they are simple, but they can accomplish complex things.\footnote{Which I guess means that ``simple'' is a matter of perspective. When I was first starting with Linux, I thought these commands were terribly complicated. But as I've gained experience, I went from ``complex input $\rightarrow$ simple intput'' to ``simple output $\rightarrow$ complex output''. Experience and knowledge change your perspective.}
|
||||||
|
|
||||||
|
Most but not all commands have both \textit{arguments} and \textit{switches}, which are sometimes called \textit{options}. (I like the term ``switch'' because I like to think that a command can switch between doing things in different ways.) For example, if I want to copy a file on the command line, I need to tell the terminal which file I'd like to copy. That file's name is the \textit{argument}—in other words, it's the thing I want the command to act on.
|
||||||
|
|
||||||
|
Sometimes an argument is obvious and can be omitted. For example, if I want to list the contents of a directry, the \texttt{ls} command (which we will talk about in a bit) assumes that the argument is the current directory. If I want to see the contents of a different directory, I either need to move to that directory, or specify that directory's path as an argument.
|
||||||
|
|
||||||
|
Switches (i.e., options) affect \textit{how} a command carries out its work. Suppose I want to see the contents of the directory I'm currently in. I would use the \texttt{ls} command for that. But do I want to see any invisible files or subdirectories? By default, the \texttt{ls} command omits those. If I want to see those (which is useful if I'm looking at configuration files, which are typically created and modified by your software and are thus hidden), I need to use the \texttt{-a} switch, which switches from hiding invisible files and subdirectories to showing invisible files and subdirectories.
|
||||||
|
|
||||||
|
As it turns out, most commands have two options for switches. For example, the manual page for the \texttt{ls} command says this:
|
||||||
|
|
||||||
|
\begin{Verbatim}[]
|
||||||
|
-a, --all
|
||||||
|
do not ignore entries starting with .
|
||||||
|
\end{Verbatim}
|
||||||
|
|
||||||
|
Both \texttt{-a} (one hyphen) and \texttt{--all} (two hyphens) have the same effect: they both show invisible files and subdirectories. So why are there two versions of this switch? I'm not 100\% sure as to the reason\footnote{Because the amount of research I have done here is exactly equal to zero.} but I suspect it has to do with how the human mind remembers information. For example, if I want to see \textit{all} the files in a directory, including the invisible ones, it's pretty easy to remember the two-hyphen version (\texttt{ls --all}). But in this case, ``\texttt{-a}'' is also short for ``\texttt{--all}'' All I need to do is remember that ``a'' is a shortcut for ``all''.
|
||||||
|
|
||||||
|
Most command switches work this way. Keep in mind, there are no hard and fast rules for this. The single-hyphen switch is not always lowercase (for example, the \texttt{cp} command has both \texttt{-l} which means ``hard link files instead of copying'' and \texttt{-L} which means ``always follow symbolic links in SOURCE''; the lower-case and upper-case options have nothing to do with each other), and the single-hypen single letter option doesn't always have a double-hypehn full word option.
|
||||||
|
|
||||||
\subsection{Moving Around}
|
\subsection{Moving Around}
|
||||||
|
|
||||||
Now that you know who and where you are, you probably want to move around a bit. The command to change directories is \texttt{cd} (which stands for ``change directory''—sometimes these things make sense). If you are in your home directory and you want to change to your Documents directory, you would use:
|
Now that you know who and where you are, you probably want to move around a bit. The command to change directories is \texttt{cd} (which stands for ``change directory''—sometimes these things make sense). If you are in your home directory and you want to change to your Documents directory, you would use:
|
||||||
|
|
||||||
\begin{Verbatim}[]
|
\input{include/cd_documents}
|
||||||
cd Documents
|
|
||||||
\end{Verbatim}
|
|
||||||
|
|
||||||
Notice that it is ``Documents'' and not ``documents''. Case matters a lot in Linux. If you are typing a command and you are sure that you have the syntax correct but it is not working, check the lettercase. It's possible you're typing something in lower case when the actual target is written in upper case.
|
Notice that it is ``Documents'' (starting with a capital letter) and not ``documents'' (starting with a lower-case letter). Case matters a lot in Linux. If you are typing a command and you are sure that you have the syntax correct but it is not working, check the lettercase. It's possible you're typing something in lower case when the actual target is written in upper case.
|
||||||
|
|
||||||
Once you're in that directory, the \texttt{pwd} command should give you this output:
|
Once you're in that directory, the \texttt{pwd} command should give you this output:
|
||||||
|
|
||||||
@ -89,23 +108,17 @@ Once you're in that directory, the \texttt{pwd} command should give you this out
|
|||||||
|
|
||||||
To get back to my user directory, I would them type:
|
To get back to my user directory, I would them type:
|
||||||
|
|
||||||
\begin{Verbatim}[]
|
\input{include/cd}
|
||||||
cd ..
|
|
||||||
\end{Verbatim}
|
|
||||||
|
|
||||||
The two dots mean ``go up one directory''. If I wanted to go up two directories, I would use:
|
The two dots mean ``go up one directory''. If I wanted to go up two directories, I would use:
|
||||||
|
|
||||||
\begin{Verbatim}[]
|
\input{include/cd_up}
|
||||||
cd ../..
|
|
||||||
\end{Verbatim}
|
|
||||||
|
|
||||||
Which means ``go up one directory (the first two dots) and then go up one more (the forward slash and the second two dots)''.
|
Which means ``go up one directory (the first two dots) and then go up one more (the forward slash and the second two dots)''.
|
||||||
|
|
||||||
And to go down two or more directories, we would use the forward slash again:
|
And to go \textit{down} two or more directories, we would use the forward slash again:
|
||||||
|
|
||||||
\begin{Verbatim}[]
|
\input{include/cd_doc_sss}
|
||||||
cd /Documents/"super secret stuff"
|
|
||||||
\end{Verbatim}
|
|
||||||
|
|
||||||
Notice that the folder ``super secret stuff'' has spaces in the title. Bash will recognize a space as marking the next option, so if we used that command without quotation marks Bash would give us an error saying there are too many arguments or that it doesn't understand the option ``secret''. This is one reason to avoid naming files or directories with spaces and why a lot of people use underscores instead of spaces.
|
Notice that the folder ``super secret stuff'' has spaces in the title. Bash will recognize a space as marking the next option, so if we used that command without quotation marks Bash would give us an error saying there are too many arguments or that it doesn't understand the option ``secret''. This is one reason to avoid naming files or directories with spaces and why a lot of people use underscores instead of spaces.
|
||||||
|
|
||||||
@ -195,7 +208,9 @@ These are the most basic examples of wildcard usage, but they have sufficed for
|
|||||||
|
|
||||||
\subsection{Working with Files and Directories}
|
\subsection{Working with Files and Directories}
|
||||||
|
|
||||||
Bash has a number of commands for working with files and directories. The first is \texttt{touch} which will create a file if it doesn't exist, or will update the date and time it was modified if it does exist.\footnote{I admit, I'm a little confused as to the purpose of this command, and have never found a use for it. It is probably a legacy from the early days of Linux or possbily Unix, and I have never had the time—or the amount of curiosity required—to investigate it.}
|
Bash has a number of commands for working with files and directories. Many of them do similar but slightly different things, so the time you invest in learning how they work and understanding their options will pay off in the long run, because you will have the exact tool that you need, and you can avoid the digital problem of trying to eat soup with a fork.
|
||||||
|
|
||||||
|
\paragraph{touch} The most basic command is probably \texttt{touch} which will create a file if it doesn't exist, or will update the date and time it was modified if it does exist.\footnote{I admit, I'm a little confused as to the purpose of this command, and have never found a use for it. It is probably a legacy from the early days of Linux or possbily Unix, and I have never had the time—or the amount of curiosity required—to investigate it.}
|
||||||
|
|
||||||
\paragraph{cat} A command I do find a lot of use for however is \texttt{cat}, which is short for ``concatenate''. This command can also create files and add content to them, but it can also add content to existing files. But the thing I find it most useful for is simply displaying the contents of a file, which I use a lot when examining log files.
|
\paragraph{cat} A command I do find a lot of use for however is \texttt{cat}, which is short for ``concatenate''. This command can also create files and add content to them, but it can also add content to existing files. But the thing I find it most useful for is simply displaying the contents of a file, which I use a lot when examining log files.
|
||||||
|
|
||||||
@ -209,31 +224,25 @@ Notice that we are using a redirect symbol here (\texttt{>}) to push your conten
|
|||||||
|
|
||||||
\paragraph{more}
|
\paragraph{more}
|
||||||
|
|
||||||
\paragraph{mkdir} To make a directory you can use the \texttt{mkdir} command, which is pretty straightforward. You can also create subdirectories by specifying the path to the subdirectory you want to create. For example, \texttt{mkdir 1/2/3} will create a directory named ``3'' in that path, provided that directories 1 and 2 exist in the first place. If they don't, \texttt{mkdir} will return an error.
|
\paragraph{mkdir} To make a directory you can use the \texttt{mkdir} command, which is pretty straightforward. You can also create subdirectories by specifying the path to the subdirectory you want to create. For example, \texttt{mkdir dir1/dir2/dir3} will create a directory named ``dir3'' in that path, provided that directories ``dir1'' and ``dir2'' exist in the first place. If they don't, \texttt{mkdir} will return an error.
|
||||||
|
|
||||||
\paragraph{cp} If you want to make a copy of a file, use the \texttt{cp} command. Its syntax is pretty straightfoward: just specify the file you want to copy and then specify the name of the copied file. You can also use paths as well, so \texttt{cp 1/2/a.txt 3/4/b.txt} will go to directory ``1'' and then to directory ``2'' and copy the file ``a.txt'' to directory ``4'' located in directory ``3'' and rename it as ``b.txt''. Again, all those directories must exist in the first place, or \texttt{cp} will return an error.
|
\paragraph{cp} If you want to make a copy of a file, use the \texttt{cp} command. Its syntax is pretty straightfoward: just specify the file you want to copy and then specify the name of the copied file. You can also use paths as well, so \texttt{cp 1/2/a.txt 3/4/b.txt} will go to directory ``1'' and then to directory ``2'' and copy the file ``a.txt'' to directory ``4'' located in directory ``3'' and rename it as ``b.txt''. Again, all those directories must exist in the first place, or \texttt{cp} will return an error.
|
||||||
|
|
||||||
\paragraph{mv} To move a file, use the \texttt{mv} command. Just specify the name of the file you want to move, and then the path you want to move it to. Interestingly, Linux does not have a command for renaming a file, but you can use the \texttt{mv} command to rename a file by not specifying a new path. Take a look at the following examples:
|
\paragraph{mv} To move a file, use the \texttt{mv} command. Just specify the name of the file you want to move, and then the path you want to move it to. Interestingly, Linux does not have a command for renaming a file, but you can use the \texttt{mv} command to rename a file by not specifying a new path. Take a look at the following examples:
|
||||||
|
|
||||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Examples of the mv Command}]
|
\input{include/mv_examples}
|
||||||
mv cat.txt bat.txt
|
|
||||||
mv cat.txt animals/mammals
|
|
||||||
mv cat.txt animals/mammals/bat.txt
|
|
||||||
\end{Verbatim}
|
|
||||||
|
|
||||||
The command in line 1 simply renames the file ``cat.txt'' to ``bat.txt'' and leaves it in the same directory. The command in line 2 moves the file ``cat.txt'' to the subdirectory ``mammals'' which is located in the subdirectory ``animals'' which itself is a subdirectory of the current directoy. The third command is a combination of the first two: it both moves the ``cat.txt'' file and also renames it as ``bat.txt''.
|
The command in line 1 simply renames the file ``cat.txt'' to ``bat.txt'' and leaves it in the same directory. The command in line 2 moves the file ``cat.txt'' to the subdirectory ``mammals'' which is located in the subdirectory ``animals'' which itself is a subdirectory of the current directoy. The third command is a combination of the first two: it both moves the ``cat.txt'' file and also renames it as ``bat.txt''.
|
||||||
|
|
||||||
\paragraph{rmdir} To remove a directory, just use the \texttt{rmdir} command. There is one caveat with this command, however: the directory must be empty, because this command only works on empty directories.
|
\paragraph{rmdir} To remove a directory, just use the \texttt{rmdir} command. There is one caveat with this command, however: the directory must be empty, because this command only works on empty directories. To remove a directory that \textit{isn't} empty (which means first removing all its contents and then finally removing the directory), you'll need to use the \texttt{rm} command.
|
||||||
|
|
||||||
\paragraph{rm} To remove a file, use the \texttt{rm} command which does take wildcards. For example, this command:
|
\paragraph{rm} To remove a file, use the \texttt{rm} command with the name of the file as an argument. The \texttt{rm} does take wildcards by the way, which means that you can do a lot of work (or a lot of damage) with very little effort. For example, this command:
|
||||||
|
|
||||||
\begin{Verbatim}[]
|
\input{include/rm_log}
|
||||||
rm *.log
|
|
||||||
\end{Verbatim}
|
|
||||||
|
|
||||||
will remove \textit{all} files in your current directory that have a \texttt{.log} extension. The \texttt{rm} command doesn't have a \texttt{stdout}; if it is successful in deleting the file or files it was directed to delete, it just exits quietly without saying anything. And unlike just about every GUI out there, the Linux command line does not have a trash can or recycling bin that deleted files go to. When you delete a file using \texttt{rm}, it's just gone forever, and there is no easy way to get it back.\footnote{You \textit{can} recover the contents of a deleted file if you have the right tools and you just deleted it, but that's pretty advanced stuff. It's better to not delete things you are unsure of and to keep backups. On the other hand, if you really want to get rid of files in a way that people with the skills and the time and inclination can recover, use the \texttt{shred} command.}
|
will remove \textit{all} files in your current directory that have a \texttt{.log} extension. The \texttt{rm} command doesn't have a \texttt{stdout}; if it is successful in deleting the file or files it was directed to delete, it just exits quietly without saying anything. And unlike just about every GUI out there, the Linux command line does not have a trash can or recycling bin that deleted files go to. When you delete a file using \texttt{rm}, it's just gone forever, and there is no easy way to get it back.\footnote{You \textit{can} recover the contents of a deleted file if you have the right tools and you just deleted it, but that's pretty advanced stuff. It's better to not delete things you are unsure of and to keep backups. On the other hand, if you really want to get rid of files in a way that people with the skills and the time and inclination can recover, use the \texttt{shred} command.}
|
||||||
|
|
||||||
If you are accumstomed to using a GUI, and the thought of wiping out a bunch of files without having a chance to think about it makes you nervous, you can always use interactive mode.
|
If you are accumstomed to using a GUI, and the thought of wiping out a bunch of files without having a chance to think about it makes you nervous, you can always use interactive mode. There are two switches for the interactive mode. The first is \texttt{-i} which prompts you to confirm you want to remove every single file. There is also the \texttt{-I} switch, which will prompt you once when removing more than three files, or when removing recursively.
|
||||||
|
|
||||||
\section{Two More Important Things}
|
\section{Two More Important Things}
|
||||||
|
|
||||||
|
|||||||
3
006/include/cd.tex
Normal file
3
006/include/cd.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ cd ..
|
||||||
|
\end{Verbatim}
|
||||||
3
006/include/cd_doc_sss.tex
Normal file
3
006/include/cd_doc_sss.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ cd /Documents/"super secret stuff"
|
||||||
|
\end{Verbatim}
|
||||||
3
006/include/cd_documents.tex
Normal file
3
006/include/cd_documents.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ cd Documents
|
||||||
|
\end{Verbatim}
|
||||||
3
006/include/cd_up.tex
Normal file
3
006/include/cd_up.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ cd ../..
|
||||||
|
\end{Verbatim}
|
||||||
5
006/include/mv_examples.tex
Normal file
5
006/include/mv_examples.tex
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Examples of the mv Command}]
|
||||||
|
$ mv cat.txt bat.txt
|
||||||
|
$ mv cat.txt animals/mammals
|
||||||
|
$ mv cat.txt animals/mammals/bat.txt
|
||||||
|
\end{Verbatim}
|
||||||
3
006/include/rm_log.tex
Normal file
3
006/include/rm_log.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ rm *.log
|
||||||
|
\end{Verbatim}
|
||||||
Loading…
Reference in New Issue
Block a user