0% found this document useful (0 votes)
83 views6 pages

Unix Basic Cmnds

This document provides instructions for basic Linux commands for file management, printing, and scripts. It discusses how to change your Linux password using the passwd command. It also covers commands for listing, viewing, copying, appending, and deleting files, as well as printing ASCII text files from Linux to the laser printers. Rules and suggestions are provided for Linux passwords.

Uploaded by

Laura Craig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views6 pages

Unix Basic Cmnds

This document provides instructions for basic Linux commands for file management, printing, and scripts. It discusses how to change your Linux password using the passwd command. It also covers commands for listing, viewing, copying, appending, and deleting files, as well as printing ASCII text files from Linux to the laser printers. Rules and suggestions are provided for Linux passwords.

Uploaded by

Laura Craig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2

hills
Basic Linux Commands
Linux Fall 2015
Each of the commands included here must be entered
at a bash prompt: [your login id@hills ~]$

Changing Your hills Linux Password

passwd CONTENTS: COMMAND SUMMARY


Linux commands in this handout explore:
begins the Password Change Sequence: The Optional Password Change..page 1
File Commands.page 2
1. Enter the passwd command. Printing Commands.....page 3
2. The system responds: Script Command..page 4
Sample Script for Java Students..page 5
Changing password for user <your login name>. Compress and Restore Files...page 5
Changing password for <your login name>. Sample Script for c++ Students.page 6
Linux Help Command..page 6
and prompts for the
(current) password:
3. Enter your current password (to confirm your identity).
For reasons of security, the password will not display on the screen.
Dont be alarmed. The characters you enter are sent to the server.
4. The prompt New password: appears.
Please refer to Rules and Suggestions for Passwords at CCSF below.
The system will end the password change sequence if you take too much time, so decide upon your new
password before you begin. Refer to Rules and Suggestions below.

5. If you get an error message such as BAD PASSWORD: is too simplistic/systematic, the password
change sequence returns you to Step 4 and gives you another opportunity to enter a new password.
Sometimes, the message is just a warning; if the password is acceptable, youll see the prompt in Step 6.

6. The prompt Retype new password: appears.

7. Enter the new password a second time for confirmation. If the two password entries do not match, you are
returned to Step 4 to try again.
8. If you make repeated mistakes, the system will end the password sequence with the message:
Have exhausted maximum number of retries for service.

Rules and Suggestions for Passwords at CCSF

Rules:
1. Password rules for Red Hat Linux are not clearly defined. The computer systems in the ACRC have different
password allowances and limitations. We suggest generic considerations that may be used for any of them:
at least 9 positions; at least one capital letter, at least one lowercase letter, and at least one numeric digit.
2. Dont use predictable patterns or sequences; dont rotate or reverse front and back portions of passwords.
3. Dont use spaces or characters that carry special meaning in Linux, like * ? / \ !
4. Remember that Linux is case sensitive. Uppercase letters may be used, but keep in mind that any uppercase
letter(s) you use in a password must be entered in uppercase at every login.

Suggestions:
1. Don't use obvious passwords like your first name; even words found in the dictionary are too predictable.
2. Think of a phrase thats easy to remember (or a favorite song title or lyric) and use the first letter of each of
the words (and at least one number).
3. Example: From the sentence: I don't want to do this one, you might create the password: Idw2dt1
hills Linux #2: Basic Linux Commands

Using Files Note: in the following sections, <fn> stands for the name of one of your saved files.
Displaying the Names of Saved Files

ls displays the names of files in the current directory that are not hidden (uses lowercase letter L) .

ls -l or ll displays detailed information about non-hidden files in the current directory


(All uses are the lowercase letter L, not the digit one).
Column 1: the file type and the permissions (read, write, and/or execute for owner, group, and other users)
Column 2: the size of the file in little links
Column 3: the login ID of the owner of the file
Column 4: the group to which the owner of the file belongs
Column 5: the size of the file in bytes
Column 6: the date of the last modification
Column 7: the time of the last modification
Column 8: the filename

