bif713 basic unix/linux commands getting help with commands

17
BIF713 Basic Unix/Linux Commands Getting Help with Commands

Upload: roderick-stevenson

Post on 04-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: BIF713 Basic Unix/Linux Commands Getting Help with Commands

BIF713

Basic Unix/Linux CommandsGetting Help with Commands

Page 2: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Basic Unix/Linux Commands All of the commands you will learn

in this course will work in Linux and Unix operating systems.

The commands taught in this lesson will provide the basics to get practice issuing Unix/Linux commands.

Page 3: BIF713 Basic Unix/Linux Commands Getting Help with Commands

pwd / cd pwd

Used to display the user’s current (present) working directory. A user may need to where they are located on the computer system in order to build directories, copy files, etc…

cd directorypath

Used to change to a directory. Entering the cd command without the directorypath will change to the user’s home directory.

Page 4: BIF713 Basic Unix/Linux Commands Getting Help with Commands

ls ls

Used to display the contents of a directory (eg. Regular files or sub-directories). By default, the ls command displays non-hidden filenames only (i.e. files not beginning with a period).

The following are options associated with the ls command:

-a short display of hidden & non-hidden files -l detailed display of files (excl. hidden files) -al detailed display of hidden & non-hidden files -F displays / after directory, * after executable file

Page 5: BIF713 Basic Unix/Linux Commands Getting Help with Commands

mkdir / rmdir mkdir directorypath

Used to create a subdirectory with a directory. Multiple arguments can be used to create many subdirectories. The option –p allows for parent directories to be created.

rmdir directorypath

Used to remove only non-empty directories (i.e. directories that contain no subdirectories or regular files). A user cannot remove a directory from within the directory location itself. The user must at least be located in the parent directory.

Page 6: BIF713 Basic Unix/Linux Commands Getting Help with Commands

mv / cp mv sourcepath destinationpath

Used to move a file from one location to another and/or rename the file. The mv command can be used to move non-empty directories as well as files. The –i option asks for confirmation if the destination filename already exists.

cp sourcepath destinationpath

Used to copy a file from one location to another. The cp command can be used to backup important files, or get sample files from their instructors. The –i option asks for confirmation if the destination filename already exists.

Page 7: BIF713 Basic Unix/Linux Commands Getting Help with Commands

rm, rm –r, rm -ri rm filepath

Used to remove a regular file.

rm -r filepath

Used to recursively remove a directory file. Recursive means to descend to lower levels, which in this case, indicates that subdirectories and it contents are also removed.

Note: it is a good idea to include the –i option to confirm deletion of subdirectories and its contents!

Page 8: BIF713 Basic Unix/Linux Commands Getting Help with Commands

cat cat filepath

Used for a couple of purposes:

1. To join files (i.e. to concatenate files to be displayed on screen). For example, cat file1 file2 file3 would display the contents of file1 and file2 and file3 on the screen at the same time.

1. To display the contents of small files (between 1 and 24 lines).For example, issuing the command cat .bash_profile in your home directory would display the contents of your setup file.

Page 9: BIF713 Basic Unix/Linux Commands Getting Help with Commands

more / less more filepath

Used to display the contents of large regular files one screen at a time. The user can navigate throughout the file by pressing keys such as:

spacebar Move to next screenb Move to previous screenenter Move to next line/car Search for pattern "car"q Exit to shell

less filepath

Works like more command, but contains more navigation features.

Page 10: BIF713 Basic Unix/Linux Commands Getting Help with Commands

touch touch path

Used to update the date and time of existing files.

The touch command is also used for creating empty files. You will be using the touch command to create empty files when you practice the file management online tutorial later in this course ...

Page 11: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Filename Expansion Many of the commands discussed so far

make reference to a filename – e.g. and regular file to store data, or a directory.

Sometimes the user may not know the exact name of a file, or the user wants to use a command to apply to a number of files that have a similar filename

For example: work.txt, work2.txt, work3.txt

Page 12: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Filename Expansion Special characters can be used to expand a general

filename and use them if they match. You may have heard about “Wildcard Characters” – this is a similar concept.

Filename expansion Symbols:

* (star) – Represents zero or more characters that could any anything.

? (question mark) – Represents any single character

[ ] (character class) – Represents a single character that only represents a group or class of characters (i.e. group or “class” contained within square brackets – placing a ! Symbol after first square bracket means “opposite”).

Page 13: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Filename Expansion To demonstrate filename expansion, let’s assume the following

regular files are contained in our current directory:

work1.txt work2.txt work3.txt work4.c worka.txtworking.txt

Note the results from using filename expansion:

ls work*work1.txt work2.txt work3.txt work4.c worka.txt working.txtls work?.txtwork1.txt work2.txt work3.txt worka.txtls work[1-3].txtwork1.txt work2.txt work3.txtls work[!1-3].txtworka.txt

Page 14: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Other Unix/Linux Commands whoami

Used to display the username of the account’s owner.

finger username

Used to display additional information regarding the user (regardless whether or not the user is currently logged onto the system).

who

Used to display a list of other users currently logged on to the same system is the user. Useful options with the who command are –i and -T

Page 15: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Other Unix/Linux Commands passwd

Used to change an owner’s password. After issuing this command, the system will prompt the user for their existing password – if that password verifies, then the user is asked to enter and re-enter their new passwords, the user’s password is stored in the system database file /etc/passwd .

A few thing to consider with the passwd command:

While entering in the new password, feedback may be provided to reject unsuitable passwords (see previous notes on how to create a valid password)

The –f option can be used with the passwd command to change the user’s name in the /etc/passwd database file.

Page 16: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Other Unix/Linux Commands date

Used to display the current date and time of the server. The super-user (i.e. root-user) can use this command to set the date and time. Refer to the online manual to format date display.

cal

Used to display the current month’s calendar (by default). The user can also display the yearly calendar (year as the first argument), or a specific month for a specific year (month number as the first argument, and year as the second argument).

Page 17: BIF713 Basic Unix/Linux Commands Getting Help with Commands

Getting Help with Commands A comprehensive online manual for common UNIX/Linux

commands exists on your server

The online manual is a command called man

Command Structure:

man [options] command

Options: -k provides short (one-line) explanation relating

to the commands matching the character string. This can be used if user doesn’t know name of command. eg. man -k calendar