Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22
Lab# 1
Linux Environment, Introduction to CLI and
File & Directory Management CS311L
Lab Engr. Eisha ter raazia Mir
Learning Outcomes Log in and log out of the Linux operating system. Understand the Linux file system and directory hierarchy. Navigate and manipulate files and directories. Know the root directory, home directory, and paths. Operating System • Operating System is a type of System Software and a collection (set) of programs that performs two specific functions. • First, it provides a user interface so that users can interact with the machine. • Second, the operating system manages computer resources. It accepts user commands, then detrains, allowing the programs to run where they are loaded into memory first, and communication between various hardware devices is coordinated. • Windows, Linux, and DOS are popular operating systems. Linux System Components: Linux systems can be split into two parts. User • Shell Shell 1. A Shell is an interface between a user and a Linux operating Kernel system, i.e., the user interacts with the Linux operating system UUUSER Sh through the Shell. Shell
2. The Shell performs two tasks; it accepts and interprets a user's
commands. • Kernel 1. The Linux kernel, a core component of the operating system, handles critical functions like system calls, process management, scheduling, signals, paging, swapping, file systems, and storage I/O. Files Mechanism - store information Two modes of storing information • File • Directories • File • Store information • File attributes: • Read - "r"; allows - read, nothing can be changed • Write - "w"; allows - written to and changed. • Execute - "x"; allows - executed by users or the operating system File • The significant operations which can be performed on files are given below: • Create • Delete • Open • Close • Read • Write • Rename • Get Attributes • Set Attributes Directories • A directory, also known as a folder, is a virtual location within a file system where files are stored. • Users can navigate through the file system efficiently, moving in and out of directories to locate and manage files. Directories • The significant operations which can be performed on the directories are given below: • Create • Delete • Open • Close • Read • Write • Rename • Get Attributes • Set Attributes Linux File System Hierarchy /home: Users’ home directory /etc: All system administrator commands, configuration, and installation control files /bin: The core set of system commands and programs. Most systems cannot boot (initially start) without executing some of the commands in this directory /dev: The device files used to access system peripherals (for example, your terminal can be accessed from /dev/tty) /lib: The standard set of programming libraries required by Linux programs /root: The root user’s home directory. /usr/bin: Common commands and programs. /usr/doc: Documentation /usr/games : Games /usr/include : Header files /usr/man : Manual pages (help) File and Directory Commands
• Move from home to root
• cd / • Move from root to home • cd • cd ~ • . ( single dot) denotes the current directory in the path. • .. (two dots) denotes the parent directory, i.e., one level above. • sudo su (Stands for "Switch User" and is used to switch to another user, in this case, the root user.) • dollar ($) – non privileged user • hash (#) – privileged user Shell Commands (Case Sensitive) pwd - present working directory mkdir name - make a directory rmdir name - remove directory cd - change directory rm - remove a file clear - clear all exit - come out of the shell ls - list the files • -a Display all the files and subdirectories, including hidden files. • -l Display detailed information about each file and directory. • -r Display files in the reverse order. Pathname
Absolute Path Relative Path
•The Absolute path always starts from the root •The pathname identifies a file or a directory that directory (/) depends on the user's state, i.e., the user's current •Absolute pathname identifies a file or a directory directory irrespective of the user's current state. • Relative pathname specifies files concerning the •The user's "current directory" is part of the user's user's current directory state. The absolute pathname always starts from the • A relative path starts from the current directory. root directory. •For example, if you are in the /home directory and •For example, to locate the my_scripts.sh file in the you want to access my_scripts.sh you can use. script directory, the absolute path of the file is:
•/home/abhishek/scripts/my_scripts.sh •abhishek/scripts/my_scripts.sh Commands and Directories
How would you go to the directory you created?
• cd dir_name How would you go up? • cd .. (space between cd and ..) Command and Directories • Create another directory, chemistry under books • mkdir book • cd book • mkdir chemistry • cd chemistry Command and Directories Now you are quite away from your home directory
How would you go to your home directory?
pwd cd .. cd .. pwd Commands and Directories How do we remove our created directories? • ls • rmdir book • ls rmdir will only work if the directory you are trying to remove does not contain any file So first, remove all files from the directory File Manipulation commands • Create a file with nano editor • nano file_name or touch file_name • Ctrl-o -> save file • Ctrl-x -> exit editor • rm -r directory_name • rm -r -i directory_name (ask for permissions) • cat file_name (to view the created file) • The cat command will print the file contents for the read-only mode • Text editor must be used to make changes in the file. File manipulation commands Rename an old directory with new one • mv oldfile newfile Delete a directory having a file • rm -r directory_name Inode number Uniquely existing number for the files in Linux ls -i directory_name ls -l directory_name The following information is printed in the given order: • 1: file permissions (coming lab) • 2: File links (coming next) • 3: Owner of a file • 4: group (coming lab) • 5: the size of a file • 6: last change • 7: Time of change • 8: File/directory name Tasks 1. Remove a subdirectory name capital from country directory from the home directory • Make a directory name capital. In capital directory create subdirectory name country. Now come back to the home directory and remove country subdirectory directly from home directory. 2. Move to a directory name plant directly from a subdirectory name lion • Make a directory name plant in home directory. Create another directory name animals in home directory as well. Now create a subdirectory name lion in animal directory. Move to the directory name plant from the lion subdirectory directly Tasks 3. Rename a file name data.txt with new name lab_data.txt in a folder name data_file • Create a directory name data_file. In data_file directory create a file name data.txt. After creation of data.txt rename it to lab_data.txt • Find the Inode number of file named lab_data.txt by keeping yourself in home directory