ls -a displays the names of all the files in the current directory (including hidden files).

Displaying the Contents of a Text File

cat <fn> displays the file named <fn> on the screen


Example: To see what is in the file called prog1, enter: cat prog1
Use cat on short files containing ordinary text created with a simple text editor like nano.
Note: if you try to display a compiled program you'll get strange characters on the screen and the responses on
your terminal screen might be slow and unpredictable.

more <fn> displays the contents of the file <fn> one screen (about 20 lines) at a time.

When the more command is in effect:


Tap the Spacebar to advance from one screen of lines to the next.
Press the Enter key to advance one line at a time.
Tap the q key to quit before all the lines in the file have been displayed.

less <fn> allows scrolling both up and down through the file
Use the Escape key and then the V key to scroll back one screen. Use the Up Arrow key to move back one line.

Copying a File
cp -i <fn> <newfn> copies the contents of existing file <fn> into a new file <newfn>

Example: To copy the contents of the file called oldfile to a file called newfile, enter: cp -i oldfile newfile
Use of option i prevents accidentally overwriting an existing file you want to keep. It warns you if a file named
newfile already exists and requires overwrite confirmation of the file before copying: cp: overwrite newfile?
If you reply y for yes, the current contents of newfile will be replaced with the contents of oldfile.
A response of n for no aborts the copy process so that nothing happens.

Adding the Contents of One File to the End of Another (Appending)


cat file1 >> file2 adds the contents of file1 to the end of file2

This command does not change or remove the contents of file1. For use only with text files, not with compiled code

Deleting a File
rm <fn> deletes a file and frees the disk space it occupied
Use option i to safeguard against accidental file deletion; deletion confirmation is required: y for yes or n or no.
Example: the response to the command rm i myfile is rm: remove regular file myfile?

2 FALL 2015 ACRC HILLS LINUX HANDOUTS


hills Linux #2: Basic Linux Commands
Using the Laser Printers
ASCII text files created in your hills Linux account may be printed on laser printers after the files have been
downloaded to your Windows account home directory on H: drive.

Download the File Using a PC:


Log in to your Windows Intranetwork account.
From the right side of the Start menu, click Computer. In the Network Location section, find your Windows
home directory on H: drive. Double-click to open it. (In lieu of using your individual H: drive directory,
you may download to the Windows desktop, but be sure to delete the file(s) from the desktop after
printing.)
Double-click the yellow SSH Secure Shell Client for FTP icon on the Windows Desktop. (Refer to
the handout Using SSH Secure Shell Client for FTP to familiarize yourself with the details of its use.)
Login to your hills Linux account.
(Click the Quick Connect button or select the Quick Connect option from the File menu.)
Your Linux home directory should appear on the right (remote) side of the window.
Move to the directory that has the file you want to download. Highlight the name of the file.
For this step, be sure that the SSH window is restored down from its Maximized size) so
that your Windows home directory on the desktop is visible in the background. Use the
Restore Down button in the upper right corner of the SSH window to de-Maximize the
screen. Now click on the name or the icon of the highlighted file and drag it to your H:
drive window.
Right-click the mouse on the icon of the file you just dragged to your H: drive. Select the Open option at
the top of the contextual menu. The applications in the window are arranged alphabetically. Highlight
Notepad and then click the OK button at the bottom of the window.
Click on the File Menu and select the Print option.
Follow the instructions on the Laser Printing from Windows handout to complete the print process.
When the blue Print Control for Desktop window appears, proceed with instructions on the Laser Printing
from Windows handout to complete the printing process.
Dont forget to log off your hills server account by selecting the Disconnect option in the File menu. After
that, you can close the SSH Secure Shell Client application (and the Notepad application and the H: drive
directory window) by clicking the X in the red box in the upper right corner of each respective window.

Download the File Using a Macintosh:


It is not possible to print from a Macintosh unit in the ACRC.
The easiest way to print ASCII files from your hills account is
to follow the instructions in the previous section above; OR
Log in to your Macintosh Intranetwork account.
Double-click the Fugu blowfish icon on the Dock; or, find the
SFTP Fugu program in the Applications folder under the Go menu.
Type the name of the hills server in the Connect to: box provided: hills.ccsf.edu
Your hills username has already been entered if you are logged in to the Macintosh Intranetwork.
If you are using an Open Mac, type your hills username in the Username: box.
Now click the Connect button at the bottom.
On the next screen, enter your hills account password and click the Authenticate button to log in.
Locate the file you want to download for printing on the right side of the window. Click to highlight the
file name and then drag it directly to your Macintosh Desktop (in the background). (It is not necessary to
open the Desktop Folder on the left side of the Fugu window.)
Double-click the file icon on the Desktop to open it. Without a file extension, a text file will open in the
default TextEdit application.
Drop the File menu and click the Print option. In the lower left corner of the screen, theres a PDF
dropdown menu. Click it and select the second option Save as PDF.
Now save the .pdf to a portable medium, like a USB drive, and follow the instructions on the Laser Printing
from Windows handout to complete the print process.
DONT FORGET to log off your hills account by clicking the Disconnect button on the
Fugu button bar. Then select the Quit [application] option from the end of the Fugu
menu application and the end of the File menu in the TextEdit application.
Because your Desktop is part of your Macintosh Home Folder, your hills document will be exclusively
available to you if it remains on the Desktop; it will not be available to any other Mac user at that workstation.
ACRC HILLS LINUX HANDOUTS FALL 2015 3
hills Linux #2: Basic Linux Commands

Scripting a Session
script <fn> copies the keystrokes you enter and the responses displayed
The script command captures whatever comes up on the screen between the time that you type in the script
command and the time that you stop the process with exit.
Script sessions can include capturing the interactive input and the screen responses of Linux commands or of
programs that display output to the screen.
The script session captured is written to the file you name in the script command or to a file called typescript if
you choose not to customize the filename.
script Linux response to this command is Script started, file is typescript
This means that Linux will copy everything that appears on the screen
even errors and error messages until you terminate the script session.
exit Linux response to this command is Script done, file is typescript
This means that everything that displayed on the screen during the script session
between the script command and the exit command has been written to a default
file named typescript.

If you want to name your script session instead of assuming the default script name, enter your script name after
the script command.

script hwk1 Linux response to this command is Script started, file is hwk1
As before, Linux captures the terminal display until the script session is ended.
Be very careful not to name your script session with the same name as your
program file or the script session will overwrite your program code.
exit Linux response to this command is Script done, file is hwk1
The script file in this example has been written to a file named hwk1

Script command does not append to the end of an existing file with contents, it replaces it, so dont name the script
with the name of a file you are still using or one that you intend to use at a later time.

Scripting procedure:
Enter the script command, followed by a space and the name of the file to which you want to save the
visual recording of the session.
Start whatever you want to copy (a common example would be to display a program's source code onscreen
with the cat command, and then compile and run the program). Refer to examples on pages 5 and 6.
When you have finished, stop the scripting process with the exit command.
You can then download the file to print it.
Be sure to exit the current script session before you begin another one. Subsequent script commands do NOT
end script sessions in progress or restart them. Script sessions are stopped with an exit command.

Warning: The script command does not work the same way when you are running multiple processes, especially
spawned shells.

ps u <your login id> shows all processes currently in progress.

PID TTY TIME COMMAND


12158 ttyp5 0:00 bash
28524 ttyp4 0:00 script
29275 pts/28 0:00 bash
28525 ttyp4 0:00 bash
12157 pts/28 0:00 script
12161 ttyp5 0:00 ps
Enter an exit command at the Linux prompt to discontinue each of the script commands in progress.
The last script started is the first script discontinued.

4 FALL 2015 ACRC HILLS LINUX HANDOUTS


hills Linux #2: Basic Linux Commands

Sample Script for Java Students

$ script hwk1
Script started, file is hwk1
Starts copying what will appear on the screen to a file named hwk1 in your current directory.

NEVER name the script with the same name as the java program.
The script file immediately destroys the program file by writing over it.

