
Introduction to Unix: Fundamental Commands Ricky Patterson – UVA Library Based on slides from Turgut Yilmaz – Istanbul Teknik University 1 • What We Will Learn • The fundamental commands of the Unix operating system. • Everything here is also applicable to the Linux operating system. 2 • What Is UNIX? • UNIX is a computer operating system, a control program that works with users to – run programs, – manage resources, and – communicate with other computer systems. • Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser system. Any of these users can also run multiple programs at the same time; hence UNIX is called multitasking. 3 • Shell Commands of UNIX • Unix Commands •When you first log into a unix system, you are presented with something that looks like the following: /home/ricky# meander:> •That “something” is called a prompt. As its name would suggest, it is prompting you to enter a command. •Every unix command is a sequence of letters, numbers and characters. But there are no spaces. 4 • Unix is also case-sensitive. This means that cat and Cat are different commands. • The prompt is displayed by a special program called the shell. • Shells accept commands, and run those commands. • They can also be programmed in their own language. These programs are called “shell scripts”. Shell scripts are extremely powerful, but beyond the scope of this introduction. 5 • When you first login, the prompt is displayed by bash, and you are running your first unix program, the bash shell. • As long as you are logged in, the bash shell will constantly be running. • Other shells are available, including csh, tcsh, and ksh. 6 • Unix Commands • obtaining help • The man command displays reference pages for the command you specify. • The UNIX man pages (man is short for manual ) cover every command available. • To search for a man page, enter man followed by the name of the command to find . • For example: ricky@meander:~>man ls 7 To exit Press “q” 8 • man (obtaining help) • There is also a keyword function in man. • For example; – If you are interested in any commands that deal with Postscript, the printer control language for Adobe – Type man -k ps or man -k Postscript, you’ll get a listing of all commands, system calls, and other documented parts of unix that have the word “ps” (or “Postscript”) in their name or short description. • This can be very useful when you’re looking for a tool to do something, but you don’t know it’s name-or if it even exists! 9 • cat • cat command is used to concatenate or displays the contents of a file. • To use it, type cat, and then press enter key: /home/larry# cat • This produces the correct result and runs the cat program. Prompt Command İf you type this row and then press enter The text indicates what we typed to cat • To end many unix command, type end-of-file command (EOF) [hold down the key labeled “Ctrl” and press “d” (Ctrl+d) ] 10 • To display the contents of a file, type cat filename 11 • To see linux commands press Tab key, • If you want to learn commands beginning with c you can write c then press Tab key /home/larry# c 12 • Storing information • Unix provides files and directories. • A directory is like a folder: it contains pieces of paper, or files. • A large folder can even hold other folders-directories can be inside directories. • In unix, the collection of directories and files is called the file system. Initially, the file system consists of one directory, called the “root” directory • Inside the “root” directory, there are more directories, and inside those directories are files and yet more directories. 13 • Each file and each directory has a name. • A short name for a file could be joe, • while it’s “full name” would be /home/larry/joe. The full name is usually called the path. • The path can be divide into a sequence of directories. • For example, here is how /home/larry/joe is read: /home/larry/joe The initial slash indicates the root directory. This signifies the directory called home. It is inside the root directory. The second slash corresponds to the directory larry, which is inside home. joe is inside larry. 14 • A path could refer to either a directory or a filename, so joe could be either. • All the items before the short name must be directories. Root Directory Directory Directory home Sub-Directory larry Directory structure File File joe 15 • Looking at directories with Is • The command ls lists files. • If you try ls as a command, it will list the files (and directories) contained in the current directory. If you have files, ls lists the names of files in the directory 16 • If you want a list of files of a more active directory, try the root directory. /home/larry# ls / bin etc install mnt root user var dev home lib proc tmp usr vmlinux “/” is a parameter saying what directory you want a list for. In this case, it is the top level directory “/” Some commands have special parameters called options or switches. To see this try: /home/larry# ls –F / bin etc/ install/ mnt/ root/ user/ var/ dev/ home/ lib/ proc/ tmp/ usr/ vmlinux/ The -F is an option. It displays file types. 17 • An option is a special kind of parameter that starts with a dash “-” • An option modifies how the program runs, but not what the program runs on. • For ls, -F is an option that lets you see which things are directories, which ones are special files, which are programs, and which are normal files. • Anything with a trailing slash “/” is a directory. • ls -l file* displays files starting with “file” • ls –l displays all details 18 • Many unix commands are like ls. • They have options, which are generally one character after a dash, and they have parameters. • Unlike ls, some commands require certain parameters and/or options. You have to learn these commands. 19 • pwd • pwd (present working directory) tells you your current directory. – Most commands act, by default, on the current directory. For instance, ls without any parameters displays the contents of the current directory. • cd • cd is used to change directories. • The format of this command : cd new-directory (where new-directory is the name of the new directory you want). 20 • For instance, try: /home/larry# cd /home /home# • If you omit the optional parameter directory, you’re returned to your home, or original directory (the same as typing cd ~ ). Otherwise, cd will change you to the specified directory. • There are two directories used only for relative pathnames: • The directory “.” refers to the current directory • The directory “..” refers to the parent directory of the current directory •The directory “..” is most useful moving back up a directory: cd .. •The command “cd –” will return you to the most recent 21 directory visited. • mkdir mkdir (make directory) is used to create a new directory, • It can take more than one parameter, interpreting each parameter as another directory to create. • By default, it will create the new directory as a subdirectory of the current directory • rmdir rmdir (remove directory) is used to remove a directory, • rmdir will refuse to remove a non-existant directory, as well as a directory that has anything in it. 22 • Moving Information • The primary commands for manipulating files under unix are cp, mv, and rm. They stand for copy, move, and remove, respectively. • cp • cp is used to copy contents of file1 to file2 cp file1 file2 (contents of file1 is copied to file2 in the same directory) cp folder1/file1 folder2 (contents of file1 is copied to file1 in the inside of folder2 directory) 23 • rm • rm is used to remove a file. – rm filename ---> removes a file named filename • mv • mv is used to move a file. – mv filename /path/newname ---> moves a file named filename to a new location, with a new name • looks like cp, except that it deletes the original file after copying it. • mv will rename a file if the second parameter is a file. If the second parameter is a directory, mv will move the file to the new directory, keeping it’s shortname the same. 24 • Some Other UNIX Commands • The Power of Unix • The power of unix is hidden in small commands that don’t seem too useful when used alone, but when combined with other commands produce a system that’s much more powerful, and flexible than most other operating systems. • The commands include sort, grep, more, cat, wc, spell, diff, head, and tail. 25 • Operating on Files • In addition to the commands like cd, mv, and rm, you learned in shell section, there are other commands that just operate on files, but not the data in them. • These include touch, chmod, du, and df. • All of these commands don’t care what is in the file. 26 Some of the things these commands manipulate: • The time stamp: Each file has three dates associated with it. These are creation time, last modification time and last access time. • The owner: the owner of files • The group: the group of users • The permissions: read, write, execute permissions of files. The permissions tell unix who can access what file, or change it, or, in the case of programs, execute it. Each of these permissions can be toggled separately for the owner, the group, and all the other users. 27 drwxr-xr-x 2 dag users 6 Dec 6 2016 file.txt file name group owner others read, write, execute permissions of files • touch • touch will update the time stamps of the files listed on the command line to the current time.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages39 Page
-
File Size-