Python Programming - Getting Started and Linux and CS Systems - Getting Started: Difference between pages

From Computer Science at Indiana State University
(Difference between pages)
Jump to navigation Jump to search
 
No edit summary
 
Line 1: Line 1:
''This page is part of [[Programming and CS - Getting Started]]''
''This page is part of [[Programming and CS - Getting Started]]''


For a video explaining how to get started here, see https://www.youtube.com/watch?v=uLnhcCZS4-Y&t=424s
This page is meant to help a new student in a CS course at ISU to get familiar with using Linux (in particular using the text-based terminal to interact with the system).


==Getting Started==
=Getting Started=
# '''Reading''' - start reading through at least one of the following before you start working on the programming problems.
# '''Read''' - [https://ubuntu.com/tutorials/command-line-for-beginners#1-overview Ubuntu Linux Command Line Tutorial] or [http://www.ee.surrey.ac.uk/Teaching/Unix/ Linux Tutorial] - this gives you some background and introduces you to some of the terms that we use. After reading through the tutorial you have a better chance of being able to follow along the rest of the steps in this Getting Started.
## [https://www.w3schools.com/python/python_intro.asp w3schools Python] - interactive tutorial where you can try out code in the browser
# '''System Setup''' - [[Linux - System Setup]] - to get your computer setup (programs installed, etc.).
## [https://www.learnpython.org/ Learn Python] - interactive tutorial where you can try out code in the browser
# '''Using the Terminal'''
## [https://automatetheboringstuff.com/ Automate the Boring Stuff with Python] - suitable for people with very limited programming experience, this is the text that is being followed for our CS 151 course (as of 2019)
## [[Linux Terminal - Files and Directories and Getting Around]]
## [http://greenteapress.com/thinkpython2/html/index.html Think Python] - suitable for people with very limited programming experience, not very deep
## [[Linux Terminal - System Information]]
## [https://learnxinyminutes.com/docs/python3/ LearnXinYminutes] - quick review once you are familiar with the basics
## [[Linux Terminal - Text Editors]]
## [https://docs.python.org/3/tutorial/ Python.org tutorial] - good for those with programming experience already
## [[Using Linux - Large Text Files]]
# '''Get Python installed on your computer''' - download the latest Python3 version at https://www.python.org/downloads/.  Having python3 installed on your computer allows you to debug much quicker.
## [[Linux Terminal - More Commands to Know]]
# '''Work on solving problems''' that are listed below.
# If you are a current or incoming ISU student, or an ISU alumni, get help on what you are working on using the online unix lab.  When asking about the hackerrank problems make sure to refer to them using the title hackerrank gives them, or give a link to the problem statement on hackerrank.
# '''Cheat sheets''' - keep a cheat sheet for yourself of python syntax, built-in functions, etc.  See below on this page for our model cheat sheets.


