Difference between revisions of "Linux Terminal - Files and Directories and Getting Around"

From Computer Science
Jump to: navigation, search
(Sample Session)
Line 33: Line 33:
  
 
=Sample Session=
 
=Sample Session=
Here is a transcript of the use of these commands on the CS server, showing how they work and what is printed on the screen.  Note that the part after the "cs299@cs:~> " is the part that was typed by the user - so the user first typed "pwd" and then enter, the system printed "/u1/class/cs299", and the system then printed the prompt "cs299@cs:~> " and waited for the user to type the next command.  You can also watch a [video demo].
+
'''In just a minute...'''
<pre>
+
 
cs299@cs:~> pwd
+
=Quiz=
/u1/class/cs299
+
An example quiz over this material -
cs299@cs:~> mkdir new-dir1
+
Fill in the blank, what is the shortcut or key used in the linux terminal for each of the following.
cs299@cs:~> mkdir new-dir2
+
* Press this key to execute a command:  
cs299@cs:~> nano hello.txt
+
* Keys that let you run a previously typed command again:
cs299@cs:~> ls
+
* Key to press to auto-complete a filename or command:
bin/  hello.txt  new-dir1/  new-dir2/  proto/
+
* Shortcut for current directory (one character):
cs299@cs:~> cp hello.txt new-dir1
+
* Shortcut for directory one level up from current:
cs299@cs:~> cp hello.txt new-dir2/hello2.txt
+
* Shortcut for your home directory (one character):
cs299@cs:~> ls new-dir1
+
* Shortcut for the top of the entire file system (one character):
hello.txt
+
* Characters to put around a filename that has spaces:
cs299@cs:~> ls new-dir2
+
* Wildcard character:
hello2.txt
+
 
cs299@cs:~> mv new-dir2 new-dir3
+
Fill in the blank, what is the linux command to do each of the following.
cs299@cs:~> ls
+
* See which other users are currently logged in:
bin/  hello.txt new-dir1/  new-dir3/  proto/
+
* Help about a command (manual):  
cs299@cs:~> rm hello.txt
+
* Change directory:
cs299@cs:~> ls
+
* Make a new directory:
bin/  new-dir1/  new-dir3/  proto/
+
* List directory contents:
cs299@cs:~> rmdir new-dir3
+
* Flag/option to use with previous command to list details of files:  
rmdir: failed to remove 'new-dir3': Directory not empty
+
* Copy file(s):
cs299@cs:~> rm new-dir3/hello2.txt
+
* Remove files:
cs299@cs:~> rmdir new-dir3
+
* Remove directory:
cs299@cs:~> ls
+
* Move or rename a file or directory:
bin/ new-dir1/  proto/
+
* A terminal text editor:  
</pre>
+
* Change your password:
 +
* Print out first few lines of a file:  
 +
* Change file permissions:
 +
* Display current system memory usage:  
 +
* See current time and date:  
 +
 
 +
Give the complete linux terminal command to complete each of the following tasks''Tasks such as these could be asked about.''
 +
* Create a new directory HELLO in your home directory:  
 +
* Copy the contents of jkinne's GREAT directory into your home directory:  
 +
* Change directory to your home directory:  
 +
* Check to see who is logged in:  
 +
* List the contest of the directory ~cs151/ including the sizes of the files:

Revision as of 16:31, 10 January 2020

This page is a part of the Linux and CS Systems - Getting Started. This page assumes you have your computer setup to connect to the CS server, or have the appropriate software installed on your computer to run commands. Go back to the Linux and CS Systems Getting Started main page if you don't have our system setup yet.

Basic idea The linux terminal is used to type commands to control your computer and files. Everything that you can do graphically on your computer (in Windows with File Explorer, on MacOS with Finder) you can do by typing commands instead.

Demo See [this link] for a video demonstrating the basics of getting around in the linux terminal.

Basic Commands

With the terminal you can create, copy, move, and delete files and directories. The following are the most important commands to do this.

  • cd - change directory
  • mkdir - make a new directory
  • ls - list directory contents (use option -l to see details)
  • cp - copy files
  • rm - remove files (be careful, there is no recycle bin or trash - once you delete, it's gone)
  • rmdir - remove directory
  • mv - move or rename a file or directory
  • nano - simple text editor

Getting Around

To "get around" in the terminal, use the following keys.

  • enter - a command is only executed when you press enter.
  • up and down arrows - lets you run a previously typed command again.
  • tab - if you are typing a filename, you can press tab to let the terminal auto-complete some part of it. This also works for command names (e.g., type mkdi and then tab).

The following are shortcuts for directories.

  • . - current directory
  • .. - directory one level up from where you are currently
  • ~ - your home directory
  • / - the top of the entire file system

The following are special notes about directory or file names.

  • "" - if you have a file name with spaces in it, then you put the file name within "". So you could do mkdir "Some Directory"
  • * - called a wildcard, used to specify all file names that match some pattern. To list all files that end in ".pdf" you could type ls *.pdf.

Sample Session

In just a minute...

Quiz

An example quiz over this material - Fill in the blank, what is the shortcut or key used in the linux terminal for each of the following.

  • Press this key to execute a command:
  • Keys that let you run a previously typed command again:
  • Key to press to auto-complete a filename or command:
  • Shortcut for current directory (one character):
  • Shortcut for directory one level up from current:
  • Shortcut for your home directory (one character):
  • Shortcut for the top of the entire file system (one character):
  • Characters to put around a filename that has spaces:
  • Wildcard character:

Fill in the blank, what is the linux command to do each of the following.

  • See which other users are currently logged in:
  • Help about a command (manual):
  • Change directory:
  • Make a new directory:
  • List directory contents:
  • Flag/option to use with previous command to list details of files:
  • Copy file(s):
  • Remove files:
  • Remove directory:
  • Move or rename a file or directory:
  • A terminal text editor:
  • Change your password:
  • Print out first few lines of a file:
  • Change file permissions:
  • Display current system memory usage:
  • See current time and date:

Give the complete linux terminal command to complete each of the following tasks. Tasks such as these could be asked about.

  • Create a new directory HELLO in your home directory:
  • Copy the contents of jkinne's GREAT directory into your home directory:
  • Change directory to your home directory:
  • Check to see who is logged in:
  • List the contest of the directory ~cs151/ including the sizes of the files: