Tutorial of Basic Commands in LINUX
Introduction
The LINUX environment is text-based, which means
you must enter the exact names of commands you want to take place. Each
time you press enter in the LINUX environment, you'll receive a prompt.
This prompt may differ from person to person, so throughout this tutorial
I will use
$ command
to indicate the prompt (given by system) followed
by command (typed by you). The LINUX environment is case-sensitive, meaning
lowercase alphabetic characters are considered different than their corresponding
uppercase alphabetic characters, including within passwords.
Note: Anywhere in the tutorial where you find section#, replace
with the course section number in which you are enrolled.
Screenshots may be added in the future.
Logging on to osprey
-
From a UNF machine, run a telnet client to hostname osprey.unf.edu
* SecureShell
-
Enter your osprey userID
* your N number
-
Enter your osprey password
Hit the <Enter> key if the system asks you what
terminal type. This means you are accepting the default answer (listed
as [vt100]).
Working in the LINUX file system
ls, pwd, and cd
-
Type ls to get a listing of the current directory contents
$ ls
* Directory names are shown with a trailing / although
it is not part of the name itself. Files do not have a /.
* Executable files (those which can be run as commands)
are shown with a trailing * although it is not part of the name. This can
be dangerous since the * is also the wildcard meaning "match everything".
-
Type ls -l to get a listing in long view which shows
you file sizes, modification dates and times, owner, and permissions
$ ls -l
-
Type pwd to see in what directory of the file system
you are currently located
$ pwd
You should still be in your home directory.
-
Change to the public directory (cd)
for this class
$ cd /var/public/cop2220/jgaudry
-
Type pwd to see you are now located in that directory
$ pwd
-
Type ls to get a listing of its contents
$ ls
-
Change to the parent directory
$ cd ..
-
Type ls to get a listing of its contents
$ ls
-
Change back to your home directory
$ cd
mkdir, touch, and wildcards (? and *)
-
Make a new directory named tempdir
$ mkdir tempdir
You made it but you didn't enter it yet. You are
still in your home directory.
-
Type ls to get a listing of your home directory and you
should see the new directory tempdir/
$ ls
-
Change into the new directory
$ cd tempdir
-
Type pwd to see your new location in the file system
$ pwd
-
Type ls to get a listing
$ ls
It should be empty.
-
Make a file called temp using the touch utility
$ touch temp
Touch either creates a nonexistent file or updates
the date/timestamp of an existing file
-
Type ls to see the contents of the tempdir
$ ls
and you should see the file temp.
-
Make another directory within tempdir called tempdir
$ mkdir tempdir
-
Type pwd to see your current location in the file system
$ pwd
-
Type ls to see the contents of this directory
$ ls
and it should show you file temp and directory tempdir/.
-
Change to the inner tempdir directory
$ cd tempdir
-
Type pwd to see your current location in the file system
$ pwd
-
Type ls to see the contents of the current directory.
It should be empty
$ ls
-
Make four files, temp1 temp2 temp50 and notemp, using
the touch utility
$ touch temp1
$ touch temp2
$ touch temp50
$ touch notemp
-
Type ls to see the contents of the current directory
$ ls
and you should see the new files.
-
Use wildcards to see filtered lists
$ ls temp? should show you
temp1 and temp2
$ ls t*
should show you all but notemp
$ ls *
should show you all
-
Type cd with no arguments to change back to your home
directory (works from anywhere in the file system)
$ cd
-
Type pwd to see where you are
$ pwd
-
Type ls with an argument to see contents of other directory/file
locations, either relative or absolute
$ ls tempdir
Keep in mind you are not in the outer tempdir. You're
still in the home directory, but you can see the contents of any directory
for which you have permission.
-
Type ls to see the contents of the inner tempdir from
your current home directory location
$ ls tempdir/tempdir
-
Change to the inner tempdir
$ cd tempdir/tempdir
-
Type pwd to see your location
$ pwd
-
Type ls to see the contents of the current directory
$ ls
-
Back up to the parent directory
$ cd ..
-
Type pwd to see your location
$ pwd
-
Type ls to see the contents of the current directory
$ ls
rm and rmdir
-
Try to delete the inner tempdir directory
$ rmdir tempdir
It should tell you that it cannot delete because
that directory isn't empty.
-
Type ls to see the contents of the current directory
$ ls
-
From the current location (outer tempdir), delete all
files within the inner tempdir
$ rm tempdir/*
BE VERY CAREFUL NEVER TO REMOVE ALL FILES IN CURRENT DIRECTORY ($ rm *)
UNLESS YOU ARE ABSOLUTELY SURE OF WHERE YOU ARE LOCATED AND WHAT YOU ARE
DOING. YOU MAY ACCIDENTALLY REMOVE OPERATING SYSTEM FILES OR YOUR C SOURCE
CODE.
-
Type ls to see the contents of the current directory
$ ls
-
Type ls with an argument to see the contents of the inner
tempdir
$ ls tempdir
It should be empty
-
Delete the inner tempdir
$ rmdir tempdir
Works this time.
-
Type ls to see the contents of the current directory
$ ls
-
Back up to the parent directory (the home directory)
$ cd .. or in this case $ cd
-
Type ls to see the contents of the current directory
$ ls
Outer tempdir still exists and is located in the
home dir.
cp and mv
-
Create a new file temp3 in the home dir
$ touch temp3
-
Copy it to the tempdir
$ cp temp3 tempdir
-
Type ls to see the contents of the current directory
$ ls
File temp3 still there.
-
Type ls with an argument to see the contents of the outer
(now only) tempdir
$ ls tempdir
File temp3 also there.
-
Copy temp3 from the homedir to the tempdir and give it
a new name
$ cp temp3 tempdir/newtemp3
-
Type ls with an argument to see the contents of tempdir
$ ls tempdir
-
Move temp3 to the tempdir and give it a new name
$ mv temp3 tempdir/movedtemp3
-
Type ls to see the contents of the current directory
$ ls
File temp3 is gone
-
Type ls with an argument to see the contents of tempdir
$ ls tempdir
-
Rename a file within tempdir from the home directory
$ mv tempdir/temp3 tempdir/renamed
-
Type ls with an argument to see the contents of tempdir
$ ls tempdir
-
Change into tempdir
$ cd tempdir
-
Type pwd to see your location
$ pwd
-
Type ls to see the contents of the current directory
$ ls
-
Rename a file to an existing filename
$ mv renamed temp
-
Type ls to see the contents of the current directory
$ ls
Shows renamed is gone and temp still there, but actually
original temp was deleted and file renamed was changed to filename temp.
Displaying files
-
Copy the file mary.txt from the public directory to your
current location (should be tempdir)
$ cp /var/public/cop2220/jgaudry/mary.txt .
-
Make a subdirectory called myfiles
$ mkdir myfiles
-
Copy the file humpty.txt from the public directory to
myfiles
$ cp /var/public/cop2220/jgaudry/humpty.txt myfiles
-
Type ls to see the contents of the current directory
$ ls
-
Type ls with an argument to see the contents of myfiles
$ ls myfiles
-
Display the contents of mary.txt
$ cat mary.txt
-
Display the contents of humpty.txt
$ cat myfiles/humpty.txt
Scrolls off the screen because is bigger than one
screen
-
Try again using a different display tool
$ less myfiles/humpty.txt
Use the space bar to see subsequent screens, use
the j and k keys to move down and up a line at a time, respectively, use
q to quit
Changing permissions
-
Display a listing of the current directory in long form
$ ls -l
Note the permissions on the files and directories
-
Remove all permissions (read, write, and execute) for
group and other users to the file mary.txt
$ chmod go-rwx mary.txt
-
Display a listing of the current directory in long form
$ ls -l
-
Display a listing of the myfiles subdirectory in long
form
$ ls -l myfiles
-
Remove read permission for group and other on all files/subdirs
in myfiles
$ chmod go-r myfiles/*
-
Display a listing of the current directory in long form
$ ls -l
Didn't change the permissions on myfiles itself,
just the files/dirs in it
-
Display a listing of the myfiles subdirectory in long
form
$ ls -l myfiles
See?
-
Add write permission for other on myfiles
$ chmod o+w myfiles
-
Display a listing of the current directory in long form
$ ls -l
Changed the permissions on myfiles itself...
-
Display a listing of the myfiles subdirectory in long
form
$ ls -l myfiles
...but not on its contents
Compiling, testing, and turning in C source
electronically
-
Change to the public directory
$ cd /var/public/cop2220/jgaudry
-
Display a listing
$ ls
You should see the files you copied before
-
Copy the file mary.c to your tempdir
$ cp mary.c ~/tempdir OR $ cp mary.c /home/<lastinitial>/<userID>/tempdir
Note the spaces separating command and arguments
-
Change back to your tempdir
$ cd ~/tempdir OR $ cd then $ cd tempdir
-
Display a listing
$ ls
-
Display the contents of the file
$ cat mary.c
It's a C source code file.
-
Compile the source code
$ gcc mary.c
-
Display a listing
$ ls
The compiler created the executable file a.out
-
Run the program to make sure it executes properly
$ ./a.out
It should display the nursery rhyme.
-
Turn in the C source to the assignment description jgaudry.tutorial
$ turnin mary.c jgaudry.tutorial
Note you are NOT turning in the executable, you are
turning in the source.
-
Check that you turned it in successfully
$ turnin -c jgaudry.tutorial
-
Display a long listing
$ ls -l
Make sure the byte size of mary.c is the same size
as what turnin -c told you was turned in.
Creating a text file (C source code is text)
-
Create a new file using pico
$ pico
Note the commands listed at the bottom of the screen.
The ^ symbol means hold down the control key <Ctrl> and press the appropriate
letter.
-
Type in some information into the file.
-
Save the file using the command ^O Write Out (hold <Ctrl>
and press O).
-
It prompts you for a filename. Type mytext and press
<Enter>.
-
Type some more information into the file.
-
Exit pico using the command ^X Exit (hold <Ctrl> and
press X).
-
It asks you whether you want to save changes. Type Y
for yes (choices listed at bottom).
-
It asks you for the filename and puts mytext in as the
default filename. Press <Enter>. You're back at the LINUX prompt.
-
Display a listing
$ ls
and you see your file mytext
-
Display the file
$ cat mytext
-
Edit the file using pico
$ pico mytext
and the editor starts with the file mytext loaded.
-
Exit the editor with the command ^X.
Creating an email message and attaching a file
-
Start the email reader
$ pine
-
At the bottom of the screen, it may ask you whether you
want to run a tutorial or move your saved mail to a different name. Answer
however you would like.
The main menu should display.
-
To read your new messages, choose I for Inbox (or use
the arrow keys).
Anytime you want to go back to the main menu, press
M (if you're not in edit mode).
-
Compose a new message by pressing C from the main menu.
Note the commands listed at the bottom of the screen are similar to pico.
-
Put in jgaudry as the recipient and press <Enter>.
-
Press <Enter> to skip the cc: field
-
To attach a file, use the command ^J Attach.
Then either type the filename (relative path from
home directory no matter where current location OR absolute path) or use
the command ^T to go to a file listing of your home directory. We'll do
the latter.
-
Go to tempdir with the arrow keys and press <Enter>,
then go to myfiles with the arrow keys and press <Enter>, then go to
humpty.txt and press <Enter> to attach the file.
-
Press <Enter> to skip the Attachment Comment.
The file is correctly attached to the email.
-
Press <Enter> to move to the Subject line.
-
Type Humpty and press <Enter>
-
Type me a message.
-
Use the command ^X to send (NOTE it is to send, not exit
as in pico).
-
Press Y to confirm the send.
-
Press L to view your folder list.
-
Choose sent-mail with the arrow keys and press <Enter>.
Note the last message sent is to me on the current
date.
-
Press M to go the main menu.
-
Press Q to quit pine.
You're back at a prompt.
Viewing online help files
-
Get online help for the pwd command
$ man pwd
Man uses the less program to display help files,
so press q to quit less.
Cleaning up
-
Display current location
$ pwd
It should be tempdir
-
Remove contents of myfiles
$ rm myfiles/*
-
Remove myfiles directory
$ rmdir myfiles
-
Back up to the parent (the home directory)
$ cd .. or in this case
$ cd
-
Remove contents of tempdir
$ rm tempdir/*
-
Remove tempdir directory
$ rmdir tempdir
Logging off
-
Log off the system
$ exit