==Running Python==
=Common Mistakes=
''See [https://youtu.be/ABmQ2QyYCLg this video] for a video demo of getting started running Python on the CS server and in IDLE.''
* When logging in remotely to the CS server, when you are typing your password you might not see anything printed on your screen while you type.  That is a security feature so that someone watching your screen would not know how many characters are in your password.  Just finish typing your password and type enter when finished.
* Note that all commands and file names in Linux are '''case sensitive'''.  hello.txt is different than Hello.txt.  The copy command is cp, Cp would not work, and neither would cP or CP.
* The characters _ and - are different, and having a space in a file name is different than not having one ("hello world.txt" is different than "helloworld.txt").
* For Linux directories and filenames, the "/" character is used to separate directories.  On Windows, the "\" character is used instead.  If you typed <pre>cd /home/cs151</pre> then this changes the directory to the cs151 user's home directory.  If you instead typed <pre>cd \home\cs151</pre> you would get an error.
* The "top" or "highest level" of the Linux file system is the directory / and this is comparable to the "C:\" that was traditionally the top of the file system in Windows.  In Windows there can be multiple drives (so D:\, E:\, etc.), but in Linux '''everything''' is underneath / (including additional drives, they will show up at a certain location under /).
* On Linux, ~ is a shortcut for your home directory.  User jkinne@isuad.indstate.edu's home directory is in /home/jkinne@isuad.indstate.edu, so if this user is logged in and types <pre>cd ~</pre> then this means to change directories to /home/jkinne@isuad.indstate.edu/. If user jeff types <pre>cd ~</pre> then this means to change directories to jeff's home directory (which happens to be /home/jeff/).
* Not all sequences of commands are ''idempotent'' - this is a technical term that means that the sequence of commands gives the same results if executed more than once. For example, executing <code>echo "hello world!" >> hello.txt</code> once creates a file hello.txt that has one line in it, but executing again makes the file have two lines. When you see a sequence of commands to run to complete some task (e.g., from an online tutorial) be careful to execute one command after the other, all the way through, stopping after each to make sure you know what that step was supposed to do.
* Sometimes the precise syntax of commands might depend on which shell program you are using. bash is the default shell program on the CS server, but  zsh is commonly used instead.  You can see which shell you are running by executing the <code>ps</code> command and seeing which one is in the printed output from that command.  For example, the command for displaying your resource limits is <code>ulimit -a</code> in bash and zsh, but is <code>limit</code> in tcsh. When looking up how to do things online, it is good to include your shell in the search terms (e.g., search for - bash get resource limits - rather than just - get resource limits).


Once you have a computer with Python installed you are ready to try it out! You can use the CS systems (computers in our classrooms and labs, or connect to the CS server - see [[Linux - System Setup]]), or install Python on your personal computer. ''We recommend doing both.''
=More Reading=
Read through another tutorial about Linux. Some options include the follow.
* [http://www.linuxcommand.org/ Linux Console Tutorial]
* [http://www.reallylinux.com/ Information for Beginning Linux Users]
* [http://cs.indstate.edu/~sbaker/faq/QuickRefCard.pdf Unix/Linux Quick Reference Card]


===Run in the Terminal===  
=Self Test=
On the CS server, other Linux systems, and macOS, you can run python using your terminal.  If you run the command <code>python3</code> then you will see the python console. Here you can type one python line at a time to run, and the results are displayed. You can try these -
Note: a practice quiz over linux commands and the terminal is here - https://indstate.instructure.com/courses/12565/quizzes/244584
<pre>
2 + 3
3 * 4
10 ** 3
</pre>


We normally store our python code in text files and want to run the entire file.  If you have a file with python code (let's say it is named myProgram.py) then you change directories to the directory that has your file, and then type <code>python3 myProgram.py</code>.  You can have one terminal open where you are running your program with this command, and you can have another terminal open to edit the file (or use some other text editor).
Here we give small tasks for you to complete.  These are numbered so that we can refer to them.  For each you would need to be logged into one of the CS systems (remotely logged into the CS server or using one of the CS lab computers).


===Run in IDLE===
''Linux.1'' Log in to the CS server, create a directory named aboutMe in your home directory, and create a text file name.txt.  In the name.txt file, give your full name.
Python comes with a graphical front-end called IDLE. You can run this program if you are in the CS labs by opening your terminal and then typing <code>idle3</code>.  If you have python installed on your personal computer, then you can find IDLE in your list of programs (Start button on Windows, Finder then click Applications on macOS) or run idle3 from the terminal (if you are using Linux).  If you are connecting to the CS server with a terminal program from home, you cannot run idle3 in the terminal because it is a graphical program - you will need to install it on your home computer to use it from home.


When you start IDLE, it shows you the Python3 console, where you can type your Python3 commands. Try typing in arithmetic expressions to make sure it is working.  For example -
''Linux.2'' In your aboutMe directory, create a file courses.txt and list which CS courses you are currently taking or plan to take in the upcoming term.
<pre>
2 + 3
3 * 4
10 ** 3
</pre>


===First Python Program===
''Linux.3'' Log in to the CS server, create a directory named notes in your home directory, and create a text file named linux.txt and put in some links to linux tutorials or information that you have found helpful.
We store python programs in text files.  You can use the following as your first python program.
<pre>
print('Hello world.')
print('Hello again.')
print('Goodbye now.')
</pre>
If you are using IDLE you create and run a file by -
# Click on File and then New File. 
# Copy/paste or type your code in the file window that comes up.
# Click File and Save As.  Name the file myProgram.py and save it in whichever directory you want to keep your python programs. 
# Click Run and then Run Module.  In the python console window you should see that your program ran.
If you are connecting to the CS server with your terminal from your home computer, you can choose one of the following options.
* Create and edit the myProgram.py file with a text editor that works in the terminal - see [[Linux Terminal - Text Editors]].  Save the program and run the program with <code>python3 myProgram.py</code>.  If you make changes, edit the program, and then run it again.
* Edit the program using a text editor on your home computer (for example, Kate or Atom, see [[Linux Terminal - Text Editors]]), transfer to the CS server using a file transfer program (see [[Linux - System Setup]]), change directories in your terminal to the directory that has the program, and then run the program in the terminal with <code>python3 myProgram.py</code>


===Python2 versus Python3===
''Linux.4'' Log in to the CS server, create a directory named linux-bootcamp in your home directory.
If you want to use Python version 2 instead, you would use commands <code>python</code> and <code>idle</code> rather than <code>python3</code> and <code>idle3</code>.  You should normally use Python3; the only reason to use Python2 is if you are using a package that is only available on Python2 (Python2 is not officially supported anymore, so this should be fairly rare).


==Installing Python on Your Personal Computer==
''Linux.5'' In your linux-bootcamp directory, create a text file shake.txt.  In shake.txt, put how many lines are in the shakespeare.txt file mentioned in the information above.
'''Windows and macOS''' Download and install from https://www.python.org/downloads/.


'''Linux''' On Linux python is probably already installed. If not do an internet search for your Linux distribution and "install python3" (i.e., search for - ubuntu install python).
''Linux.6'' In your shake.txt file, add information about how many times "the" appears in shakespeare.txt.  Use the command grep,
add to what you had how many lines "the" appears in shakespeare.txt. Hint - use the -c option for grep, also use the -i option so your count will also include "The", "THE", etc. In your shake.txt, you should have the number of lines that contain "the" (including "The", etc.), and also the percentage of the lines that contain the.


'''Chromebook''' You should first get the Linux development environment enabled and then you can follow instructions for installing python3 for ubuntu.  If python3 is not already installed, then running <code>sudo apt-get install python3</code> should install it.
''Linux.7'' In your linux-bootcamp directory, create a text file weather.txt.  Copy the Indianapolis weather csv file from /var/junk/weather/ into your linux-bootcamp directory.  In your weather.txt file, put how many rows of data are in the csv file (use wc, head, and tail).  Assuming 365 days per year, put in your weather.txt file how many years of data are in the csv file.


==Lists of Problems==
''Linux.8'' In your weather.txt file, put the maximum PRCP, SNOW, SNWD, TMAX, TMIN, MEAN from the csv file. Hint - use the sort command, and use the options -t, -k, -n, -o.
===Programming Assignments 1===
[[Programming Assignments - Beginning 1]] - start with trying to solve these problems. Each requires a different feature of the Python programming language, so solve these problems as you read through one of the tutorials or links above. Note that the page includes a link to repl.it that contains solutions to most of the problems.  If you do not have Python installed on your computer, you can try it out at [https://repl.it/ repl.it] - click the logo at the top, then click "+ new repl", select Python and Create Repl.


[[Programming Assignments - Beginning 2]] - another set of classic beginning programming exercises. Some of these will be more involved.
=Account Configuration=
Bash reads configuration information from a file <code>~/.bashrc</code>.  A file with good defaults for the CS server are at [https://cs.indstate.edu/~jkinne/training_files/.bashrc .bashrc]. More help on bash - [https://www.gnu.org/software/bash/manual/ bash manual].


===HackerRank Problems===
If you want to see what commands you have run in the current login session you can run the command <code>history</code>.  Bash also keeps history from previous sessions in the file <code>~/.bash_history</code>.
Once you can do some basic Python programming it is time to have some of your work checked.  Hackerrank is a site where you can create an account and work on problems that will be checked if they are correct. Note that hackerrank has very strict rules for accepting correct solutions.  Start with the basic problems to get a feel for what hackerrank expects.


[[Python programming - hackerrank problems]]
You should create the following directories and use (a) your <code>bin</code> directory to put programs or scripts that you have downloaded or created that you want to be able to use, (b) your <code>programs</code> directory to put installation files for programs that you might need, (c) your <code>private</code> directory to keep files you want to make sure to keep private from other users, and (d) your <code>public_html</code> directory to store files that you want to be accessible on the web (at https://cs.indstate.edu/~YOUR_LOGIN).
 
===More Practice===
If you are able to do most of the problems on the pages linked above, then you don't need us to give you lists of problems any more.  You can pick problems to work through on your own.  Some suggested places with problems are as follows.
* [https://www.hackerrank.com/domains/algorithms Hackerrank - algorithms]
* [https://www.hackerrank.com/domains/data-structures Hackerrank - data structures]
* [http://cs.indstate.edu/acm/contests.html ACM Contest Problems]
 
==Cheat Sheets and Quizzes==
These cheat sheets have the highlights of some of the basic information to memorize when you are in your first year of Python programming.  Note - each cheat sheet contains a sample quiz that might be used by your instructor.
* [[Cheat sheet - Python Operators, Expressions]]
* [[Cheat sheet - Python Keywords, Concepts, Functions]]
 
==Programming Errors and How to Fix Them==
* '''Syntax error''' - program is not a valid program, and normally python gives you an error message giving some indication of what the problem was. 
** ''Debugging'' - read the error message!  Normally you are given a line number where python got "confused" - sometimes that is where the problem is, but you may need to look just before that line (or just after).  Common syntax errors in python...
** ''Mismatched'' () or [] or "" or '', for example <code>x = 2 * (3 + 4</code>
** ''Mis-capitalization or mis-spelling'', for example <code>Print('hello')</code>
** ''Improper indenting'', for example
** ''Data type'' problems - mixing up strings and numbers, for example <code>x = '3' + 4</code>
<pre>
<pre>
for i in range(0, 10):
mkdir ~/bin/
print(i)
echo "export PATH=$PATH:~/bin/" >> .bashrc  # add the ~/bin/ directory to where shell looks for programs
mkdir ~/programs/
mkdir ~/private/
chmod go-rwx ~/private/    # makes that directory not accessible to other users
mkdir ~/public_html/
chmod go+rx ~/public_html/ # so the web server can access this directory
chmod go+x ~              # so the web server can access your public_html
</pre>
</pre>
* '''Runtime error''' - program is a valid program but when you run it something goes wrong. Debugging is similar as for syntax errors and logical errors.  For example...
Note that the web server is Apache, so if you want to configure how it processes files in your account, you should look for help on the Apache web server. It is also possible to run a web server using node.js; you can look up tutorials for how to do that.
 
=Copying/Creating/Editing Files=
Create a file in your <code>public_html</code> directory, and practice copying a file from somewhere else on the system.
<pre>
<pre>
x = 1
cd ~/public_html
print(x)
nano hello.txt  # or use your preferred editor - vim, emacs, jove, ...
x = y + z
# type something in your hello.txt file, save it, and
#  check that you can view it at https://cs.indstate.edu/~YOUR_LOGIN/hello.txt
cp /usr/dict/words . # copies that file into current directory, which should still be your public_html
# now check https://cs.indstate.edu/~YOUR_LOGIN/words
</pre>
</pre>
* '''Logical error''' - program runs but does not do the right thing.
Create a sub-directory within your <code>public_html</code> directory, put some file there, edit the Apache configuration file (<code>.htaccess</code>) to allow directory listing of this directory (turned off by default for security reasons).
** ''Print debugging'' - One debugging method is to start printing things (values of variables) in your program starting at the beginning, run the program, make sure it is printing the values you expect, at some point you see a value you don't expect, and that tells you where to look in your code.  You often are 100% sure what you have is right, but in the end there is some problem.  So you have to ''check everything'', start at the very beginning of the program.
** ''Disable all'' - Another strategy is to disable almost all parts of your program (e.g., put it all in comments) until you get behavior that makes sense, and then start adding things back in (uncommenting), and eventually you'll add something in that doesn't behave the way you thought, and now you know where the problem is.  Examples...
<pre>
<pre>
x = 1
cd ~/public_html
y = 2
mkdir files_public
z = 3
cd files_public
avg = x + y + z / 3
echo "Options +Indexes" >> .htaccess
print(avg)
ls -a        # verify that the .htaccess file exists now
cat .htaccess # see what is in the file now
cp /var/junk/kinne/text-samples/shakespeare.txt .
cp /var/junk/kinne/text-samples/austen.txt .
# Now browse to https://cs.indstate.edu/~YOUR_LOGIN/files_public
</pre>
</pre>
=Long Running Jobs=
If you have a process that needs to run for more than a few minutes, you should run it like this:
<pre>time nice -n 19 whatever_command</pre>
Starting the command with <code>time</code> will give you a printout afterwards of how much time the job took (<code>man time</code> for more details). Having <code>nice -n 19</code> makes your long running job run at a lower priority. Your job will finish just as fast, but it will interfere less with more important processes (other users on the system).
If the job is going to take an hour or more, you probably want to run it like this:
<pre>time nice -n 19 whatever_command > output.txt 2>stderr.txt &</pre>
The <code> > output.txt</code> will have output go to the output.txt file, and <code> 2>stderr.txt</code> (no spaces is important) redirects error output to stderr.txt. The <code>&</code> will detach the process from your terminal so that it can continue running even if your terminal disconnects. You can login again and check on it by running <code>ps a</code> to see all your running processes (not just the ones started on the current login).
Alternatively to redirecting the output and detaching, you could use the <code>screen</code> command to run the command in a terminal that you can detach. You can lookup help on the screen command for how to do that (for example, [https://www.geeksforgeeks.org/screen-command-in-linux-with-examples/ here]).

Latest revision as of 22:27, 4 June 2026

This page is part of Programming and CS - Getting Started

This page is meant to help a new student in a CS course at ISU to get familiar with using Linux (in particular using the text-based terminal to interact with the system).

Getting Started

  1. Read - Ubuntu Linux Command Line Tutorial or Linux Tutorial - this gives you some background and introduces you to some of the terms that we use. After reading through the tutorial you have a better chance of being able to follow along the rest of the steps in this Getting Started.
  2. System Setup - Linux - System Setup - to get your computer setup (programs installed, etc.).
  3. Using the Terminal
    1. Linux Terminal - Files and Directories and Getting Around
    2. Linux Terminal - System Information
    3. Linux Terminal - Text Editors
    4. Using Linux - Large Text Files
    5. Linux Terminal - More Commands to Know

Common Mistakes

  • When logging in remotely to the CS server, when you are typing your password you might not see anything printed on your screen while you type. That is a security feature so that someone watching your screen would not know how many characters are in your password. Just finish typing your password and type enter when finished.
  • Note that all commands and file names in Linux are case sensitive. hello.txt is different than Hello.txt. The copy command is cp, Cp would not work, and neither would cP or CP.
  • The characters _ and - are different, and having a space in a file name is different than not having one ("hello world.txt" is different than "helloworld.txt").
  • For Linux directories and filenames, the "/" character is used to separate directories. On Windows, the "\" character is used instead. If you typed
    cd /home/cs151
    then this changes the directory to the cs151 user's home directory. If you instead typed
    cd \home\cs151
    you would get an error.
  • The "top" or "highest level" of the Linux file system is the directory / and this is comparable to the "C:\" that was traditionally the top of the file system in Windows. In Windows there can be multiple drives (so D:\, E:\, etc.), but in Linux everything is underneath / (including additional drives, they will show up at a certain location under /).
  • On Linux, ~ is a shortcut for your home directory. User jkinne@isuad.indstate.edu's home directory is in /home/jkinne@isuad.indstate.edu, so if this user is logged in and types
    cd ~
    then this means to change directories to /home/jkinne@isuad.indstate.edu/. If user jeff types
    cd ~
    then this means to change directories to jeff's home directory (which happens to be /home/jeff/).
  • Not all sequences of commands are idempotent - this is a technical term that means that the sequence of commands gives the same results if executed more than once. For example, executing echo "hello world!" >> hello.txt once creates a file hello.txt that has one line in it, but executing again makes the file have two lines. When you see a sequence of commands to run to complete some task (e.g., from an online tutorial) be careful to execute one command after the other, all the way through, stopping after each to make sure you know what that step was supposed to do.
  • Sometimes the precise syntax of commands might depend on which shell program you are using. bash is the default shell program on the CS server, but zsh is commonly used instead. You can see which shell you are running by executing the ps command and seeing which one is in the printed output from that command. For example, the command for displaying your resource limits is ulimit -a in bash and zsh, but is limit in tcsh. When looking up how to do things online, it is good to include your shell in the search terms (e.g., search for - bash get resource limits - rather than just - get resource limits).

More Reading

Read through another tutorial about Linux. Some options include the follow.

Self Test

Note: a practice quiz over linux commands and the terminal is here - https://indstate.instructure.com/courses/12565/quizzes/244584

Here we give small tasks for you to complete. These are numbered so that we can refer to them. For each you would need to be logged into one of the CS systems (remotely logged into the CS server or using one of the CS lab computers).

Linux.1 Log in to the CS server, create a directory named aboutMe in your home directory, and create a text file name.txt. In the name.txt file, give your full name.

Linux.2 In your aboutMe directory, create a file courses.txt and list which CS courses you are currently taking or plan to take in the upcoming term.

Linux.3 Log in to the CS server, create a directory named notes in your home directory, and create a text file named linux.txt and put in some links to linux tutorials or information that you have found helpful.

Linux.4 Log in to the CS server, create a directory named linux-bootcamp in your home directory.

Linux.5 In your linux-bootcamp directory, create a text file shake.txt. In shake.txt, put how many lines are in the shakespeare.txt file mentioned in the information above.

Linux.6 In your shake.txt file, add information about how many times "the" appears in shakespeare.txt. Use the command grep, add to what you had how many lines "the" appears in shakespeare.txt. Hint - use the -c option for grep, also use the -i option so your count will also include "The", "THE", etc. In your shake.txt, you should have the number of lines that contain "the" (including "The", etc.), and also the percentage of the lines that contain the.

Linux.7 In your linux-bootcamp directory, create a text file weather.txt. Copy the Indianapolis weather csv file from /var/junk/weather/ into your linux-bootcamp directory. In your weather.txt file, put how many rows of data are in the csv file (use wc, head, and tail). Assuming 365 days per year, put in your weather.txt file how many years of data are in the csv file.

Linux.8 In your weather.txt file, put the maximum PRCP, SNOW, SNWD, TMAX, TMIN, MEAN from the csv file. Hint - use the sort command, and use the options -t, -k, -n, -o.

Account Configuration

Bash reads configuration information from a file ~/.bashrc. A file with good defaults for the CS server are at .bashrc. More help on bash - bash manual.

If you want to see what commands you have run in the current login session you can run the command history. Bash also keeps history from previous sessions in the file ~/.bash_history.

You should create the following directories and use (a) your bin directory to put programs or scripts that you have downloaded or created that you want to be able to use, (b) your programs directory to put installation files for programs that you might need, (c) your private directory to keep files you want to make sure to keep private from other users, and (d) your public_html directory to store files that you want to be accessible on the web (at https://cs.indstate.edu/~YOUR_LOGIN).

mkdir ~/bin/
echo "export PATH=$PATH:~/bin/" >> .bashrc  # add the ~/bin/ directory to where shell looks for programs
mkdir ~/programs/
mkdir ~/private/
chmod go-rwx ~/private/    # makes that directory not accessible to other users
mkdir ~/public_html/
chmod go+rx ~/public_html/ # so the web server can access this directory
chmod go+x ~               # so the web server can access your public_html

Note that the web server is Apache, so if you want to configure how it processes files in your account, you should look for help on the Apache web server. It is also possible to run a web server using node.js; you can look up tutorials for how to do that.

Copying/Creating/Editing Files

Create a file in your public_html directory, and practice copying a file from somewhere else on the system.

cd ~/public_html
nano hello.txt  # or use your preferred editor - vim, emacs, jove, ...
# type something in your hello.txt file, save it, and
#  check that you can view it at https://cs.indstate.edu/~YOUR_LOGIN/hello.txt
cp /usr/dict/words . # copies that file into current directory, which should still be your public_html
# now check https://cs.indstate.edu/~YOUR_LOGIN/words

Create a sub-directory within your public_html directory, put some file there, edit the Apache configuration file (.htaccess) to allow directory listing of this directory (turned off by default for security reasons).

cd ~/public_html
mkdir files_public
cd files_public
echo "Options +Indexes" >> .htaccess
ls -a         # verify that the .htaccess file exists now
cat .htaccess # see what is in the file now
cp /var/junk/kinne/text-samples/shakespeare.txt .
cp /var/junk/kinne/text-samples/austen.txt .
# Now browse to https://cs.indstate.edu/~YOUR_LOGIN/files_public

Long Running Jobs

If you have a process that needs to run for more than a few minutes, you should run it like this:

time nice -n 19 whatever_command

Starting the command with time will give you a printout afterwards of how much time the job took (man time for more details). Having nice -n 19 makes your long running job run at a lower priority. Your job will finish just as fast, but it will interfere less with more important processes (other users on the system).

If the job is going to take an hour or more, you probably want to run it like this:

time nice -n 19 whatever_command > output.txt 2>stderr.txt &

The > output.txt will have output go to the output.txt file, and 2>stderr.txt (no spaces is important) redirects error output to stderr.txt. The & will detach the process from your terminal so that it can continue running even if your terminal disconnects. You can login again and check on it by running ps a to see all your running processes (not just the ones started on the current login).

Alternatively to redirecting the output and detaching, you could use the screen command to run the command in a terminal that you can detach. You can lookup help on the screen command for how to do that (for example, here).