# The Command Line - More Commands

### The cat command

This command allows one to print to the screen the contents of a text file.

Example:

• To print the text found in the file my_poem.txt:
cat my_poem.txt

### The cp command

This command allows one to make a copy of a file or directory

Examples:

• To make a copy of the file named some_existing_file in the current directory, naming the new copy new_copy and placing it in the same directory:
cp some_existing_file new_copy
• To make a copy of the file named some_existing_file in the current directory, naming the new copy newcopy and placing it in the parent directory:
cp some_existing_file ../newcopy
• To make a copy of the file some_file that exists in the directory /Users/student00/project1/, giving the copy with the same name and placing it in the directory /Users/student00/project2/, presuming the current directory is /Users/student00/:
cp /Users/student00/project1/some_file /Users/student00/project2/
To do the same thing more briefly by using relative paths:
cp ./project1/some_file ./project2/
• To make a copy of a directory named some_existing_directory and all of its contents -- assuming some_existing_directory resides in the current directory -- and naming the new directory new_directory and placing it also in the current directory:
cp -r some_existing_directory new_directory
The cp command doesn't copy all of the contents of a directory by default. We tell the cp command that we want it to copy all of the contents by including the "-r" flag.

### The mv command

This command allows one to rename and/or relocate a file.

Examples:

• To rename the file junk found in the current directory to the file precious:
mv junk precious
• To move the file precious from the current directory to a directory treasure also in the current directory:
mv precious treasure
• To move the file jewel to a directory casket also in the current directory and rename it to amethyst:
mv jewel casket/amethyst
• To move a directory bag_of_diamonds to a directory safety_deposit in the parent directory, while renaming it rainy_day_fund:
 mv bag_of_diamonds ../safety_deposit/rainy_day_fund

### The rm command

This command allows one to remove an existing file.

Example:

• To remove the file named junk.txt from the current directory:
rm junk.txt

### The mkdir command

This command allows one to make a new directory of a given name.

Examples:

• To make a directory named alice in the current directory:
mkdir alice
• To make a directory named bob in the parent directory:
mkdir ../bob

### The rmdir command

This command allows one to remove an existing directory.

Example:

• To remove the directory empty_folder from the current directory:
rmdir empty_folder

### The man command

This command allows you to learn about any other command. The metaphor here would be looking up the command in question in the "manual". Invoking man will bring up text detailing the command in question, citing what it does, how it and it's arguments should be called, what happens when optional flags are provided, and so on...

Example:

• To learn more about the java compiler command, javac:
man javac

### The nano editor

nano is a simple text editing program that will run in a terminal/console window. Note, in such a program, one obviously doesn't have the benefit of a mouse. Thus, moving the cursor around must be done with the arrow keys and other keyboard shortcuts. Copying and pasting, searching for specified text, indenting, and other operations are all handled in this way -- through the use of keyboard shortcuts.

Note: The nano editor does not come as a standard part of the windows operating system, so to use it in this environment you must install it first. (See nano for windows)

Example

• To create a new text file called myTextFile and immediately start editing it:
nano myTextFile

Once you are in editing mode, type "Ctrl-g" to bring up the help document that details all of the keyboard shortcuts you can perform within the editor itself.

### The vim editor

vim is a much more powerful text editing program that also runs in a terminal/console window. The learning curve, however, is substantially steeper. If you want to learn how to use it, this interactive tutorial is a nice gentle way to start...

Note: The vim editor does not come as a standard part of the windows operating system, so to use it in this environment you must install it first. (See vim for windows)

Example

• To create a new text file called myTextFile and immediately start editing it:
vim myTextFile
Your are strongly encouraged to read through the aforementioned tutorial (or some other tutorial on vim) before executing something similar to the above -- if for no other reason than learning how to exit the editor (it's not obvious)!