Unix Basic Cmnds
Unix Basic Cmnds
hills
Basic Linux Commands
Linux Fall 2015
Each of the commands included here must be entered
at a bash prompt: [your login id@hills ~]$
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.
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:
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 -a displays the names of all the files in the current directory (including hidden files).
more <fn> displays the contents of the file <fn> one screen (about 20 lines) at a time.
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.
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?
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.
$ 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.
$ 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.
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.
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.
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.