Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux Commands C151 Multi-User Operating Systems.

Similar presentations


Presentation on theme: "Linux Commands C151 Multi-User Operating Systems."— Presentation transcript:

1 Linux Commands C151 Multi-User Operating Systems

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

3 Path Absolute path / Absolute path: complete sequence of directories to a file starting from the root directory /: /home/yul/c151/cat.jpg Relative path 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 / /bin /dev /etc /home /lib /mnt /proc /root /sbin /tmp /usr / root directory /bin executable for single user mode /dev devices that can be mounted by the system /etc local configuration, administrative things /home home directories for most users /lib shared 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 root /home/username 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 ls /usr Argument: what the command applies to. ls /usr Option ls –l Option: how do we want the command to be executed ls –l ls -l /usr/include 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 Spacebar moves 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 backward in 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 11 - 15 Linux Commands mv: rename or move files Requires two parameters: n ame 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

16 11 - 16 Linux Commands cp: copy files Requires two parameters: path and n ame 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

17 11 - 17 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

18 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: ps Useful 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

19 Launching Jobs on Linux job 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. fg A job can be intentionally brought to the foreground with the command fg.

20 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

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

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

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

24 File Ownership and Permissions owner groups 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. rwx 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). chmod Change permissions: chmod

25 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) 2 nd, 3 rd, and 4 th characters show permissions of owner 5 th, 6 th, and 7 th characters show permissions of group 8 th, 9 th, and 10 th characters show permissions of all others

26 Managing Files and Directories with Shell Commands File and Folder Permissions (continued) Permissions R = read W = write X = execute - =disabled Permission mode values read=4 write=2 execute=1

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

28 Reading Assignment Textbook: Chapter 3, Chapter 4, and Chapter 5


Download ppt "Linux Commands C151 Multi-User Operating Systems."

Similar presentations


Ads by Google