Abstract
This uses knitr to interleave shell commands and output, using the CRMDA style sheet.Prompt might be verbose
pauljohn:Documents/Projects $
On some it is very lean, just the dollar sign
$
Prompt is configurable, it is a good exercise for somebody who has used the Terminal for a week or two on a daily basis.
$ whoami
output: pauljohn
$ echo $USER
output: pauljohn
echo: prints out a value to the screen
whoami
.whoami
existed until I watched an SC video.* In the standard shell, variables in *the environment* are named with capitals, like "USER"
* but to access (retrieve) we need to add dollar sign
$ pwd
pwd: print working directory
$ cd
* Will see later that cd is a multipurpose command.
$ pwd
output: /home/pauljohn/GIT/github/sc_shell/notes
$ echo $HOME
output: /home/pauljohn
Know what HOME ought to be? Can set manually within the current shell’s session.
export HOME="/c/Users/pauljohn"
export HOME="/c/Users/$USER"
export: A BASH shell command that takes the following value and places it into the environment for the duration of the session.
* A more permanent and direct approach is to create an environment variable within the Windows system, which Git BASH can then inherit. This can be done in Control Panel -> System menu, but it can also be done in a DOS Command box:
$ setx HOME "%USERPROFILE%"
history
$ echo $SHELL
output: /bin/bash
$ env
whoami
or echo $USER
or echo $HOME
.$ ls
I’m unable to show you my color-coded command line in this document because the colors are lost in the document compilation process. But can show you in person :)
$ ls --color=always
Short form arguments with ls
are -l
, -a
, -S
, -1
, -F
See why color-coded output in the Terminal was a major breakthrough?
$ ls --color=never
output: kutils.css
output: ou_swc_files
output: rmd2html.sh
output: shell-1.html
output: shell-1.Rmd
output: shell-2.aux
output: shell-2.html
output: shell-2.html~
output: shell-2.log
output: shell-2.org
output: shell-2.org~
output: shell-2.out
output: shell-2.Rmd
output: shell-2.tex
output: shell-2.tex~
output: shell-2.toc
output: shell-3.html
output: shell-3.html~
output: shell-3.org
output: shell-3.org~
output: shell.html
output: shell.Rmd
output: test_dummy.html
output: #test_dummy.Rmd#
output: test_dummy.Rmd
output: test_dummy.Rmd~
output: tmpout
$ ls --color=never -F
output: kutils.css
output: ou_swc_files/
output: rmd2html.sh*
output: shell-1.html
output: shell-1.Rmd
output: shell-2.aux
output: shell-2.html
output: shell-2.html~
output: shell-2.log
output: shell-2.org
output: shell-2.org~
output: shell-2.out
output: shell-2.Rmd
output: shell-2.tex
output: shell-2.tex~
output: shell-2.toc
output: shell-3.html
output: shell-3.html~
output: shell-3.org
output: shell-3.org~
output: shell.html
output: shell.Rmd
output: test_dummy.html
output: #test_dummy.Rmd#
output: test_dummy.Rmd
output: test_dummy.Rmd~
output: tmpout/
$ man ls
ls
lists everything by default. But it might be used to list
ls a*
ls *.Rmd
The symbol * matches anything, any number of times.
Shell globs are easy and quick, but not very powerful. If you move further into the command line interface (or programming in general), the “regular expressions” will come into play.
-l
and -a
* Default will not list "hidden" items, things that begin with period
$ ls -a
output: .
output: ..
output: kutils.css
output: ou_swc_files
output: .Rhistory
output: rmd2html.sh
output: shell-1.html
output: shell-1.Rmd
output: shell-2.aux
output: shell-2.html
output: shell-2.html~
output: shell-2.log
output: shell-2.org
output: shell-2.org~
output: shell-2.out
output: shell-2.Rmd
output: shell-2.tex
output: shell-2.tex~
output: shell-2.toc
output: shell-3.html
output: shell-3.html~
output: shell-3.org
output: shell-3.org~
output: shell.html
output: shell.Rmd
output: test_dummy.html
output: .#test_dummy.Rmd
output: #test_dummy.Rmd#
output: test_dummy.Rmd
output: test_dummy.Rmd~
output: tmpout
$ ls -l
output: total 2440
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout
$ ls -la
output: total 2452
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 14 17:48 .
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 13 10:44 ..
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files
output: -rw-rw-r-- 1 pauljohn pauljohn 822 Nov 14 09:03 .Rhistory
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: lrwxrwxrwx 1 pauljohn pauljohn 35 Nov 14 09:03 .#test_dummy.Rmd -> pauljohn@delllap-16.3060:1478924101
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout
ls
, hopefully you see at least one directory. Suppose that’s called “Documents”$ ls Documents
* If we are lucky, Documents has another directory, say "Papers" inside it
$ ls Documents/Papers
$ ls ..
$ ls ../..
$ ls /
$ /c/
If we set the working directory as $HOME with
$ cd
Then inspecting a sub-folder with
$ ls Documents/Papers
is equivalent to using a full, absolute path
$ ls /c/Users/pauljohn/Documents/Papers
The “absolute path” always begin with “/” and it explicitly shows each directory name.
Many ways to show HOME (if working directory is somewhere else)
$ ls $HOME
Is the same as
$ ls ~
And relative PATH will work in an understandable way
$ ls ~/Documents
cd
(without arguments) returns user to $HOMEcd
can change the specified working directorycd
examples everybody should try.ls -F
to find a directory name (thing with slash on end), e.g. Desktop
, then$ cd Desktop
$ pwd
$ ls -F
cd: change the working directory
If ls
shows there is another directory, then cd
into it. Run ls
again
Run cd
to go back to HOME.
cd Des
and stop typing, and then hit TAB, does it auto-complete the word Desktop?After all of that TABing, you shoud have a prompt that looks like this
$ cd Desktop/whatever_subdir
* hit enter, then run `pwd` to make sure you are in there
* perhaps the prompt changed to let you know, without running pwd
$ cd ..
$ cd Desktop
$ mkdir sc-20161115
mkdir: make a new directory
ls
Change into that directory, (don’t forget TAB completion)!
recursive (nested) directories
By default, mkdir
is willing to create only one new “layer”.
mkdir Desktop/sc-20161115/topdir/middir/lowerdir
will be rejected.To create a hierarchy of directories in one command, add the -p
flag
$ mkdir -p Desktop/sc-20161115/topdir/middir/lowerdir
mkdir: creates a directory. Only adds “one level deeper”
mkdir -p: create recursively
Lets figure out how to see your new directory Desktop/sc-20161115 in your “Modern Graphical Operating System”.
Launch a file manager in the usual way (Windows Explorer, Mac Finder, Linux Nautilus, etc)
* Navigate to Desktop/sc-20161115
Terminal programs can launch those file managers
Git BASH for Windows includes a shortcut command. Type
$ explorer .
$ open .
* In both of these, "." means "Current Working Directory"
$ cd
$ mkdir -p Desktop/mistake
Check to see if the directory mistake is visible
inside the Terminal
in the graphical file manager program
Use the graphical file manager to create a directory inside mistake
.
Make sure you can see that from inside the terminal
Then create an empty file this way
$ cd Desktop/mistake
$ touch great_file.txt
touch: sets current time on a file. If no file exists, create emtpty file with that date.
Run ls -la
to make sure the file is there
Use the graphical file manager program to see if “great_file.txt” exists.
Does right-click “edit with” give you any candidate editors? We need a text editor. Not a Word Processor (Word, Libre Office), but rather a “flat text” editor. Save the file.
Back in the terminal, lets inspect what happened.
$ ls -la
$ cat great_file.txt
cat: opens file and displays it from top to bottom
There are editors that work well “in the terminal”, but using them is a lost art, except among programmers and truly devoted terminal-loving data scientists. My Mom could do this in 1985, you could too.
nano is available on most Mac and Linux systems, and it might be available in a Windows BASH shell program.
vi is an old old fast fast flat text editor I can demonstrate.
It will be launched often by programs like Git, so one must get some tolerance for it.
The get out of jail keystrokes: Esc : wq
(Yes, Escape, followed by a colon. If you watch the very bottom of the terminal, you get a hint it is accepting commands. Then type w
and q
(to “write” and “quit”)
I’m an Emacs enthusiast, but NOT in the terminal. That’s too severe without menus.
Ctl-x Ctl-c
to close it down.A part of the hard disk file storage can be thought of as ‘shared’ content between 2 separate systems.
Shell commands like “mkdir” and “cd” have obvious equivalents in the GUI File Manager
A benefit of the Terminal/Shell is that problems too big, which would overwhelm the GUI, can still be done.
There’s no “Trash Can” built into the shell
Default setup will not ask “do you really mean to delete that?” It will just do it.
There is a “safe delete” flag, -i
If that is included in usage of all file mover/destroyer functions, system will not follow your orders right away.
When I go to a new computer account, the first thing I do is insert a shell configuration that inserts -i
with all usages of rm
, cp
and mv
. (keywords: alias
and profile
).
rm
deletes thingscd
into directory that has the trash file we were fiddling with “great_file.txt”
Delete that file
$ rm great_file.txt
ls
* rm will refuse a request to delete a non-empty directory
* Error message will be something like
rm: cannot remove 'mistake': Is a directory
* Flags "-r" and "-f" override that resistance
* "**-r**": recursive
* "**-f**": force (don't bother me with warnings)
* If the mistake directory is still there, get rid of it
$ cd
$ cd Desktop
$ ls mistake
$ rm -rf mistake
next.
General syntax mv x y
x is the source
y is the target
If x is a directory, and
If y is a directory name that already exists, x is moved inside y.
$ mkdir mistake
* Spawn a few empty files in there
$ touch mistake/myfile1.txt
$ touch mistake/myfile2.txt
$ ls -la mistake
output: total 8
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 .
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ..
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 14 17:48 myfile1.txt
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 14 17:48 myfile2.txt
$ ls -laF
output: total 2456
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 13 10:44 ../
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 mistake/
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files/
output: -rw-rw-r-- 1 pauljohn pauljohn 822 Nov 14 09:03 .Rhistory
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh*
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: lrwxrwxrwx 1 pauljohn pauljohn 35 Nov 14 09:03 .#test_dummy.Rmd -> pauljohn@delllap-16.3060:1478924101
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout/
$ ls -laF
output: total 2456
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 13 10:44 ../
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 mistake/
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files/
output: -rw-rw-r-- 1 pauljohn pauljohn 822 Nov 14 09:03 .Rhistory
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh*
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: lrwxrwxrwx 1 pauljohn pauljohn 35 Nov 14 09:03 .#test_dummy.Rmd -> pauljohn@delllap-16.3060:1478924101
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout/
$ mv mistake success
$ ls -laF
output: total 2456
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 13 10:44 ../
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files/
output: -rw-rw-r-- 1 pauljohn pauljohn 822 Nov 14 09:03 .Rhistory
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh*
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 success/
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: lrwxrwxrwx 1 pauljohn pauljohn 35 Nov 14 09:03 .#test_dummy.Rmd -> pauljohn@delllap-16.3060:1478924101
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout/
Check that the files are still in there
$ ls -laF success
output: total 8
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ../
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 14 17:48 myfile1.txt
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 14 17:48 myfile2.txt
In previous example, the target directory “success” did not exist, so Shell understood what we needed.
If target directory did exist, then whole “mistake” directory would be moved into it.
$ mkdir wonderful
$ ls -F
$ # Move success into wonderful:
$ mv success wonderful
output: kutils.css
output: ou_swc_files/
output: rmd2html.sh*
output: shell-1.html
output: shell-1.Rmd
output: shell-2.aux
output: shell-2.html
output: shell-2.html~
output: shell-2.log
output: shell-2.org
output: shell-2.org~
output: shell-2.out
output: shell-2.Rmd
output: shell-2.tex
output: shell-2.tex~
output: shell-2.toc
output: shell-3.html
output: shell-3.html~
output: shell-3.org
output: shell-3.org~
output: shell.html
output: shell.Rmd
output: success/
output: test_dummy.html
output: #test_dummy.Rmd#
output: test_dummy.Rmd
output: test_dummy.Rmd~
output: tmpout/
output: wonderful/
$ ls -laF
output: total 2456
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 13 10:44 ../
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files/
output: -rw-rw-r-- 1 pauljohn pauljohn 822 Nov 14 09:03 .Rhistory
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh*
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: lrwxrwxrwx 1 pauljohn pauljohn 35 Nov 14 09:03 .#test_dummy.Rmd -> pauljohn@delllap-16.3060:1478924101
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout/
output: drwxrwxr-x 3 pauljohn pauljohn 4096 Nov 14 17:48 wonderful/
$ ls -laF wonderful
output: total 12
output: drwxrwxr-x 3 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 5 pauljohn pauljohn 4096 Nov 14 17:48 ../
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 success/
$ cd wonderful
$ mv success ~/
$ cd ..
Recall, “~”: Tilde is shorthand for $HOME
where we started.
$ mv ~/success .
$ ls -laF
output: total 2460
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 13 10:44 ../
output: -rw-rw-r-- 1 pauljohn pauljohn 7480 Nov 14 17:46 kutils.css
output: drwxrwxr-x 6 pauljohn pauljohn 4096 Nov 11 19:20 ou_swc_files/
output: -rw-rw-r-- 1 pauljohn pauljohn 822 Nov 14 09:03 .Rhistory
output: -rwxrwxr-x 1 pauljohn pauljohn 1182 Nov 11 08:38 rmd2html.sh*
output: -rw-rw-r-- 1 pauljohn pauljohn 733511 Nov 14 17:47 shell-1.html
output: -rw-rw-r-- 1 pauljohn pauljohn 22198 Nov 14 17:48 shell-1.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 6903 Nov 13 15:22 shell-2.aux
output: -rw-rw-r-- 1 pauljohn pauljohn 44626 Nov 13 15:21 shell-2.html
output: -rw-rw-r-- 1 pauljohn pauljohn 44623 Nov 13 15:16 shell-2.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 41563 Nov 13 15:22 shell-2.log
output: -rw-rw-r-- 1 pauljohn pauljohn 29842 Nov 14 17:18 shell-2.org
output: -rw-rw-r-- 1 pauljohn pauljohn 13993 Nov 13 13:04 shell-2.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 2488 Nov 13 15:22 shell-2.out
output: -rw-rw-r-- 1 pauljohn pauljohn 1431 Nov 11 19:31 shell-2.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 26446 Nov 13 15:22 shell-2.tex
output: -rw-rw-r-- 1 pauljohn pauljohn 16246 Nov 13 14:05 shell-2.tex~
output: -rw-rw-r-- 1 pauljohn pauljohn 0 Nov 13 15:22 shell-2.toc
output: -rw-rw-r-- 1 pauljohn pauljohn 16300 Nov 13 16:21 shell-3.html
output: -rw-rw-r-- 1 pauljohn pauljohn 12035 Nov 13 15:44 shell-3.html~
output: -rw-rw-r-- 1 pauljohn pauljohn 5629 Nov 13 16:25 shell-3.org
output: -rw-rw-r-- 1 pauljohn pauljohn 1416 Nov 13 15:33 shell-3.org~
output: -rw-rw-r-- 1 pauljohn pauljohn 719850 Nov 11 17:34 shell.html
output: -rw-rw-r-- 1 pauljohn pauljohn 286 Nov 11 08:38 shell.Rmd
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 success/
output: -rw-rw-r-- 1 pauljohn pauljohn 669702 Nov 14 09:02 test_dummy.html
output: lrwxrwxrwx 1 pauljohn pauljohn 35 Nov 14 09:03 .#test_dummy.Rmd -> pauljohn@delllap-16.3060:1478924101
output: -rw-rw-r-- 1 pauljohn pauljohn 3063 Nov 14 09:10 #test_dummy.Rmd#
output: -rw-rw-r-- 1 pauljohn pauljohn 2535 Nov 14 09:03 test_dummy.Rmd
output: -rw-rw-r-- 1 pauljohn pauljohn 21726 Nov 14 08:36 test_dummy.Rmd~
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 11 08:38 tmpout/
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 wonderful/
“.”: Period is shorthand for here!, the current working directory
$ if [ ! -d ~/Trash ]
$ then
$ mkdir ~/Trash
$ fi
Instead of running rm
on unwanted things, consider
$ mv wonderful ~/Trash
$ ls -laF ~/Trash
output: total 16
output: drwxrwxr-x 4 pauljohn pauljohn 4096 Nov 14 17:48 ./
output: drwxr-xr-x 82 pauljohn pauljohn 4096 Nov 14 17:48 ../
output: drwxr-xr-x 5 pauljohn pauljohn 4096 Jul 9 22:17 VBox/
output: drwxrwxr-x 2 pauljohn pauljohn 4096 Nov 14 17:48 wonderful/
mv x y
will rename a file x as y if y does not exist
mv x y
will move x into y if y is a directory
mv x y
will obliterate y if y is a file
y
can be a relative or absolute path
cp
is for Copy: enough different from mv
to be frustratingcp x y
# copies file x
to file name y
cp -R x y
# copies recursively directory x to yrecall I always have -i
on uses of rm, cp, and mv
Like mv, if y is a directory that exists, then x is moved within it.
mv
is that cp
will do nothing to copy a directory if you forget the -R.
$ cp success ~/Trash cp: omitting directory 'success'
# Big summary. We have reviewed
rm
remove (delete)mv
move / renamecp
: copy directories and filesecho $XYZ
prints out the contents of an environment variable XYZ
cat xyz
prints out the contents of a file named xyz
env
prints out the entire contents of the environment