0% found this document useful (0 votes)
7 views36 pages

? JavaScript Interviews in 2025 Have Changed

The document outlines a course on Linux Administration and Security, detailing its objectives, instructional methodology, and learning outcomes. It covers essential Linux commands, system administration, network configuration, and security best practices, along with policies on academic honesty and participation. Additionally, it provides a brief history of Unix and Linux, their advantages, and an overview of various Linux distributions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
7 views36 pages

? JavaScript Interviews in 2025 Have Changed

The document outlines a course on Linux Administration and Security, detailing its objectives, instructional methodology, and learning outcomes. It covers essential Linux commands, system administration, network configuration, and security best practices, along with policies on academic honesty and participation. Additionally, it provides a brief history of Unix and Linux, their advantages, and an overview of various Linux distributions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual [Fan T foo Display the section T manual page of Too ‘man 3 foo Display the section S manual page of foo. [apropos fo Tist manual pages ontaning the srng fo. an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual [mand Regeneraethe man index caches. ‘When inside a man page er Gow the ext ine Space bar Govo he next page fa quite mana ite Search forthe sing oo x jump next occurence of Sing P jum to previous occur of saa COURSE OUTLINE, NOTES AND TUTORL )UESTIONS COURSE INFORMATION (Course Title: Linux administration and security Course Number: NWS 235 Credit Hours: Instructor: Mr. Kfeban Belvis Contact: +237 670 472 592 COURSE DESCRIPTION: ‘The Linux Administration and Security course provides a comprehensive exploration of Linux operating systems, focusing on system administration and security practices. This course is designed for learners ranging from beginners to intermediate users, aiming to equip them with the skills necessary to manage Linux environments effectively and securely. INSTRUCTIONAL METHODOLOGY The course will have both a lecture and lab component, Normally, there will be a lecture and lab component each day with the lab occurring at the end of the period. ‘There will be team and individual projects, paper writing, Internet research, and oral presentations. LEARNING OUTCOMES & OBJECTIVES Understand Linux Fundamentals: Gain foundational knowledge of Linux operating systems, including file systems, commands, and user management. System Administration: Learn how to install, configure, and manage Linux servers, including package management and system updates. Network Configuration: Understand basic networking concepts and how to configure network settings on Linux systems. Security Best Practices: Explore essential security measures, including user permissions, firewall configurations, and security protocols. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo Display the section T manual page of Too ‘man 3 foo Display the section S manual page of foo. apropos foo Tist manual pages ontaning the srng fo. an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand Regeneraethe man index caches. ‘When inside a man page emery Goto the next line space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing Monitoring and Troubleshooting: Develop skills to monitor system performance, Giagnose issues, and apply troubleshooting techniques. COURSE POLICIES Plagiarism and cheating Plagiarism and cheating at the all level are viewed as being particularly serious and the sanctions imposed are accordingly severe. Students are expected to familiarize themselves with and follow internal regulations. The Policy is strictly enforced and is binding on all students. Plagiarism and cheating, presenting another’s ideas, arguments, words ot images as your own, using unauthorized material, misrepresentation, fabricating or misrepresenting research data, unauthorized co-operation or collaboration or completing work for another student — weaken the quality of the graduate degree. Academic dishonesty in any form will not be tolerated. Students who infringe the Policy may be subject to one of several penalties including: expulsion; suspension from all studies at Carleton; suspension from full-time studies; a refusal of permission to continue or to register in a specific degree program; academic probation; or a grade of Failure in the course. Academic Honesty: Academic honesty is fundamental to the activities and principles of a university. All members of the academic community must work to provide an environment in which each student could be evaluated fairly based on his/her own performance. University regulations regarding academic dishonesty will be strictly enforced. Ata minimum, any student found to be in violation of academic honesty policies will receive a zero on the exam ot assignment involved. ALL instance of academic dishonesty will be reported to both the Department Head as well as the Dean of the school. These offices may also wish to evaluate the case and decide punishment independent of this professor's actions. Class Participation and Paper Presentation (20% of grade): Class attendance is mandatory, and we strongly encourage you to participate actively throughout the course ask questions, challenge what class members have said, make connections to material from other courses, and relate course material to your own developing research interests. We will all Jeam more, and have more fim, if you do. Toward the end of the term/semester, you will have ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jmp to next occurrence of in P jump 10 previous oecurenee of sti ‘an opportunity to present your term paper to the class. The paper presentation will give you a chance to share your research interests, to provide/receive comments, and to refine the ideas and analysis prior to submitting a final draft of your term paper. The paper presentation should be constructed using PowerPoint and not be longer than 15 minutes. UNIT -T Lesson 1 Introduction to Linux 1.1. Introduction Operating system: ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When inside a man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing An operating system is a program that manages computer hardware and software for the user. Operating systems were originally designed to perform repetitive hardware tasks, which centered around managing files, running programs, and receiving commands from the user. ‘You interact with an operating system through a user interface, which allows the operating system to receive and interpret instructions sent by the user. You need only send an instruction to the operating system to perform a task, such as reading a file or printing a document. An operating system's user interface can be as simple as entering commands on a line or as complex as selecting menus and icons on a desktop. An OS is a “privileged” program run when the machine is switched on and that: Loads other programs in memory (RAM), Allocates the resources (memory, CPU time, disk space) they request, Handles their communications (input/output) with peripheral devices (screen, keyboard, mouse, network, printer. ..) Halts their execution Reclaims the allocated resources. lin ‘An operating system also manages software applications. To perform different tasks, such as editing documents or performing calculations, you need specific software applications. An editor is an example of a software application that enables you to edit a document, making ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tist manus pages containing the sing oo an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand Regeneraethe man index caches. ‘When inside a man page emery Goto the next line space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing changes and adding new text, The editor itself is a program consisting of instructions to be executed by the computer. For the program to be used, it must first be loaded into computer ‘memory, and then its instructions are executed, The operating system controls the loading and execution of all programs, including any software applications. When you want to use an editor, simply instruct the operating system to load the editor application and execute it. File ‘management, program management, and user interaction are traditional features common to all operating systems. Linux, like all versions of Unix, adds two more features. Linux is a multiuser and multitasking system. As itis a multitasking system, you can ask the system to perform several tasks at the same time. While one task is being done, you can work on another, For example, you can edit a file while another file is being printed. You do not have to wait for the other file to finish printing before you edit. As itis a multiuser system, several users can log in to the system at the same time, each interacting with the system through his or her own terminal. Examples: Windows, Unix, Linux, Apple iOS, Mac OS, Xenomai, Android, Linus, i 4 « wml . ubuntu unix g z &. 2th) is MacOS BlackBerry = OS2 Wan? History of Unix and Linux Unix : In 1969, Ken Thompson, Dennis Ritchie, and the researchers at AT&T Bell Laboratories developed the Unix operating system, incorporating many of the features of the ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tist manus pages containing the sing oo an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goto the next line space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing MULTICS research project. They tailored the system for the needs of a research environment, designing it to run on minicomputers. From its inception, Unix was an affordable and efficient multiuser and multitasking operating system Linux : Originally designed specifically for Intel-based PCs, Linux started out at the University of Helsinki as a personal project of a computer science student named Linus Torvalds. At that time, students were making use of a program called Minix, which highlighted different Unix features. Minix was created by Professor Andrew Tanenbaum and widely distributed over the Internet to students around the world. Linus’s intention was to create an effective PC version of Unix for Minix users. It was named Linux, and in 1991, Linus released version 0.1. Linux was widely distributed over the Internet, and in the following years, other programmers refined and added to it, incorporating most of the applications and features now found in standard Unix systems, Linux today Linux is everywhere: = Most academic computing clusters/supercomputers — Many mass storage systems (“Big Data”) —Data-centers of major companies like the so-called “GAFAM” — Everyday equipment (like the box from your Intemet provider) — Internet providers infrastructure (webservers,...) — Cloud providers — Android is based on a branch of the Linux kernel, modified to support hardware found in smart-phones, tablets, Linux system advantages: A Unix-like Operating System Has the X Windows GUL Coexists with other Operating Systems ‘Runs on multiple platforms ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual ofthe mana ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tis manual pages containing the string 0 an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page aera Gorw the next Tine spacebar Govw ithe next pare a uittbe manual ite Search forthe sing foo a jump to next occurence Of Sing P jump to previous oceurenae of sn Easy to install applications, Secure Stability (Community Portability Modularity Based on open standards Unix philosophy of tools : only do one thing, but do it well, Easy to interact with development teams Management of processes © Documentation © Preemptive multitasking & multi-user system, mutiprocessor — Durability & stability with a track record back to 1994 © Open-source and free (as in beer) — Its code can be freely copied, modified and redistributed © Offering a vast software catalogue : = Office suites : LibreOffice — Internet tools : browsers (Firefox, Chrome), e-mail programs (Thunderbird, Evolution) — Multimedia : audio/video playback tools (VLC, Totem ) — Graphics : image manipulation (Gimp), 3D modeling (Blender) — Software development : languages (Python, Java, C/C+...), environments (Eelips IDLE, PyDev, DDD) ‘© Scientific disciplines included — Bioinformatics : blast, emboss, phylip, mafft,clustal,trimal Distributions A Linux distribution is a collection of (usually open source) software on top of a Linux kernel. A distribution (or short, distro) can bundle server software, system management tools, documentation and many desktop applications in a central secure software repository. A ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tist manus pages containing the sing oo an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing distro aims to provide a common look and feel, secure and easy software management and often a specific operational purpose ‘Ubuntu, Fedora, Debian, Arch Linux, CentOS, Kali Linux, Mint, OpenSUSE, Red Hat, Slackware, AlmaLinux,...cte @ Ge # © debian archlinux openSUSE centos ubuntu fedora redhat The main differences between distributions are: * Ona technical level - The packaging format used to package(!) software. - The tools to administer these packages. ~ A portfolio of prepackaged software - Administration tools facilitating the installation and update of these packages. * Business model wise : - Technical Support : community-based vs. commercial. ~ The licenses for the software they provide. Which to choose ? Below are some very personal opinions on some of the most popular Linux Distributions. Keep in mind that any of the below Linux distributions can be a stable server and a nice graphical desktop client. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of them ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo ist manual pages containing the sng foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe string oo a jump to next occurrence of sing P jump to previous occurence of sing distribution name | reason(s) for using Red Hat Enterprise (RHEL) | You are a manager and you want a good support contract. CentOS "You want Red Hat without the support contract from Red Hat Fedora "You want Red Hat on your laptop/desktop. Linux Mint "You want a personal graphical desktop to play movies, music and games, Debian ‘My personal favorite for servers, laptops, and any other device. Ubuntu ‘Very popular, based on Debian, not my favorite. Kali ‘You want a pointy-clicky hacking interface. ‘others "Advanced users may prefer Arch, Gentoo, OpenSUSE, Scientific, af Linux Overview Like Unix, Linux can be generally divided into three major components: the kernel, the environment, and the file structure. The kemel is the core program that runs programs and manages hardware devices, such as disks and printers. The environment provides an interface for the user. It receives commands from the user and sends those commands to the keel for execution. The file structure organizes the way files are stored on a storage device, such as a disk. Files are organized into directories. Each directory may contain any number of subdirectories, each holding files. Together, the kernel, the environment, and the file structure form the basic operating system structure. With these three, you can run programs, manage files, and interact with the system, An environment provides an interface between the kernel and the user. It can be described as an interpreter. Such an interface interprets commands entered by the user and sends them to the kemel. Linux provides several kinds of environments: desktops, window managers, and command line shells. Each user on a Linux system has his or her own user interface. Users can tailor their environments to their own special needs, whether they be shells, window managers, or desktops. In this sense, for the user, the operating system functions more as an operating environment, which the user can control ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page @ uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing device interfaces Fig. ARCHITECTURE OF LINUX OS. Kernel: Kemel is the core part of Linux. It is responsible for all major activities of this operating system. It consists of various modules and it interacts directly with the underlying hardware. . It allocates CPU time and memory to each program and determines when each program will run, The ketnel also provides an interface to programs whereby they may access files, the network, and devices. Shell: It is an interface among the kernel and user. The shell is a command line interpreter (CLD. It interprets the commands the user types in and executes them. The ‘commands are themselves programs, Hardware layer: The hardware layer consists of several peripheral devices like CPU, HDD, and RAM. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo Display the section | manual page of oo ‘man 3 foo Display the section S manual page of foo. spp Tod Tist manus pages containing the sting foo an Fo ist manual pages containing the sng foo. ‘whais foo ‘Shows the shor desertion of foo. wheres 00 ‘Shows the location of foo and ts mand ‘mand Regeneraethe man index caches. ‘When inside a man page eae Go to the next Tine space bar Go twthe next page 4 uit the manual 700 Search forthe sting Too a jump 0 next occurence of ing P jump 10 previous ooeurenes of suf File system Linux Files: ‘© Normal files: data files, executables files and text files © Directory files: are simply containers for files and other directories, '® Special files: represent interfaces with the devices managed by the system, In the Linux operating system files are stored in a tree-like structure starting with the root directory as shown in the below diagram. The Linux file system hierarchy base begins at the root and everything starts with the root directory. Linux file system structure J - Root directory that forms the base of the file system. Al files and directories are logically contained inside the root directory regardless of their physical locations. Jbin - Contains the executable programs that are part of the Linux operating system. Many Linux commands, stch as cat, ep, Is, more, and tar, are locate in Jin /boot - Contains the Linux kernel and other files needed by LILO and GRUB boot managers. /dev - Contains all device files. Linux treats each device as a special file. Jete - Contains most system configuration files. /home ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tist manus pages containing the sing oo an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goto the next line space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing / Home (-~) directory is the parent to the home directories for users. ‘ib - Contains library files, including loadable driver modules needed to boot the system, Jmedia - Directory for mounting files systems on removable media like DVD-ROM drives, flash drives, . Jmnt - A directory for temporarily mounted file systems. Jopt - Optional software packages copy/install files here. Iproc - A special directory in a virtual memory file system. It contains the information about various aspects of a Linux system. Jroot - Home directory of the root user. Jeun - Gives applications a standard place to store transient files they require like sockets and process IDs. Isbin - Contains administrative binary files. (mount, shutdown, umount, ....) Isrv - Contains data for services (HTTP, FTP, etc.) offered by the system. Jsys - A special directory that contains information about the devices, as viewed by the Linux kernel. ‘itmp - Temporary directory which can be used as a scratch directory (storage for temporary files). The contents of this directory are cleared each time the system boots, Jusr - Contains subdirectories for many programs such as the X or GUI Window System. © /ust/bin - Contains executable the core Linux operating system. ‘* /usr/include - Contains header files for C programming languages ‘© fusr/lib - Contains libraries for C programming languages. Jusrisbin - Contains administrative commands. Ivar - Contains various system files such as log, mail directories, print spool, et. which tend to change in numbers and size over time. les for many Linux commands, It is not part of Directories can be accessed by their name. Linux uses also the symbols to represent directories. Symbols, (This directory. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing (~) Home directory. (.) The parent directory. (/) The root directory, Absolute and relative paths: Absolute path-name: An absolute path is defined as the specifying the location of a file or directory from the root directory (/). To write an absolute path-name: © Start at the root directory (/) and work down. © Write a slash (/) after every directory name (last one is optional) Example: Juser/lib Jete/network/interfaces Relative path: relative path is defined as the path related to the present working directly. It starts at your current directory and never starts with a /, User session login: usernamre Password: xxXXXXXXXXXXXxxAx If the login or password is not correct the system give you the response: Login incorrect Login:username Pass word:xxxxxXxxX000000%x 10> username @sysname:~$ If the login is correct the prompt of the user appears in the terminal in 2 common format of username@sysname:~S. In this example, the prompt is displaying the username, the sysname, and if that user is using the system as a normal user ($) or a super user (#). The user can now type a program. Once programs terminate, control is retumed to the shell and the user receives another prompt ($), indicating that another command may be entered. The super user on a Linux system is called root. Anything that can be done on system can be done by root. exit, logout, or Ctrl-d Exits the shell or your current session. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page @ uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing Sshutdown —h time “message” The shutdown command is used for shutting down the system (poweroff) if you are the super Example: Sshutdown —h now Login shell startup files: ‘When you run a login shell it reads and executes a number of ‘commands from the files on start-up, in the following order: Jete/profile ~I-bash_profile /bash_login ~L-profile When an interactive shell that is not a login shell is started. The shell in this case reads and executes commands from: Jete/[Link] tebashre When an interactive login shell exits, or a non-interactive login shell executes the exit built commands from the file ~/.bash_logout, if it exists. command, the shell reads and executes ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual ofthe mana ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page @ uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing UNIT - IL Lesson 2. Start using Linux Shell Sometimes called “terminal” or “CLI” (Command Line Interface) # A shell is a command-line interpreter: — Executes commands entered by user (interactive mode) — Executes seripts (command mode) «© Different variants: esh, tsh, sh, Bash,... « Exercise To determine which shell you are currently using, type one of the following command: ps $$ ¢ Why use command-ines? Many things can't be done or are very difficult to do ina graphical environment. Examples: — Executing an operation on files matching a given criteria, — Sending the output of a process in input of another process — Working with scripts : task automation, re-usability, modularity... Convenient features of Bash Bash (or Bourne She brings a lot of features: = Process control ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing — Automatic completion. — Keeps an history of what user has typed — Copyipaste — Keyboard shorteuts Structure of the Command Line [stage01@slurmO ~|S head -n 20 [Link] #print the first 20 lines [stage01@slurmo ~] $ The prompt : displays the current user's login (stage01), the host (or machine) name (slurm), the current directory (working directory) (~) head The name of the program to run (first word following the prompt) -n 20 A command option (-n) possibly with an associated value (20) [Link] A command argument # print (..) Comments (ignored by the command) ‘* The space character is used to separate the various fields of the command line. ‘© The character case (upper/lower) is important (head is not the same as HEAD ) ‘* Each command hs its own set of arguments and options, * The Enter key (© ) is used to run the program, The root user # You always log in on a system using a given identity (or “login” or “account”. © On all Unix-like systems, there is a special accou # Root account has ALL the privileges. © Working with root account is dangerous, because: —you can execute non-reversible commands that might damage your files/data; — you can break your system, making it very difficult to repair if you are not an expert; — you can create security holes that can be exploited by “bad guys”. Toot. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual of the manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. apropos 100 Tist manus pages containing the sing oo an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page aera Gorw the next Tine spacebar Govw ithe next pare a uittbe manual ite Search forthe sing foo a jump to next occurence Of Sing P jump to previous oceurenae of sn ‘The prompt ‘© The prompt is a short message text at the beginning of the command-line. # On Linux, the prompt is also giving you some basic information, like your user name and the machine to which you are logged in. © The prompt is ending by a'S' indicating that you are an ordinary user (i.e. not the root user, whose prompt is ending with © Can be customized by the user Start using Linux(Practice) [Link] am I? ~The who command displays a list of logged on users. - The who am i command will display your line in the list of logged on users. [Link] am I? ~The hostname command will display the name of the computer (on which you are logged on), By default this name is also displayed in your command prompt. 3. Change your password - You can use the passwd command to change your password (for that user, on that computer) [Link] are we? - The date command will display the current date and time - There are many options possible to the date command, But this is a humble introduction so we will keep it simple. Try executing date ~date="Next Sunday” - You can use the eal command to display a calendar of the current month, 5. What was I doing? - Instead of typing a command multiple times, you can use the arrow up key to see and. execute previously entered commands. Try now to use arrow up and execute some of your previous commands [Link] me out of here. ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jmp to next occurrence of in P jump to previous occurence of sing - You can exit from this Debian Linux computer by typing exit or Ctrled. Both, ‘commands have the same effect. [Link] the computer = off If you created a virtual machine for this book, then you can tum it off by typing, poweroff as root. That means you need to log on as the root user, since only root has the power to tum a computer off, ‘command ‘explanation who Tis all users Togged on the system ‘who ami Tist your logon information ‘Hostame display the name of the computer passwd ‘change your password date display the current ime and date cal splay this montis calendar ea OT 1970 display’ a calendar of Fanuary 1970 arrow up key {0 fo previous command) exit og out of your curent session Cutt send an EOF character (log out of Your Curent session) ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page @ uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing UNIT - ID Lesson 3 BASIC COMMANDS(PRACTICALS) 1, Manual pages ‘man Most Linux commands come with an excellent manual in the form of a man page. This ‘man page can usually be accessed by typing man followed by the command. The example below enters the man page of the tail command. Command: man tail When inside the man page, you have several options that are the same as when using the more command, Key action enter continue one line space bar next page a quit Searching the man page You can use the slash key "/" to search for strings in the man page. The /-will appearatthe bottom of the sereen. The search is case insensitive by default. You can jump to the next ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jmp to next occurrence of in P jump 10 previous oecurenee of sti ocourrence using the n key and to the previous occurrence using the p key. And remember type q to quit the man page = man man = man Seommand - man Sconfigfile = man Sdaemon, = man -k (apropos) - Whatis - Whereis = mandb 2. introduction to users ~ Whoami = Who - who ami - Ww - id ~ Suto another user = suto root - suas root - u- - Visudo ~ una program as another user ~ su Susername ~ sudo su- 3. working with directories - Pwd - ed ~ ed~ ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page er Goro the nex Tine spacebar Govw ithe next pare a quite mana oo Search forthe sing foo ™ jmp to nex occurence OF Sng P ump to previous occurence of sin - ed. - ed- ~ absolute and relative paths = path completion - is - isd - isa = Is-l-hyIs-th, Is -hl, Is -h - mkdir ~ mkdir -p - rmdir - mméir-p ~ Searching for directories ‘command ‘explanation is list the contents ofthe current directory Is foo Tist the contents of the foo directory [is bar Tis the contents ofthe Mbar directory mkdir Too make (create) anew directory named Too kai Foobar ‘ereate the bar directory in the foo directory mkdir p foo/bar ‘create both foo and foobar if they don't exist od ‘rint the name ofthe current (working) directory ef ‘change into your home directory ed foo hang into the foo directory ed far change ito the Phar directory ed change tothe parent dieetory of Te current dreciory ‘mdi Foo romove (delete) the empty directory foo ind -name Too search fr the dtectory (or file named foo Tind type d name Too | search forthe directory named foo 7 Tis the name of the root directory i Tio Use an absolute path to enter the foo directory ed fo0 Uwe a relative path (0 enter the foo directory ‘ab Key ‘complete the path you are typing 4. working with files - all files are case sensitive ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo ‘Display the section 5 manual page of fo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing = everything is a file - file = touch = touch-t - om - mi - mat - pt - copy multiple files to directory - pei - my = mv - rename - Hidden files ‘command ‘explanation is List the ies in the current directory. isl Long list of files in the cutent directory. Isa Tint also the iden files in the cure directory. Touch Foo ‘Create an empty file naned foo. Touch foo ‘Create a hidden ile named foo. Touch -1 19702271730 bar | Create a file named bar with a spesife ime vamp. ‘moo ‘Remove the foo file ‘mi foo ‘Ask for permission to remove the foo fle ‘maf Too ‘Remove foo recursively and forced "wget hip Tina aing elTOo ‘Download foo from hip linux waning Ba Tile bar entity the type of ie for bar ep foo bar ‘Copy the foo file to bar. {£p fool foo? F003 ball ‘Copy multipe fle to the Bar directory. p= fo0 ar ‘Copy foo to bar but ask permission before overwriting ale = foo bat ‘Copy and preserve the time stamp. Fv foo Bar [Rename the foo file o ur. ry Tool foo? Too Ba ‘Move multiple files tothe bar directory rename WfooPba? = [tind -mame foo ‘ind “type f -name foo ‘Rename allies in the current directory replacing the sing Yoo withthe sing Da. ‘Search forthe ile (or directory) named foo. ‘Search forthe ile (not directory) names foo. ind type d-name Too" ‘Search forthe directory named foo. ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo ‘Display the section 5 manual page of fo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing 5. working with file contents - head = tail = cat ‘* Concatenate,custom end maker, create file, copy files, tac, more and less, strings ‘command ‘explanation Thead foo ‘Show the top ten lines oF the Text file Too, Tread 5 ‘Show the top 5 Tine. ‘ail how the Tas ten lines. ‘wil Show the Tast 42 lines. cat Show the complete file. ‘we Reverse of eat, shows last Tine fist ‘we foo Count lines, words and characters in (ext file foo wwe-l ‘Count ines. we Count words wee Count characters. rep foo Bar ‘Show the lines containing oo inthe Gext He ar. more foo ‘Show the (text) fle foo page By page. echo foo Display the string foo. ‘at > foo ‘Create (or empty) file named foo, end input with Ctra Thead -33 foo > Bar ‘Create (or empty) the bar fil. then put the ist 33 lines of foo in tail -1201 Too > bar Create (or empty the bar file, then put the last 1201 lines of foo int echo foo > bar Pt the string fo inthe file named bar after clearing Ba. echo foo >> Bar “Append the string foo to the file named bar. 6, user management = etc/passwd command ‘explanation ian foo Display the manna page oF Toa "an ‘iaplay the manual ofthe manual ‘man Tf09 ‘Display the section | manual page of fo. ‘man Too Display the section 5 mann page of fo aprogRs TO ist manual pages containing the sting foo. man foo ‘ist manual pages containing the sring foo ‘was foo ‘Shows the shor description of feo. ‘wees foo Shows th locaton of fo and is maul rand ‘Regenerate the man index caches. ‘When inside a man page er Gorw the next Tine space Bar Govw ithe next pare a uittbe manual ite Search forthe sing foo ™ jump to next occurence Of Sing P jump to previous oceurenae of sn field explanation annik the username: x x (long ago the encrypted password was here) 1004 the uid TOO4 the gid an optional comment /home/annik] the name of the home directory /bin/bash the default shell for this user useradd option explanation “Cc Set an optional comment for this user. “2 Set an expiry date for this account. =m Create a home directory for this user. -p Set an encrypted password. -s Set the default shell for this user. -u Set the uid for this user. userdel usermod ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jmp to next occurrence of in P jump to previous occurence of sing ‘command ‘explanation useradd foo ‘Create a new user named foo on this computer. useradd -m foo ‘Create a new user with a home directory (home/f00). useradd-s Pinbash Too ‘Greate a new user with the bash shell as default shell. "usermod -s bin/bash foo ‘Change the default shell forthe user foo to bash. userdel foo Delete the user foo, the home directory is untouched. userdel -r foo ehsh -sPbin/bash foo Delete the user foo, also delete the home ‘Change the default shell for user foo. TeteTpasswd “The Tist ofall users on this computer Thome The default location for home directories. Tetehskel The skeleton (template) directory for home directories 7. Password management - [etc/shadow - chage - fete/[Link] - encryption with passwd - encryption with openssl = encryption with erypt - disabling a password - editing local files - Generating good passwords © Pwgen Gpw . © Diceware © xkedpass command ‘planation ao Dis the anal age TF ‘an ma ‘isl the ana of th man aa foo Display tie seton Tana ape fo a fo Dipl the section Sanna age of prays foo st manpages conning the tg To tia Tare pager cont i ng ‘whatis foo “Shows the short description of foo. ‘hts Too Shows he Toston of bo an is mani ab Topas Grentiiitecios ‘When sie a man page aay Grishin spacebar Goioibe net pes a quit mama 0 Search forthe ing 00 = jmp to next occ af Sing P ump previous eeurense of sing ‘command ‘planation passwd ‘Change your password passwd foo ‘Change the password of the user named foo, chase “Tfoo List the fields in eta (excep the hash) Tor ase foo: penal pnt aE splay a hash ors password unter peal parma 6 hen ——| Dispny a tong hash forthe password bane pasewd foo Tock the account foo ‘iw it etclpaswd or tsa, Knowing you are he only one using pw Pee ‘Generates passwords: 2p Generates passwords iceware ‘Geeates passwords Consisting of words sap ‘Generates pasword consisting of word: Teta “Te Hle-wih al password Rashes. Fetflogn des This le conrans default sings Tor new wer accom 8. Group management = groupadd ~ fete/geoup - groupmod ~ groupde! ~ usermod ~ gpasswd - newsrp = vigr ~ backups ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo ‘Display the section 5 manval page of fo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing ‘command ‘explanation groups List your group memberships groupadd Too ‘Adds an empty group named foo to this computer groupmod “Tool fo modify properties of groups. groupe foo Delete the group named foo. usermod -G foo bar ‘Add the user bar to the group foo (and remove bar Irom all other groups). uusermod -a -G foo Bar ‘Add the user bar to the group foo. newaep ‘Change the primary group in your current environment. ‘gpasswd-A foo bar “Make user foo an administrator of group bar. Tetelgroup ‘Contains the Tist of all groups and their members on this computer. Tvarlbackups ‘Contains backups of Fetefpasswd, /etc/group and more. [Link]/passwd “The file that performs the backup (see the Scheduling chapter). 9. File permissions - File ownership ~ chgrp ~ chown ~ Regular files Tetter short | permission r read ‘Can read the file with cat, more, ... w write | Can write to the file with vi, >, ... i execute | Can execute (run) the file. = Special files command ‘explanation ian foo Display the nana uae OT oo "an ‘Display the manual fhe man ‘man Tf09 ‘Display the section | manual page of fo. ‘man Too Display the section 5 mann page of fo apropos Tint mana pages contain the sng foo man foo Tis manual pages containing Te ing foo. ‘was foo ‘Shows the shor description of feo. were 09 Shows th locaton of fo and is maul rand ‘Regenerate he man dex ace. ‘When inside a man page er Goro the nex Tine space bar Goro the next pas a “quite manual i Search forthe sing To ™ jmp to nex occurence OF Sng P ump to previous occurence of sin file type on normal file ad directory 1 symbolic link Pp named pipe b block device c character device . 3 socket - chmod character short | permission u user user owner g group | group owner ° other | others + add ‘add permission(s) to file or directory character short__| permission > remove | remove permission(s) from file or directory set ‘set permissions on file or directory r ead read permission write | write permission x execute | execute permission = old school chmod command ‘explanation ian foo Display the nana uae OT oo "an ‘Display the manual fhe man ‘man Tf09 ‘Display the section | manual page of fo. ‘man Too Display the section 5 mann page of fo aprogRs TO Tint manual pages containing the ring foo man foo Tis manual pages containing Te ing foo. ‘was foo ‘Shows the shor description of feo. ‘wees foo Shows th locaton of fo and is maul rand ‘Regenerate he man dex ace. ‘When inside a man page er Goro the nex Tine spacebar Govw ithe next pare a uittbe manual oo Search forthe sing foo ™ jump to next oceumence Of Si P ump to previous occurence of sin octal number rwx equivalent 0 ~ 1 =e 2, -w- 3) -WX 4 i 5 x 6 rw- 7 rwx ~ stat ~ umask ~ mkdir -m = root and permissions command ‘explanatfon Is-1feo Display user owner and group owner of a file named foo, charp bar foo ‘Change the group owner of a file named Too to bar. chowa bazhar foo ‘Change both owners ofthe ile named foo to ar. chmod “Tool to change the permissions (he mode) oFa fie chmod w=" foo Sets the user owner permission to read (for te file foo) mod gaw Too ‘Adds read and write permissions for the group owner chmod o- Foo Removes the execute permission for others chmod 777 foo els 777 octal permissions on the fle named fo. chmod Re Recursively sets permissions forall Riles i all subdirectories. Stat foo Display owners and permissions (and more) information about the fle foo. ‘umask Display the default permission mask (for your curent environment) umask 002 Set the default permission mask (for your current environment!) rmikdir-m TOOTS ‘Create the directory foo with octal 700 permissions. ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump 10 previous oecurenee of sti UNIT - IV Lesson 4 pipes and commands 1. W/O redirection One of the powers of the Unix command line is the use of input/output redirection and pipes. This chapter explains redirection of input, output and error streams, ‘The bash shell has three basic streams; it takes input from stdin (stream 0), it sends output to stdout (stream 1) and it sends error messages to stderr (stream 2) . The drawing below has a graphical interpretation of these three streams. [stain (o> - > stdout ‘stdout (1) > stderr (2) > 2 ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jmp to next occurrence of in P jump 10 previous oecurenee of sti Using the bigger than sign > we can redirect stream 1 to something else than the terminal window. In fact > is identical to 1> because we are redirecting stream 1. + >> stdout append = noclobber - redirection by the shell + > stderr - 25> stderr append filters ‘Commands that are ereated to be used with a pipe are often called filters. These filters are very small programs that do one specific thing very efficiently. They can be used as building blocks - | pipe symbol - cat ~ tac - tee ~ grep - cat = paste - - we ~ sort ~ unig = comm ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing command explanation cat ony sidin io sdout tae reverse of ea, ast Tine Fist ‘ee copy stdin o a ile and to stdout rep filter lines Tom stdin or a ile tha contain a Sting grep Titer Tnes That match a regular expression (se Tate rep case insensitive flier rep filter the lines not matching a ringrenex grep -AZ ‘ler the Ties and also output the wo next (ATiev nes grep BD filter the lines and also output the tw previous (Before) Tins grep-c> Titer the Ties and also output the wo next and previous (Conte) Ines cut Select columns from stdin or from a file out -deD ‘separate columns by x and dispay the second cofomn (HEI) cut -b5A2 isp the fh til {nc character of each line paste [Join Tines by column (the reverse of eu) G translate characters wab ‘tarslate each ato a (om stdin stdout) war AZ translate text 0 uppercase aed remove all occurrences of we ‘oun Fines, words or characte sont sort by alphabet (or By ASCII val) sont ‘numerical sor sont remove doubles (and Wples te) from a Tat ‘nig remove doubles rom a sorted list om compare sorted Tsts ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual ofthe mana ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page @ uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing UNIT - V Lesson V Introduction to scripting A script is a text file that can be executed line by line by (in this case) the bash shell. Below is an example of a Hello world script in bash, paul @debian10:~$ vi [Link] paul@debian10:~8 cat [Link] echo Hello world paul@debianI0:~$ A text file is not executable by default. We have to manually set the x flag for executable on the file, We can do this with the chmod +x command (which will be discussed in detail in the Permissions chapter), paul@debian!0:~$ chmod +x [Link] paul@debian10.~S ‘To execute the script we wrote, we HAVE To eHET USE an absOIMTe pale /home/paul/[Link] or use a relative path starting from the current directory as in firsts. Remember that the current directory is by default not in SPATH so typing just [Link] will result in a command not found error. paul@debian10:~$ fhome/paul/firstsh ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man Display the manual ofthe mana ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo Tist manual pages contsining the ring foo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate the man index caches. ‘When insidea man page emery Goro the next Tine space bar Gowwthe next page @ uit the manual 70 ‘Search forthe sing Too a jump to next occurrence of sing P jump to previous occurence of sing Hello world paul@debian10-~8 J/firstsh Hello world paul @debian10:~$ [Link] -bash: [Link] command not found paul@debian10:~$ Itis advised to start any script (bash or Perl or any other scripting language) with #! as the first two characters, followed by the interpreter. In our case the interpreter will always be ‘bin/bash. The #! is called a sha-bang or she-bang. The next screenshot shows how this looks, paul@debian10:~$ vi [Link] paul @debian10:~$ cat [Link] #Ubin/bash echo Hello world paul@debian10.~$ ‘When launching the script, the Linux kernel will start a new process and will read the sha- bang to know which exec it should perform for that new process. This new process will end when the script ends, Except for the sha-bang, any line that starts with # is ignored by the bash shell. You can use the # to write comment about the instruction(s). In the example below we added some ‘comments to our script, paul(@debian 10:~$ vi [Link] paul@debian10°~$ cat [Link] #Ybin/bash # This command displays Hello world echo Hello world Htrm--rf~ is not executed # The script will end here paul@debian10:~$ ‘command ‘explanation ‘man foo Display the manval page of Fo. ‘man man ‘Display the manual ofthe manual ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo Display the section S manual page of foo. ‘apropos Fo, Tis manual pages containing the string 0 an Fo st manual pages containing the ating fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump 10 previous oecurenee of sti ‘You can, of course, use variables in a script. In our example we create a variable named var_s and we give it a value, paul@debian10.~$ vi [Link] paul @debian10:~$ chmod +x [Link] paul@debian10:~$ cat [Link] #Ybin/bash 00 vars Echo Our var_s is $var_s paul@debian10:~8 /[Link] Our var_s is 200 paul @debian10:~$ ‘You ean ask the user of the script to give runtime input by using the read statement. ‘The following screenshot asks for a number and then displays that number. paul@debian10:~$ cat [Link] #Ybin/bash echo -n "Give a number between 1 and 9:" read number echo You gave $number paul@debian10:~$ /ask-sh Give a number between I and 9:4 You gave 4 paul@debianl0:~$ ‘command ‘explanation ‘man foo ‘Display the manual page of fo. ‘man man ‘Display he manda of the manu ‘man T Yoo ‘Display dhe section | manual page of foo, ‘man 3 foo ‘Display the section 5 manual page of fo. ‘apropos Fo, ist manual pages containing the tring foo. an Fo ist manual pages containing the tring fo. ‘whais foo ‘Shows the shor desertion of foo. ‘wheres foo ‘Shows the focation of fo and is manual ‘mand ‘Regenerate dhe man index caches, ‘When insidea man page emery Go tothe next Tine space bar Gowwthe next page 4 uit the manual 70 ‘Search forthe sing Too 2 jump to next occurrence of sing P jump to previous occurence of sing command ‘explanation ‘chmod +x foo. “Make foo executable Floo. Execute foo in the current directory, # ‘Denoies a sha-bang (if these are the first two characters of a scrip) #binfbash Denotes a sha-bang for the bash shell ‘Starts @ comment in a script (or on the command Tine). Declare a variable named foo witha value of bar. source fo Source the seript named foo, foo ‘Source the seript named foo. ‘ead ba ‘Read runtime input in the variable bar. ‘ash foo Run the scrip foo ina child bash shell, ‘bash -x foo Run the script foo ina child bash shell with xtrace on,

You might also like