Linux - System Setup and Linux Terminal - Files and Directories and Getting Around: Difference between pages

From Computer Science at Indiana State University
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
This page is meant to help you get your computer ready to connect to the CS server.   
''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 commandsGo back to the Linux and CS Systems Getting Started main page if you don't have our system setup yet.''


''Note - this page needs updating, was last updated in 2020.''
'''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.


=CS User Accounts=
'''Demo''' See [https://www.youtube.com/watch?v=ynETRS3KGGs&feature=youtu.be this demo video] for a video demonstration of the topics on this page, including running the commands on the ISU CS serverYou should start reading through this page before watching the video.
Below we guide you through getting software setup on your computerIn order to connect to the CS server you will also need your CS user account; see [[CS accounts]].  


=Your Personal Computer=
=Basic Commands=
You need to have access to a computer that you can install the following on - (a) ''terminal program'' used to connect to the CS server and execute commands on the CS server, (b) ''file transfer program'' for transferring files between your computer and the CS server, (c) ''text editor'' to use on your computer.
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


'''The minimum to get you started is to get a terminal program working.'''  You can use the terminal program to connect to the CS server and do your work in the terminal. Eventually you will want to get setup with a file transfer program and text editor on your personal computer, but you can get started just with a terminal.
=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).


==Terminal Program==
The following are shortcuts for directories.
A terminal program allows you to type commands to run programs and view files and folders on your computer, and allows you to do the same on a remote computer (i.e., the CS server) after you have connected to it.
* . - current directory
* .. - directory one level up from where you are currently
* ~ - your home directory
* / - the top of the entire file system


If you are using MacOS, Linux, or an up to date Windows system then you already have a terminal program installedYou don't need to install anything, you just need to follow some steps to use the terminal program that is already installed.
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 <code>mkdir "Some Directory"</code>
* * - called a wildcard, used to specify all file names that match some pattern.  To list all files that end in ".pdf" you could type <code>ls *.pdf</code>.


''Note - the first time you connect to the CS server with a terminal or file transfer program, you will be notified that the identity of cs.indstate.edu cannot be verified, an ECDSA key will be displayed, and you will be asked if you still want to connect.  Type or click yes.''
=Sample Quiz=
''An example quiz over this material.  After watching the video and trying the commands out yourself to make sure you understand.''


* '''On Windows''' - you have two options - use the built-in ssh client if your Windows computer is up to date, or install a terminal program. [https://youtu.be/kqkgXhKjAP8 video demo of both options from around 2020]
Fill in the blank, what is the shortcut or key used in the linux terminal for each of the following.
** ''Built-in ssh'' - Click the start button, type cmd, click Command Prompt to open the command prompt program, then in this window type "ssh username@cs.indstate.edu" and then enter (but with your CS username) to start your connection to the CS server.  Note that you need an up to date Windows 10 for the ssh program to be pre-installed.
* Press this key to execute a command:
** ''Putty'' -  [https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html download] [http://cs.indstate.edu/FAQ/PuTTY/ Installing Putty on Windows].  Putty has some features that the built-in ssh client does not; either are sufficient to get started.
* Keys that let you run a previously typed command again:
* '''On Mac OS''' - ''Built-in Terminal'' - [https://youtu.be/xtDFNGe6Gy4 video demo] Use the built-in Terminal program in Mac OS to connect to the cs server, and you can also use the Terminal program to run commands on your local computer. You open the terminal by opening Finder, then click on Applications, then click on Utilities, then open Terminal.  When you get the terminal program open, you can login remotely to the CS server by typing "ssh username@cs.indstate.edu" and enter/return (but with your CS username).
* Key to press to auto-complete a filename or command:
* '''On Chromebook''' - Install the ''Secure Shell'' app - [https://youtu.be/IjNdGu36bok video demo], [https://chrome.google.com/webstore/detail/secure-shell-app/pnhechapfaindjhompbnflcldabbghjo?hl=en Download] [https://chrome.google.com/webstore/detail/secure-shell-extension/iodihamcpbpeioajjeobimgagajmlibd Chrome Extension] [https://mooselander.com/secure-shell-app-setup-and-profiles/ configuration]
* Shortcut for current directory (one character):
* '''On Linux''' - ''Built-in Terminal'' - Similar to MacOS, a terminal program is already built-in.  How to get to the terminal program (also called the "shell") depends on which distribution you are running - ask the internet where to find the terminal program for your distribution.  When you get the terminal program open, you can login remotely to the CS server by typing "ssh username@cs.indstate.edu" and enter/return (but with your CS username).
* 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:


==File Transfer Program==
Fill in the blank, what is the linux command to do each of the following.
You will eventually need to transfer files between your personal computer and the CS server.  Most OSes have built-in support to do this, but there are other options that are easier to use.  We recommend choosing a file transfer program to install.  For Windows or Mac you will download the installer to install the program.  If you are using Linux or Chromebook, see the sections below about these environments.
* Change directory:
* [https://cyberduck.io/download/ CyberDuck] - works for MacOS or Windows, is freeware, click the large "Download for Windows" or "Download for macOS" in the middle of the page.
* Make a new directory:
* [https://winscp.net/eng/download.php WinSCP] - works for Windows, scroll past ads and click the "Download WINSCP" button.
* List directory contents:
* [https://www.gftp.org/ gFTP] - good option for Linux, see below about Linux for how to install.
* 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:


''Note - the first time you connect to the CS server with a terminal or file transfer program, you will be notified that the identity of cs.indstate.edu cannot be verified, an ECDSA key will be displayed, and you will be asked if you still want to connect.  Type or click yes.''
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:


''Note - make sure to choose "sftp" as opposed to "ftp" when connectingftp is not encrypted and is disabled on the CS server (it will not work)sftp is encrypted and is what we use.''
=Sample HW=
The following might be used by your instructor as part of a HW assignment to verify that you are able to use the terminal to create and copy files and view the contents of directories.
 
Create a directory to store files for this HW.  If you are given this assignment in one of your courses you will be told which directory to use.  We refer to this directory as HW_dir.
# Copy /var/junk/shakespeare.txt into your HW_dir.
# Copy /proc/cpuinfo into your HW_dir, but make the file name cpuinfo-HW.txt
# Copy /proc/version into your HW_dir, but make the file name version-HW.txt
# Create a file info.txt in your HW_dir.  Inside the file fill in the following information.
#* Name (what you want to be called):
#* Why you are taking this course:
#* Anything you are worried about (wrt this course):
#* Most excited about (wrt this course):
# In the terminal, browse to the directory /net/web, run the command <code>ls -l cs151</code>, and copy the output of that command.  Go back to your HW_dir, edit your info.txt file, and paste into the file.
# Copy ~cs151/hello.txt into your HW_dir
 
=Sample Session=
The following is a transcript of the commands and screen output from the youtube video linked at the top of this pageBlank lines have been put in after each command.  You can read through the transcript and think about what you think the output will be after each command is entered, and check that this is how it shows in the transcript. 
 
Note that a few text files have been edited using the nano text editor.  When the nano text editor was used the editing of the file itself is not part of the transcript.  Note that the transcript is for the user jkinne@isuad@indstate.edu logged in to the CS server.
<pre>
cs15100@cs:/u1/class/cs15100> ls
Desktop/  proto/
 
cs15100@cs:/u1/class/cs15100> ls -l
total 8
drwxr-xr-x 2 cs15100 class 4096 Jan  8 21:17 Desktop/
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/
 
cs15100@cs:/u1/class/cs15100> cd Desktop
 
cs15100@cs:/u1/class/cs15100/Desktop> ls
 
cs15100@cs:/u1/class/cs15100/Desktop> cd ..
 
cs15100@cs:/u1/class/cs15100> mkdir hello
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/
 
cs15100@cs:/u1/class/cs15100> nano hello.txt
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  hello.txt  proto/
 
cs15100@cs:/u1/class/cs15100> ls -l
total 16
drwxr-xr-x 2 cs15100 class 4096 Jan  8 21:17 Desktop/
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:37 hello/
-rw-r--r-- 1 cs15100 class  60 Jan 10 11:43 hello.txt
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/
 
cs15100@cs:/u1/class/cs15100> mv hello.txt Desktop
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/
 
cs15100@cs:/u1/class/cs15100> ls Desktop
hello.txt
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/
 
cs15100@cs:/u1/class/cs15100> ls /
bin/  dev/  home/  lib64/      media/  net/  proc/  run/  srv/    swap  tmp/  u2/  var/
boot/  etc/  lib/  lost+found/  mnt/    opt/  root/  sbin/  store/  sys/  u1/  usr/  xsys/
 
cs15100@cs:/u1/class/cs15100> cd Desktop
 
cs15100@cs:/u1/class/cs15100/Desktop> ls /u1/class/cs15100
Desktop/  hello/  proto/
 
cs15100@cs:/u1/class/cs15100/Desktop> ls ~
Desktop/  hello/  proto/
 
cs15100@cs:/u1/class/cs15100/Desktop> cd /u1/junk/kinne
 
cs15100@cs:/u1/junk/kinne> ls
cs151Hello            Indianapolis-Weather-Station-USW00093819-1950-2018.csv  shakespeare_1000_lines.txt
GRCh38.p12.genome.fa interview-questions/                                    shakespeare.txt
hello.txt            shakespeare_1000_lines_tail.txt                        Terre_Haute_airport_93823-03868.csv


''Text-based sftp program that is already installed on many systems - see OS Specific Notes below''
cs15100@cs:/u1/junk/kinne> ls ~
Desktop/  hello/  proto/


==Text Editor==
cs15100@cs:/u1/junk/kinne> ls
Note that while you are using a terminal that is connected to the CS server you can use text-based editors - nano, emacs, vim, jove (see [[Linux Terminal - Text Editors]] for more on how to get started with these)You will eventually want to have a good text editor on your personal computer.  
cs151Hello            Indianapolis-Weather-Station-USW00093819-1950-2018.csv  shakespeare_1000_lines.txt
GRCh38.p12.genome.fa interview-questions/                                    shakespeare.txt
hello.txt            shakespeare_1000_lines_tail.txt                        Terre_Haute_airport_93823-03868.csv


The following are four good options that are cross-platform - can be installed on Mac, Windows, Linux, and Chromebook.  If you already use some other option (e.g., Visual Studio Code, Eclipse, Notepad++, or anything else that is used by programmers) feel free to keep using what you are already using.  Note that Word is ''not'' a text editor - it does not store files in plain text, which is what is needed for programming.
cs15100@cs:/u1/junk/kinne> cp cs151Hello ~
* [https://kate-editor.org/get-it/ Kate] - make sure to download the "release" installer.
* [https://www.sublimetext.com/ Submlime] - used by Luke May.
* [https://www.gnu.org/software/emacs/ Emacs] - used by Jeff Kinne, click "GNU/Linux", "Windows", or "MacOS" depending on your OS and follow the instructions. 
** For Windows, download is from https://ftp.gnu.org/gnu/emacs/windows/, choose the latest emacs-## folder to click on, then download the zip file at the bottom that ends in "-x86_64.zip", extract the zip to somewhere to keep the program (e.g., C:\Program Files\), then run the file runemacs.exe in the bin directory.
** For macOS, the easiest install is from https://emacsformacosx.com/
* [https://www.vim.org/download.php Vim] - used by Geoff Exoo.  For Windows, download and run the "self-installing executable".  For macOS download and run MacVim.dmg from https://github.com/macvim-dev/macvim/releases/latest
* VS Code
* ne (nice editor)


When starting a new text editor do an internet search for a tutorial to get you started; once you are comfortable with the basics do an internet search for a cheat sheet of keyboard shortcuts to help you remember them.
cs15100@cs:/u1/junk/kinne> cd ~


==Installing for Linux==
cs15100@cs:/u1/class/cs15100> ls
Most Linux distributions have their own package management systems, with the programs mentioned on this page being installable via the package management system. There often is a graphical interface to the package management system, and there is normally a text-based interface - you type commands on the terminal to install packages.  
cs151Hello Desktop/ hello/  proto/


''Debian'', ''Ubuntu'', and related Linux distributions use the APT package manager, and you can install the programs mentioned on this page by entering the following commands in the terminal.  Note that you will likely be asked in the terminal whether you want to install the package, you need to type Y and press enter.
cs15100@cs:/u1/class/cs15100> ls -l
<pre>
total 16
sudo apt update # makes sure APT has the latest information about packages available
-rw-r--r-- 1 cs15100 class  16 Jan 10 11:46 cs151Hello
sudo apt install emacs
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:44 Desktop/
sudo apt install kate
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:37 hello/
sudo apt install gftp
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/
sudo apt install vim
 
# Note - installing atom requires adding the repository where atom is kept
cs15100@cs:/u1/class/cs15100> nano cs151Hello
wget -qO - https://packagecloud.io/AtomEditor/atom/gpgkey | sudo apt-key add -
 
sudo sh -c 'echo "deb [arch=amd64] https://packagecloud.io/AtomEditor/atom/any/ any main" > /etc/apt/sources.list.d/atom.list'
cs15100@cs:/u1/class/cs15100> ls
sudo apt update
cs151Hello  Desktop/  hello/  proto/
sudo apt install atom
 
</pre>
cs15100@cs:/u1/class/cs15100> rm cs151Hello
''Other Linux distributions'' use different package managersIf you use a different Linux distribution and are unable to figure out how to install packages you can ask your instructor, your advisor, or the CS system administrator.
rm: remove regular file 'cs151Hello'? y
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/ hello/  proto/
 
cs15100@cs:/u1/class/cs15100> rmdir hello
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  proto/
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/ proto/
 
cs15100@cs:/u1/class/cs15100> cd Desktop/
 
cs15100@cs:/u1/class/cs15100/Desktop> ls
hello.txt
 
cs15100@cs:/u1/class/cs15100/Desktop> mv hello.txt ..
 
cs15100@cs:/u1/class/cs15100/Desktop> ls
 
cs15100@cs:/u1/class/cs15100/Desktop> cd ..
 
cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello.txt proto/


After installing the above programs you can open them from the terminal (i.e., to open filezilla you type the command, filezilla).  The programs may also appear in the graphical menu of programs.
cs15100@cs:/u1/class/cs15100> mv hello.txt helloThere.txt


==Chromebook==
cs15100@cs:/u1/class/cs15100> ls
On Chromebook you can choose whether to install apps and do all of your work connected to the CS server, or install Linux on your Chromebook and then use the instructions above on installing the programs.
Desktop/  helloThere.txt  proto/


'''Using apps''' - Install the following apps.
cs15100@cs:/u1/class/cs15100> ls
* ''Text Editor'' - [https://chrome.google.com/webstore/detail/text/mmfbcljfglbokpmkimbfghdkjmjhdgbg?hl=en Text]
Desktop/ helloThere.txt  proto/
* ''Terminal Program'' - [https://chrome.google.com/webstore/detail/secure-shell-app/pnhechapfaindjhompbnflcldabbghjo Secure Shell]
* ''File Transfer Program'' - use the builtin Files app along with the Secure Shell app, configure as follows.
** Open the Files app.
** Click on the triple-dots in the upper right of the Files app, click Add new service, click Secure Shell App.
** On the Secure Shell App screen that comes up, enter your login information with cs.indstate.edu as the server and 22 as the port.  Then click SFTP Mount.
** Go back to the Files app and you will see LOGIN@cs.indstate.edu:22 as an option on the left.


'''Linux (Beta) on Chromebook'''
cs15100@cs:/u1/class/cs15100> mv hello.txt helloThere.txt
* Not all chromebooks allow installation of Linux (Beta).  If this works then you will have Linux installed on your Chromebook and will be able to use any of the commands that you use on the CS server.
mv: cannot stat 'hello.txt': No such file or directory
* Follow [https://support.google.com/chromebook/answer/9145439?hl=en instructions from google].
* Note - installation could take a very long time (e.g., an hour or more).  If installation fails you may need to select Remove Linux Beta and try again.
* Once installation is complete you open a terminal using the Terminal app. To install the programs mentioned on this page follow the instructions above for Linux (using the APT package manager commands).
* After the programs are installed you can open them by typing the command in the Terminal or by opening them as apps.


'''Copy/paste''' - in either the Secure Shell app or the Terminal app, copy/paste as follows. To copy, simply select text with the mouse and it will be copied to the clipboardTo paste, do a triple-click (three finger click).
cs15100@cs:/u1/class/cs15100> ls
DesktophelloThere.txt proto/


==Other OS-Specific Notes==
cs15100@cs:/u1/class/cs15100> cp helloThere.txt hello.txt
If you are using Windows and have Putty installed as your terminal program, it installs a text-based file transfer program as well - psftp - which you should be able to find in your list of programs.


If you are using MacOS or Linux, a text-based file transfer program - sftp - is normally installed by default.
cs15100@cs:/u1/class/cs15100> ls
Desktop/  helloThere.txt  hello.txt  proto/


In either case, new users often prefer to use graphical file transfer programs (those mentioned above).
cs15100@cs:/u1/class/cs15100> nano helloThere.txt


For the text-based sftp programs, the basic commands you will need.
cs15100@cs:/u1/class/cs15100> cd Desktop
* ls, cd, pwd - show you the files on the server and change directories on the server.
* lls, lcd, lpwd - show you the files on your computer and change directories on your computer.
* put - send a file from your computer to the server (from your current directory on your computer, to the current directory on the server).
* get - download a file from the server to your computer
* quit


==Compilers/Interpreters==
cs15100@cs:/u1/class/cs15100/Desktop> ls


===Python===
cs15100@cs:/u1/class/cs15100/Desktop> ls .


===C/C++===
jkinne@isuad@indstate.edu@cs:/u1/class/jkinne@isuad@indstate.edu/Desktop> cp ../helloThere.txt .


==Backing up Files - Rsync==
cs15100@cs:/u1/class/cs15100/Desktop> ls
helloThere.txt


==GUI Programs X-Windows==
cs15100@cs:/u1/class/cs15100/Desktop> cp /u1/class/cs15100/helloThere.txt /u1/class/cs15100/Desktop/
To run a GUI program while connected to the server, you will need to be running an X11 client on your local computer and have it running when connect to the server. Some further details depending on your operating system.
cp: overwrite '/u1/class/cs15100/Desktop/helloThere.txt'? n
* MacOS - install [https://www.xquartz.org/ XQuartz] and run it.
* Windows - install [https://x.cygwin.com/ Cygwin/X] ([https://x.cygwin.com/docs/ug/setup.html#setup-cygwin-x-installing installation]) and run it. Or, euse the [https://learn.microsoft.com/en-us/windows/wsl/install Windows Subsystem for Linux] (WSL).
* Linux - do not need to install anything extra.


Once you have your X11 client installed, open it, and then connect to the CS server using the -Y switch in your ssh command: <pre>ssh -Y username@cs.indstate.edu</pre>
cs15100@cs:/u1/class/cs15100/Desktop> cd ..


To verify everything is working try running in your terminal xcalc: <pre>xcalc</pre>
cs15100@cs:/u1/class/cs15100> nano hello there.txt


=Sample HW=
cs15100@cs:/u1/class/cs15100> nano "hello there.txt"
The following might be used by your instructor as part of a HW assignment to verify you have your computer setup properly.


# Follow the steps above to setup your computer with a file transfer program, text editor, and terminal program.  Make sure you are able to use the file transfer program and terminal programs to connect to your CS class account on the CS server.
cs15100@cs:/u1/class/cs15100> ls -l
# Make sure you can open the text editor. Create a text file aboutMySystem.txt and put the following information.
total 20
## Your name:  
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:51 Desktop/
## Your CS class account:  
-rw-r--r-- 1 cs15100 class   9 Jan 10 11:52 hello\ there.txt
## Operating System:
-rw-r--r-- 1 cs15100 class  60 Jan 10 11:43 helloThere.txt
## Text editor you are using:
-rw-r--r-- 1 cs15100 class   60 Jan 10 11:50 hello.txt
## File transfer program:
drwxr-xr-x 2 cs15100 class 4096 Jan 9 12:35 proto/
## Did you have any difficulties in getting the programs setup? If yes, explain.
</pre>
# Create the following screen shots demonstrating that you have the programs installed on your system properly.  Note - you can ask the internet how to take a screenshot (e.g., type in - how to screenshot on chromebook).  For each screenshot, make the screenshot of your whole screen (so I can see which OS you are running on and the program open and connected).
## textEditor.jpg - a screenshot that shows you editing the aboutMySystem.txt file with your text editor.
## fileTransfer.jpg - a screenshot that shows you using the file transfer program to connect to the CS server with your CS class account.
## terminal.jpg - a screenshot that shows you with the terminal program open and connected to the CS server with your CS class account.
# Use the file transfer program to connect to the CS server with your CS class account.  
## While connected, create a new directory in your CS class account on the CS server.  Name the new directory SystemSetup.
## Transfer the files you just created (aboutMySystem.txt, textEditor.jpg, fileTransfer.jpg, terminal.jpg) into the SystemSetup directory in your CS class account on the server.

Latest revision as of 12:16, 29 September 2025

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 demo video for a video demonstration of the topics on this page, including running the commands on the ISU CS server. You should start reading through this page before watching the video.

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 Quiz

An example quiz over this material. After watching the video and trying the commands out yourself to make sure you understand.

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.

  • 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:

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:

Sample HW

The following might be used by your instructor as part of a HW assignment to verify that you are able to use the terminal to create and copy files and view the contents of directories.

Create a directory to store files for this HW. If you are given this assignment in one of your courses you will be told which directory to use. We refer to this directory as HW_dir.

  1. Copy /var/junk/shakespeare.txt into your HW_dir.
  2. Copy /proc/cpuinfo into your HW_dir, but make the file name cpuinfo-HW.txt
  3. Copy /proc/version into your HW_dir, but make the file name version-HW.txt
  4. Create a file info.txt in your HW_dir. Inside the file fill in the following information.
    • Name (what you want to be called):
    • Why you are taking this course:
    • Anything you are worried about (wrt this course):
    • Most excited about (wrt this course):
  5. In the terminal, browse to the directory /net/web, run the command ls -l cs151, and copy the output of that command. Go back to your HW_dir, edit your info.txt file, and paste into the file.
  6. Copy ~cs151/hello.txt into your HW_dir

Sample Session

The following is a transcript of the commands and screen output from the youtube video linked at the top of this page. Blank lines have been put in after each command. You can read through the transcript and think about what you think the output will be after each command is entered, and check that this is how it shows in the transcript.

Note that a few text files have been edited using the nano text editor. When the nano text editor was used the editing of the file itself is not part of the transcript. Note that the transcript is for the user jkinne@isuad@indstate.edu logged in to the CS server.

cs15100@cs:/u1/class/cs15100> ls
Desktop/  proto/

cs15100@cs:/u1/class/cs15100> ls -l
total 8
drwxr-xr-x 2 cs15100 class 4096 Jan  8 21:17 Desktop/
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/

cs15100@cs:/u1/class/cs15100> cd Desktop

cs15100@cs:/u1/class/cs15100/Desktop> ls

cs15100@cs:/u1/class/cs15100/Desktop> cd ..

cs15100@cs:/u1/class/cs15100> mkdir hello

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> nano hello.txt

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  hello.txt  proto/

cs15100@cs:/u1/class/cs15100> ls -l
total 16
drwxr-xr-x 2 cs15100 class 4096 Jan  8 21:17 Desktop/
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:37 hello/
-rw-r--r-- 1 cs15100 class   60 Jan 10 11:43 hello.txt
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/

cs15100@cs:/u1/class/cs15100> mv hello.txt Desktop

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> ls Desktop
hello.txt

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> ls /
bin/   dev/  home/  lib64/       media/  net/  proc/  run/   srv/    swap  tmp/  u2/   var/
boot/  etc/  lib/   lost+found/  mnt/    opt/  root/  sbin/  store/  sys/  u1/   usr/  xsys/

cs15100@cs:/u1/class/cs15100> cd Desktop

cs15100@cs:/u1/class/cs15100/Desktop> ls /u1/class/cs15100
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100/Desktop> ls ~
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100/Desktop> cd /u1/junk/kinne

cs15100@cs:/u1/junk/kinne> ls
cs151Hello            Indianapolis-Weather-Station-USW00093819-1950-2018.csv  shakespeare_1000_lines.txt
GRCh38.p12.genome.fa  interview-questions/                                    shakespeare.txt
hello.txt             shakespeare_1000_lines_tail.txt                         Terre_Haute_airport_93823-03868.csv

cs15100@cs:/u1/junk/kinne> ls ~
Desktop/  hello/  proto/

cs15100@cs:/u1/junk/kinne> ls
cs151Hello            Indianapolis-Weather-Station-USW00093819-1950-2018.csv  shakespeare_1000_lines.txt
GRCh38.p12.genome.fa  interview-questions/                                    shakespeare.txt
hello.txt             shakespeare_1000_lines_tail.txt                         Terre_Haute_airport_93823-03868.csv

cs15100@cs:/u1/junk/kinne> cp cs151Hello ~

cs15100@cs:/u1/junk/kinne> cd ~

cs15100@cs:/u1/class/cs15100> ls
cs151Hello  Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> ls -l
total 16
-rw-r--r-- 1 cs15100 class   16 Jan 10 11:46 cs151Hello
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:44 Desktop/
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:37 hello/
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/

cs15100@cs:/u1/class/cs15100> nano cs151Hello

cs15100@cs:/u1/class/cs15100> ls
cs151Hello  Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> rm cs151Hello
rm: remove regular file 'cs151Hello'? y

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello/  proto/

cs15100@cs:/u1/class/cs15100> rmdir hello

cs15100@cs:/u1/class/cs15100> ls
Desktop/  proto/

cs15100@cs:/u1/class/cs15100> ls
Desktop/  proto/

cs15100@cs:/u1/class/cs15100> cd Desktop/

cs15100@cs:/u1/class/cs15100/Desktop> ls
hello.txt

cs15100@cs:/u1/class/cs15100/Desktop> mv hello.txt ..

cs15100@cs:/u1/class/cs15100/Desktop> ls

cs15100@cs:/u1/class/cs15100/Desktop> cd ..

cs15100@cs:/u1/class/cs15100> ls
Desktop/  hello.txt  proto/

cs15100@cs:/u1/class/cs15100> mv hello.txt helloThere.txt

cs15100@cs:/u1/class/cs15100> ls
Desktop/  helloThere.txt  proto/

cs15100@cs:/u1/class/cs15100> ls
Desktop/  helloThere.txt  proto/

cs15100@cs:/u1/class/cs15100> mv hello.txt helloThere.txt
mv: cannot stat 'hello.txt': No such file or directory

cs15100@cs:/u1/class/cs15100> ls
Desktop/  helloThere.txt  proto/

cs15100@cs:/u1/class/cs15100> cp helloThere.txt hello.txt

cs15100@cs:/u1/class/cs15100> ls
Desktop/  helloThere.txt  hello.txt  proto/

cs15100@cs:/u1/class/cs15100> nano helloThere.txt 

cs15100@cs:/u1/class/cs15100> cd Desktop

cs15100@cs:/u1/class/cs15100/Desktop> ls

cs15100@cs:/u1/class/cs15100/Desktop> ls .

jkinne@isuad@indstate.edu@cs:/u1/class/jkinne@isuad@indstate.edu/Desktop> cp ../helloThere.txt .

cs15100@cs:/u1/class/cs15100/Desktop> ls
helloThere.txt

cs15100@cs:/u1/class/cs15100/Desktop> cp /u1/class/cs15100/helloThere.txt /u1/class/cs15100/Desktop/
cp: overwrite '/u1/class/cs15100/Desktop/helloThere.txt'? n

cs15100@cs:/u1/class/cs15100/Desktop> cd ..

cs15100@cs:/u1/class/cs15100> nano hello there.txt

cs15100@cs:/u1/class/cs15100> nano "hello there.txt"

cs15100@cs:/u1/class/cs15100> ls -l
total 20
drwxr-xr-x 2 cs15100 class 4096 Jan 10 11:51 Desktop/
-rw-r--r-- 1 cs15100 class    9 Jan 10 11:52 hello\ there.txt
-rw-r--r-- 1 cs15100 class   60 Jan 10 11:43 helloThere.txt
-rw-r--r-- 1 cs15100 class   60 Jan 10 11:50 hello.txt
drwxr-xr-x 2 cs15100 class 4096 Jan  9 12:35 proto/