390 likes | 826 Views
Introduction to Linux Commands. By:- GAGAN KUMAR C.S.E 7 TH SEMESTER 3710103. Introduction. SHELL A program that interprets commands. Allows a user to execute commands by typing them manually at a terminal, or automatically in programs called shell scripts.
E N D
Introduction to Linux Commands By:- GAGAN KUMAR C.S.E 7TH SEMESTER 3710103
Introduction SHELL A program that interprets commands. Allows a user to execute commands by typing them manually at a terminal, or automatically in programs called shell scripts. A Shell is not an operating system. It is a way to interface operating system and run commands. BASH BASH= Bourne Again Shell Bash is a shell written as free replacement to the standard Bourne Shell (/bin/ sh) originally written by Steve Bourne for UNIX Systems. It has all the features of the original Bourne Shell, plus additions that make it easier to program with and use from the command line. Since it is Free Software, it has been adopted as the default shell on most Linux Systems.
Command Syntax Commands can run by themselves, or you can pass in additional arguments to make them do different things. Typical command syntax can look something like this: command [-argument] [-argument] [--argument] [file] Examples: ls List files in current directory ls –l Lists files in “long” format ls–l –color As above, with colorized output cat filename Show contents of a file cat –n filename Show contents of a file, with line numbers
Navigating the Linux File system The Linux file system is a tree-like hierarchy of directories and files. At the base of the file system is the “/” directory, otherwise known as the “root” (not to be confused with the root user). Unlike DOS or Windows file systems that have multiple “roots”, one for each disk drive, the Linux file system mounts all disks somewhere underneath the / file system.
Vi Editor Vi Editor is used for editing the documents, it can read and write the text files.
Shell Script Write a Shell Script to print the following Linux Command. 1. Ask for the User name to be entered. 2.Print Welcome Mr. User 3. The Date and Time 4. Your are Mr. User 5. Thank You
Steps to Write Shell Script $ cat >scriptdemo echo "Please Enter Your Name" read Name echo "Welcome Mr.$Name" echo "Date and Time is:`date`" echo "You are Mr.`whoami`" echo "Thank You” -> Press (Ctrl + d) to save file $chmod +x script demo $./scriptdemo
Write a Shell Script to Find Sum of Two Numbers $ cat >calculate echo "Enter a" read a echo "Enter b” read b echo "Sum:`expr $a + $b`" ->Press (ctrl +d) to save file $ chmod +x calculate $ ./calculate
Write a shell Script to print 10 numbers cat >while a=0 while [ $a -lt 10 ] Do echo $a a=`expr $a + 1` done
Tree Structure of Directories Cd /usr/local/bin Cat >tree #!/bin/bash SEDMAGIC='s;[^/]*/;|____;g;s;____|; |;g’ if [ "$#" -gt 0 ] ; then dirlist="$@" else dirlist=".” fi for x in $dirlist; do find "$x" -print | sed -e "$SEDMAGIC" Done Press (ctrl +d) to save Chmod +x tree Run in any Directory