1 / 15

Unix Basics

Unix Basics. Chapter 4. The Filesystem. Partitions / - The root partition: essential system binaries & configuration files /bin contains shells, ls, mkdir, etc. /usr – Operating system binaries & source code /usr/include contains c header files ie: stdio.h

Download Presentation

Unix Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix Basics Chapter 4

  2. The Filesystem • Partitions • / - The root partition: essential system binaries & configuration files • /bin contains shells, ls, mkdir, etc. • /usr – Operating system binaries & source code • /usr/include contains c header files ie: stdio.h • /usr/bin contains executables ie: gcc, g++, locate, where, passwd, etc. • /usr/local – Administrator installed programs • ie: apache web server, samba file server, etc. • /tmp – Temporary files

  3. Partitions Continued … • /var – Files that change regularly • ie: mail spools, printer spools • /dev – Device files • Provides access to all hard drives, ports, tape drives, floppy drive & cdrom drive. • /users – User home directories • Some UNIX servers use /home instead • On Turing, all of your student accounts are in /users/student ie: /users/student/lbburford

  4. Moving Around the Filesystem • cd – change directory • Absolute paths – specify the full path from the root directory (/) • ie: cd /usr/include • Absolute paths always have a leading slash • Relative paths – specify the path from the present working directory • Relative paths never have a leading slash • For example, let’s assume I’m currently in the /usr directory • The command cd bin would take me to /usr/bin not to /bin

  5. Moving Continued • Special characters • . – current directory • .. – parent directory • ie: from the /usr/bin directory, cd .. would take you to the /usr directory. • ~ - home directory • cd ~ will take you to your home directory • cd ~user will take you to user’s home directory

  6. You’ve changed directories, how do you find out what’s in there? • ls – Directory listing • ls -a - list all files in the current directory. Files beginning with a ‘.’ are hidden. Using the -a flag will show those files. • ls -l - list all files in the current directory with permissions, user and group information, size, and last modified date • ls -al - lists extended information about all files in the current directory • pwd – Present working directory • If you forget which directory you’re currently working in, the pwd command will show you.

  7. Working with Files & Directories • cp – copy file(s) • cp source destination • mv – move & rename files • mv source destination • rm – delete a file or directory • rm filename • rm -R directory • recursively deletes all files in the specified directory, then deletes the directory itself. • mkdir – make directory • mkdir directory

  8. File Permissions • There are 3 different types of permissions for files & directories on UNIX systems • Read • On files, allows the file to be opened • On directories, allows a file listing (ls) inside the directory • Write • On files, allows the file to be modified/deleted • On directories, allows the creation of files in the directory • Execute • On files, allows the file to be executed (run as a program) • On directories, allows traversal inside the directory (lets you cd into the directory)

  9. File Permissions • There are 3 different sets of users for which permissions are set on a file. • Owner – the person who owns the file • Group – The group that owns the file • World – Everyone else • When you do an ls –l in a directory, you’ll see each file has a permission entry like this: • rwxr-xr-x • This type of entry is read left to right, the first 3 letters are for the user, the second 3 letters are for the group, and the third three letters are for the world. A hyphen indicates no permission. • This particular entry means that the user has read, write, and execute permissions, while the group and the world have read and execute permission on it.

  10. File Permissions Continued • The chmod command is used to modify file and directory permissions • chmod permission file • permission in the above command is a 3 digit number. The first digit represents the owner permission, the second represents the group permission, and the third represents the world permission. • Read = 4 • Write = 2 • Execute = 1 • Add the numbers of the permissions you wish to assign together • ie: read and write = 4 + 2 = 6 • Apply the same principle for each set of users

  11. File Permissions Exercise • Let’s assume we have a file called test.sh • We want to allow the owner to have all permissions, the group to have read and write permissions, and the world to have only execute permission. What is the 3 digit number representing the permissions we want? • Let’s start with the owner: read + write + execute = permission • 4 + 2 + 1 = 7 • Group = read + write • 4 + 2 = 6 • World = execute • 1 • Now put it all together • Permission = 761 • The final command is: chmod 761 test.sh

  12. Getting Help • man – Display manual pages aka: man pages • man command • If when you run man on a particular command, you get the “builtin” man page, it means the command you specified is provided directly by the shell and not as an external program. In this case, you need to look up the man page for the shell you are using to find information about the command. • man also works for C functions provided by the system. • ie: man printf

  13. Editing Text • There are several options for text editors • pico – easy to use editor with on screen menus. • ee – similar to pico, menus not quite as intuitive. • vi – the most powerful text editor. No on screen menus, high learning curve. The only editor guaranteed to be on any UNIX system you encounter. • Textpad – while not a UNIX application, it is probably the best available choice for a Windows text editor with C syntax highlighting. Available for use on all CS computers, allows you to work on your programs through a mapped network drive.

  14. Other Useful Commands • pine – email client with on screen menus • lpr – print a file • lpr –P prlaser myfile.c • available printers on Turing: prlaser, syslaser, memlj, mem2lj, advlaser • grep – search for specific text • less & more – show the contents of a file, or page output of a command • ps – show all of your currently running processes • kill – allows you to send signals to your processes • kill -TERM pid • TERM, HUP, & 9 are the most common signals you’ll need to send

  15. Hints to make your life easier • ./ - UNIX only knows about commands in your path. To run a program/script not in your path, you must either specify the whole path to the executable, or if you’re in the same directory as the executable, then type ./name_of_executable • ./a.out • tab – auto complete file names & paths • | - pipe operator, allows you to redirect the output of one command to the input of another • ls | grep .c • ls -l | lpr -P prlaser • ls | more • > - output redirection operator • ./a.out > output.txt • up arrow – allows you to scroll through your command history instead of retyping a command

More Related