$ cat prg1.java
Displays the contents of the java source file prg1.java on the screen.
In this example, the script process records everything that appears on the screen in the file named hwk1.
When script command is in progress, editor commands like pico or vi are prohibited because the
printers cannot interpret the changes these commands create in screen displays.

NEVER cat the script file while it is in progress.


It will duplicate itself in the script in progress and never find the end of the file.
Use Ctrl/C to stop such a file from listing endlessly.

$ javac prg1.java
Compiles the java source code in prg1.java
There are different arguments that your instructor might recommend for use with this command.
Any error messages displayed on the screen would also be copied to the hwk1 file by the script process.

$ java prg1
Runs the compiled java code. The script process captures output displayed on the screen to the hwk1 file.

NEVER cat a file with compiled code. Object code is not a legible representation of your program.
The assembled java code can be executed with the java command to produce the intended output.

$ exit
Script done, file is hwk1
Ends the script (copying) process.
Now you can download hwk1 and print everything the script command captured.
Follow the instructions on page 3.

Compress and Restore Files


gzip <fn> compresses and stores the compressed file(s) with the .gz extension
This utility allows you to save storage space and to reduce file transmission time across networks. The amount
of compression depends upon the size and the content of the file(s). Source code or English text can be reduced
60-70%. More popularly used in Linux and Linux environments, the gzip command employs the same algorithm
as the zip command but allows for a greater degree of compression. It is generally preferable especially when
compressing large numbers of files.
gzip yourbigfile removes yourbigfile and replaces it with the compressed version yourbigfile.gz

gunzip <fn> restores the original decompressed file(s)


Compressed files are not in a format that can be displayed or printed, so they must be restored to their original
format for viewing.
gunzip yourbigfile.gz removes yourbigfile.gz and restores the original yourbigfile

ACRC HILLS LINUX HANDOUTS FALL 2015 5


hills Linux #2: Basic Linux Commands

Sample Script for c++ Students

script hwk1
Starts copying what will appear on the screen to a file named hwk1 in your current directory.

NEVER name the script with the same name as the C++ program.
The script file immediately destroys the program file by writing over it.

cat prg1.cpp
Displays the contents of the c++ source file prg1.cpp on the screen.
In this example, the script process records everything that appears on the screen in the script file named hwk1.

When script command is in progress, editor commands like pico or vi are prohibited because the
printers cannot interpret the changes these commands create in screen displays.

NEVER cat the script file while it is in progress.


It will duplicate itself in the script in progress and never find the end of the file.
Use Ctrl/C to stop such a file from listing endlessly.

gcc prg1.cpp
Compiles the source code in prg1.cpp The g++ command accepts most of the options that gcc accepts.
There are different arguments that your instructor might recommend for use with this command.
Any error messages displayed on the screen would also be copied to the hwk1 file by the script process.

a.out
Runs the compiled c++ code. The script process captures output displayed on the screen to the hwk1 file.
NEVER cat an a.out file. Object code is not a legible representation of your program.
The assembled c++ code can be executed with the a.out command to produce the intended output.

exit
Ends the script (copying) process.
Now you can download hwk1 and print everything the script command captured.
Follow the instructions on page 3.

Getting Help Online with a Linux Command


man <cmd>
You can read the pages of the Linux manual on your screen by using the man command followed by a space
and the name of the Linux command for which you want information. Entries are often long and contain many
options that you might not be interested in, but you can get a lot of information about the command, its options,
and the system environment in this way. The manual pages are displayed like the more command, so you can:
see the next page by pressing the spacebar
scroll up and down the manual page by piping it with the less command: man <cmd> | less
quit the manual command in progress and get back to the Linux prompt by pressing q

man -k <cmd>
If you just want to find out whether there is a manual entry for a particular command, or if you want to see
whether you have the correct spelling of a command, use this form of man. It gives a one-line response if the
manual page for the command exists on the system, or an error message if it doesn't.

6 FALL 2015 ACRC HILLS LINUX HANDOUTS

You might also like