Agenda Basic Unix Commands (Chapters 2 & 3)
Miscellaneous Commands: which, passwd, date, ps / kill
Working with Files: file, touch, cat, more, less, grep,
head, tail, cp, mv, ls sort, diff
Communicating with Users who, finger
Textbook Coverage These slides are based on
Chapters 2 and 3 of “A Practical Guide to Linux”
Read pages 36 to 38, 41 to 46, and 49-57
Miscellaneous Commands
which passwd date ps / kill
which which is a utility that lists only the
directory path of the command that the shell will run when the user issues the command from the shell prompt.
For Example: which cp
passwd A user can change their account
password by issuing passwd command at shell prompt. The user will be prompted for their current password and then be prompted for new password and confirmation.
date The date command is used to display
the current date and time.
Example: date
Note: If you have superuser or "root" access, you can change the computer system's date and time.
ps / kill As mentioned in last week’s notes, the Unix OS
continually runs processes (jobs). The ps command is used to provide status information regarding the user’s processes, such as PID (process I.D. number). The kill command can be used to terminate process number (eg. kill [PID] or kill –9 [PID])
Options (for ps command):
-l Provides detailed process status info (eg parent PID)-a Provides process status info for all processes
-al Provides detailed info for all processes
Working with Files file, touch, cat, more, less grep, head, tail cp, mv, ls sort, diff
file The file command is used to identify a
type of file (for example, whether the file is an ASCII (text), executable file, graphics file, MS-PowerPoint file, a directory file, etc...). This command is useful if file does not contain an extension and therefore is hard to identify.
Example: file try_me (Identifies the file type of "try_me")
touch The touch command is used to create empty
files. This command is useful to create empty files to be edited later with content. Another use for this command is to create empty files in order to practise using Unix commands that may require a filename such as ls, cp, mv, etc…
Example: touch file1 file2 file3
(Creates 3 files in current directory)
cat The cat command is used to combine the
contents of multiple files (“catenate” means to join together). This command can be used to display contents of small files (that will fit on your terminal's display screen).
Example: cat hello.c (displays contents of c program
"hello.c")
more The more command displays a file, one
screenful at a time.
Example: more large_file
Movement keys (within more command): <spacebar> Move to next screen
b Move to previous screen<enter> Move to next line/car Search for pattern "car"q Exit to shell
less The less command is similar to more
command, but “less” command contains more movement and search commands than "more" command. “less” is available in bash, not ksh.
Example
less large_file
Note: You are not required to learn "less" command for this course, but if you are interested in using this command, you can refer to the online manual.
grep The grep command is used to search for
a pattern whether contained in files or from other forms of input (eg. keyboard).
Example: grep "frog" data (matches and displays lines in
file called "data" that contain pattern "frog")
Options: -c displays # of lines that contain a match -i ignores case sensitivity -v displays lines that do not match the pattern
head The head command displays the
beginning lines of a file. This command is useful to identify any heading information of a file.
example: head fname (displays the first 10 lines of
"fname")
Options: -n displays the first "n" number of lines
tail The tail command displays the ending
lines of a file. This command is useful for viewing files that continually add information to the bottom of a file such as log files (eg. Last person to logon, or last system message).
Example: tail fname (views the last 10 lines of "fname") Options: -n displays the last "n" number of lines +n displays all lines from line "n" to the end of the file
cp The cp command is used to copy one or
more files between directories, or to make backup copies of files within the same directory.
Example: cp /public/ipc144/hw.c /home/jsmith/
(copies file "hw.c" from “/public/ipc144" directory to jsmith’s home directory)
Options: -R subdirectories & contents are copied -i prompts user to overwrite existing file
mv The mv command is used to move or
rename files. Examples:
mv hw.c work(moves file "hw.c" from current directory to subdirectory called "work”, assuming directory “work” exists) mv hw.c hello.c(renames file "hw.c" in current directory to "hello.c”) Options:-i prompts user to overwrite existing file
ls The ls command is used to display
information regarding a file or directory.
Example: ls (Displays a compact listing (filenames only) contained in current directory, or in a specified directory) Options:
-a short display of all files (incl. hidden files)-l detailed display of files (excl. hidden files)-al detailed display of all files-F displays / after directory, * after executable file
sort The sort command is used to sort files. Very useful as a filter to sort output of
the previous command. Example: sort fname (alphabetically sorts (in ascending
order) the contents of "fname")
Options: -r sorts in reverse (descending order) -n sort numerically -kn Sorts by column number "n" -u sorts and only displays unique lines
diff The diff command displays the differences
between two files. If there are no differences in the files, there is no display. If there is a display the command provides instructions on how to make the first file identical to the second file.
Example:diff file1 file2
Getting Info About Users who finger
who Used to display names of users logged
into system.
Example: who
Options: -H displays headings above user information -i displays # of minutes user was idle
finger Used to display user names and
related information. Example: finger jsmith (Will provide information regarding user "jsmith")