Download presentation
Presentation is loading. Please wait.
Published byRoderick Stevenson Modified over 9 years ago
1
BIF713 Basic Unix/Linux Commands Getting Help with Commands
2
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.
3
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.
4
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
5
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.
6
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.
7
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!
8
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.
9
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 screen b Move to previous screen enter Move to next line /car Search for pattern "car" q Exit to shell less filepath Works like more command, but contains more navigation features.
10
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...
11
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
12
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”).
13
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.txt working.txt Note the results from using filename expansion: ls work* work1.txt work2.txt work3.txt work4.c worka.txt working.txt ls work?.txt work1.txt work2.txt work3.txt worka.txt ls work[1-3].txt work1.txt work2.txt work3.txt ls work[!1-3].txt worka.txt
14
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
15
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.
16
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).
17
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.