220 likes | 359 Vues
This lab guide provides an overview of essential Linux operations, including how to log in and out, manage directories and files, and set permissions. Learn user account basics, such as the importance of case sensitivity and the root user. Discover critical commands like `ls`, `pwd`, `mkdir`, and `chmod` to navigate the file system and manage file access rights. Explore advanced utilities for file management and text editing, with practical examples to enhance your Linux command line skills.
E N D
Working with Linux Lab 1
Login and logout • Account • username & password • Note: • Linux is case-sensitive • Administrator: username = root • Logout: exit, Ctrl+D
(D) (C) WINDOWS Program Files Data Music …. OS Fonts System32 …. …. Linux File System (/) home boot etc root khoa student1 …. …. Linux File System Windows File System
Directory/file commands • List contents of directory : ls [-a] [-l] [directory_name] • Print working directory: pwd • Change working directory : cd directory_name E.g. cd /home • Create new directory : mkdir directory_name • Remove a directory: rm -r directory_name • Some special symbols : ~ : home directory .. : parent directory
Directory/file commands • Display file content : cat filename or more filename head filename or tail filename • Copy file(s) or directory: cp [-r] source_file destination_file • Remove file or directory rm –r file_name • Move (rename) file(s)/directory mv old_path new_path
File system and permissions • Each user may owns one or more directories/files • Each user has different access rights in different directories/files • users can share their data together • users also can protect their private data
File system and permissions • Access right on directory/file • read (r) • write (w) • execute (x) • Each directory/file has 9 access-right bits, divide into 3 groups as follow : • owner • group (e.g. people the same project team) • others (people in public domain)
Changing access rights (1) • Symbolic chmod whoopmode [-R] file(s) • Who: u : owner g : group o : others a : all • Mode: r : read w : write x : execute • Op + : grant more rights - : revoke rights = : reset rights
Changing access rights (2) • Example $ touch temp $ ls –l temp -rw-r--r-- 1 user1 staff 0 Jun 11 11:44 temp $ chmod o-r temp $ ls -l temp -rw-r----- 1 user1 staff 0 Jun 11 11:44 temp $ chmod u+x, o+r temp $ ls -l temp -rwxr--r-- 1 user1 staff 0 Jun 11 11:44 temp
Changing access rights (3) • Numeric: chmod xyz [-R] file(s) read = 4 write = 2 execute = 1
Changing access rights (4) • Example: some common access rights of directory/file(s)
Changing access rights (5) • Example $ touch abc $ ls –l abc -rw-r--r-- 1 user1 staff 0 Jun 11 11:44 abc $ chmod 555 abc $ ls -l abc -r-xr-xr-x 1 user1 staff 0 Jun 11 11:44 abc $ chmod 775 abc $ ls -l abc -rwxrwxr-x 1 user1 staff 0 Jun 11 11:44 abc
Advanced utilities (1) • Who is who? who [option] • Print current host name hostname • Where do they come from? which [filename] • How much disk usage? df [option] • Clear screen clear OR Ctrl + L
Advanced utilities (2) • Find a specified file : find path –name filename • Find lines in file matching a pattern grep patternfile_name • Mount and unmount file system mount -t filesystemdevice_filemount_point umount mount_point
vi editor • Interactive simple editor • Can not use mouse • Text editing on a buffer • Appears on most Unix or Unix-like system