1 / 29

C151 Multi-User Operating Systems

Learn essential Linux commands, file systems, users, and environment variables. Practice commands such as ls, cd, man, cat, find, grep, and more for file manipulation efficiency.

rklinger
Download Presentation

C151 Multi-User Operating Systems

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. C151 Multi-User Operating Systems Linux Commands

  2. Expressions in Commands • Current directory: . • Parent directory: .. • Home directory: ~ • Root directory: /

  3. Path • Absolute path: complete sequence of directories to a file starting from the root directory /:/home/yul/c151/cat.jpg • Relative path: the sequence of directories to reach a file starting from the current directory:c151/cat.jpg • The absolute paths have the same meaning no matter what the working directory is. The relative paths depend on the current working directory. • An absolute path is the concatenation of the current working directory and the relative path:/home/yul/ + c151/cat.jpg

  4. Linux File Systems /root directory /binexecutable for single user mode /devdevices that can be mounted by the system /etclocal configuration, administrative things /homehome directories for most users /libshared libraries /mnt   temporary mount point for mountable devices /proc  kernel and process information /root  home of the superuser (root) /sbin  system binaries (executables) /tmp   temporary files /usr   lots of information used by the system

  5. Linux Users • There is one special user that has administrative powers - the superuser. It's name is root. Every user has a home directory that can be found under /home/username. They have an allocated disk space. • Every user’s home directory contains configuration (resource) files that define their environment. They all start with a dot. Example: .signature. • For example, the file ".cshrc" will always be executed whenever the user logs in or opens a terminal window.

  6. Environment Variables • The environment variables are global variables that are defined within the shell and that can be used for many purposes. • Their names are in general in all uppercase. • Display the value of an environment variable:echo $PATH • $PATH • lookup list for binaries to be executed. • $HOME • user's home directory

  7. Linux Commands • Small utilities/programs under Linux that can take options and arguments. • Argument: what the command applies to.ls/usr • Option: how do we want the command to be executedls–l • The options and arguments can be combined: ls-l/usr/include • Some commands take more than one argument • cp requires a source file and a destination file.

  8. More On Commands • Some useful commands: cd, ls, man, pwd, cat, find, grep, wc • Manipulating files and directories: mv, rm, cp, mkdir, rmdir

  9. Linux Commands • ls: list files • Example: ls ~ • cd: switch working directories • Example: cd \ • pwd: display current working directory • Example: pwd • man: display manual of command • Example: man ls • cat: display the entire content of a file • Example: cat lab1.txt

  10. Linux Commands • mkdir: create a directory • Example: mkdir C151 • rm:delete files • Example: rm *.txt • rmdir: delete a directory • Example: rmdir C151

  11. Linux Commands • Viewing the Contents of a File • The more command • Displays the entire contents of a file one page at a time • Spacebarmoves through file one page at a time • Enter key moves through file one line at a time • Only moves forward through a file, not backward • Exit: q • Example 1: more lab1.txt • Example 2: man ls | more

  12. Linux Commands • Viewing the Contents of a File (continued) • The less command • Nearly equivalent to the more command • Allows you to move forward and backwardin the file • Usage: same as more

  13. Linux Commands • Viewing the Contents of a File (continued) • The head command • Displays just the first ten lines of a file • The tail command • Displays just the last ten lines of a file • Usage: same as more and less

  14. Linux Commands • The find command: find files • The argument is a path. The name of the file must be specified with the option –name. • There more options • Find file with name “hw1.txt” in current directory (including sub directories) find./-name hw1.txt • Find file with name extension “.txt” in root (including all sub directories) find/-name “*.txt”

  15. Linux Commands • The grep command: match a regular expression against text in a file • Display the lines that contain ligyu in file file1.txt grep “ligyu” file1.txt

  16. Linux Commands • mv: rename or move files • Requires two parameters: name of original file and new name or location of file • Examples: • Move file “a.cpp” from home directory to current working directory: mv ~/a.pp ./ • Rename file “a.cpp” in home directory to “b.cpp” mv ~/a.pp ~/b.cpp

  17. Linux Commands • cp: copy files • Requires two parameters: path and name of the original file and path and name or the new file • Examples: • Copy file “a.cpp” from home directory to current working directory (without changing name): cp ~/a.pp ./ • copy file “a.cpp” in home directory to “b.cpp” cp ~/a.pp ~/b.cpp

  18. Text Editor: Pico • Provides a series of commands at the bottom of the screen • Backspace, Delete, and other keys work as expected • Easy to Use • Start Pico • Pico file_name • Exit Pico • [ctrl]+x

  19. Linux Processes • A process is any running program. Under Linux a process has an identity (PID), a parent process (PPID), an owner (UID). • To view the active processes: psUseful options: -A (all), -l (long list) • Stop the execution of a program launched from a terminal: Ctrl-c • Stop the execution of any process kill pid • The signal 9 is the most powerful. • Kill a process with id 1258 Kill 1258 kill 9 1258

  20. Launching Jobs on Linux • A job is any executable run from the terminal. • The jobs are launched as foreground tasks by default - they will block the terminal until they are done. • To launch a job in the background, use the symbol & at the end of the command line. • A job can be intentionally brought to the foreground with the command fg.

  21. Pipe • Pipe (|) enables you to pass the output of one command through the input of another command • ls -l | more • The way this works is that when the shell sees the pipe symbol, it creates a temporary file to store the result of the first command • Then this file becomes the input to second command

  22. Input and Output Redirection • Redirecting the input: command < filenameAny input will read from that file (must be file). • Redirecting the output. The simple > rewrites the output file, while the double one >> appends to the file (must be file).command > filenamecommand >> filename • Combine input and ouput redirections • Example: • wc < my_text_file.txt > output_file.txt

  23. Compressing Files • The most common utilities for compressing and decompressing files on Linux are tar, gzip,and gunzip. • tar allows us to compress several files (directories) into one archive. • Options: cf for compressing, xf for decompressing. • Example: tar –cf C151.tar C151 • gzip compresses one file at a time. • Options: none to compress, -d to decompress. • Example: gzip C151.tar • To archive more than one file, most people use a combination of tar and gzip in that order. Those archives have the extension .tar.gzor simply .tgz.

  24. Decompressing Files • Suppose we have a compressed file called C151.tar.gz, how could we decompress it? • gzip –d C151.tar.gz (or gunzip C151.tar.gz) • We get C151.tar • tar –xf C151.tar • We get uncompressed files (folders)

  25. File Ownership and Permissions • Every file belongs to a particular user, generally the creator of that file. This is the owner of the file. Users may be organized in groups and a group can have special permissions to a file. • A file can be accessible for reading r, writing w, or executing x. To view the content of a directory, the directory should be executable. • Usually the owner has read and write permission to a file, also execute permission if applicable. The root (super user)has read and write permissions for any file. • The command ls -l displays the permissions of a file for the owner, the group, and everyone else (all). • Change permissions: chmod

  26. File Ownership and Permissions • Linux file and folder attributes seen with ls -l • Column of 10 characters on left • First character: file (-), directory (d), or link (l) • 2nd, 3rd, and 4th characters show permissions of owner • 5th, 6th, and 7th characters show permissions of group • 8th , 9th, and 10th characters show permissions of all others

  27. Managing Files and Directories with Shell Commands • File and Folder Permissions(continued)

  28. File Ownership and Permissions • Change permissions with chmod • Requires two parameters • Access mode number • File or directory name to change • Example chmod 644 reports

  29. Reading Assignment • Textbook: Chapter 3, Chapter 4, and Chapter 5

More Related