If you weren't here previously, and don't have a bunch of stuff in here to play with already, to make the following examples I have prepared work, you could run these commands
mkdir playroom
cd playroom
echo $USER > name
echo chocolate > "shopping list"
mkdir numbers
touch numbers/{1..100}
1. What does mv do, if you provide exactly two words (ignoring any options, such as the -v option, which I like (words after the first word of a command can be called "arguments", but we don't need to fight about it), and the first one is the name (or more accurately, the path) of a file that does exist, and the second one is not the name of an existing file
so mv will complain that the last argument is not a directory, because you would lose at least one file otherwise, as two files can't have the same name
so it tried to move the directory three into the directory numbers, (or to rename ./three to numbers/three) exactly as we asked, instead of trying to move numbers into three
but you already have a file called three in there so it failed - your file didn't get overwritten
which is good
you could just specify a different name like this (sorry I should be using the -v flag!)
@Zanna So mv x y and mv -t y x don't mean quite the same thing. y need not identify a directory in mv x y and if it doesn't then x is renamed to y instead of being renamed to y/x (i.e., instead of being moved into y), but in mv -t y x it is required that y identify a directory. man mv summarizes the -t syntax as:
@BeastOfCaerbannog well, the numbers directory exists
@EliahKagan thank you :) :)
if I remember rightly, last time we had an example where mv overwrote a file - if you mv some-file file-that-existed-already, the contents of file-that-existed-already get replaced with the contents of some-file
> It is not UNIX’s job to stop you from shooting your foot. If you so choose to do so [sic], then it is UNIX’s job to deliver Mr. Bullet to Mr Foot in the most efficient way it knows.
what about if you mv a file into a directory that already has a file with the same name (actually we just saw mv refuse to do that when the file we were trying to move in was a directory and there was a non-directory with the same name there already, but it might not be the same with two non-directories)
As long as the destination exists, mv will either copy the source into it (when the destination is a directory) or will overwrite it (when the destination is a file). It doesn't matter if the destination is in the same directory or not.
I find the tree command useful for seeing a whole directory tree. (It is not installed by default on all flavors and releases of Ubuntu, but it is provided by the tree package.)
@terdon Note, though, that the destination being a directory does not mean no file will be lost, because the destination may itself contain a file of the same name as the file being moved, and if that file is not itself a directory then it will be replaced. (If it is a directory then mv gives an error about not being able to overwrite a directory with a non-directory.)
Yeah. When you press Ctrl+O, you are prompted to tell nano how you want to name the file. Since you gave nano a name already, it shows that name. You can just press enter to have it use that name.
We've always run a bit over before and there's a half-hour gap before the next class, so I assume it is okay to wrap up rather than stopping immediately.
In regex `[1-9]*` matches zero or more of any of the characters 1, 2, 3, 4, 5, 6, 7, 8 or 9 Here, it matches exactly one character which can be 1, 2, 3, 4, 5, 6, 7, 8 or 9, and any number of any characters at all after that.
The issue is that [1..9] matches a character that is a 1 or a . or a . or a 9 (which is the same as matching a 1 or a . or a 9, since . is the same as .).
For some reason, some people seem to add the -r and -f options every time they use rm. That's bad! The -r option makes rm recursive, so that it can remove directories and their contents. Obviously, if you mess up and type the wrong thing as an argument, you would lose a lot more data with -r than without. So you should only use -r when you're sure you want to completely and permanently remove a directory.
-f prevents rm from prompting the user before deleting files it thinks you might not have intended to delete and from complaining about files you've specified not existing. I just never use that option at all, but it is useful for non-interactive scripts.
zanna@peach:~/playroom$ ls numbers
four one three three2 two
zanna@peach:~/playroom$ mkdir words
zanna@peach:~/playroom$ cp numbers/* words
cp: -r not specified; omitting directory 'numbers/three2'
zanna@peach:~/playroom$ ls words
four one three two
@jokerdino yes, only it doesn't remove the files you already had
less is /usr/bin/less man is hashed (/usr/bin/man) mv is hashed (/bin/mv) ls is aliased to `ls --color=auto' cd is a shell builtin type is a shell builtin
cd and type are built into the shell. Commands that are shell builtins don't have individual man pages (their man page can be accessed with man bash, but it's extremely long (you may find it easier to read the Bash manual online) but you can usually run help command to get information about how to use them. For example
less is /usr/bin/less less is /bin/less man is /usr/bin/man mv is /bin/mv ls is aliased to `ls --color=auto' ls is /bin/ls cd is a shell builtin type is a shell builtin