Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Linux Commands By:- GAGAN KUMAR C.S.E 7 TH SEMESTER 3710103 1.

Similar presentations


Presentation on theme: "Introduction to Linux Commands By:- GAGAN KUMAR C.S.E 7 TH SEMESTER 3710103 1."— Presentation transcript:

1 Introduction to Linux Commands By:- GAGAN KUMAR C.S.E 7 TH SEMESTER 3710103 1

2  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. Introduction 2

3  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: lsList files in current directory ls –lLists files in “long” format ls –l –colorAs above, with colorized output cat filenameShow contents of a file cat –n filenameShow contents of a file, with line numbers 3

4  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. Navigating the Linux File system 4

5 The Linux Directory Layout /binEssential command binaries (programs) are stored here (bash,ls,mount,tar,etc.) /bootStatic files of the boot loader. /devDevice files (just like other files) /etcHost-specific system configuration files. /homeLocation of users’ personal home directories (e.g. /home/gagan) /libEssential shared libraries and kernel modules. /rootThe root (super user) home directory. /sbinEssential system binaries (fdisk,fsck,init,etc). /tmpTemporary files.(All users have permission to place temporary files here.) /usrThe base directory for most shareable, read- only data(programs, libraries,etc.) /usr/binMost user programs are kept here (cc,find,du). /usr/includeHeader files for compiling C programs. 5

6 /usr/libLibraries for most binary programs. /usr/local“Locally” installed files. The directory only really matters in environments where files are stored on the network. /usr/sbinNon-vital system binaries. /usr/shareArchitecture-independent data (icons, backgrounds, documentation, etc). /usr/srcProgram source code. E.g. The Linux kernel. /usr/X11 R6The X Window System. /varVariable data: mail and printer spools, log files,lock files, etc. 6

7 Working With Files and Directories fileFind out what kind of file it is. e.g: “file /bin/ls” tells us that it is a Linux executable file. CatDisplay the contents of a text file on the screen. e.g: “cat mp3files.txt” HeadDisplay the first few lines of a text file. e.g: “head /etc/services TailDisplay the last few lines of a text file. e.g: “tail /etc/services” CpCopies a file from one location to another. e.g: “cp mp3files.txt /tmp” (copies the mp3files.txt to the /tmp directory) mvMoves a file to a new location, or renames it. e.g: “mv mp3files.txt /tmp” RmDelete a file. e.g: “rm /tmp/mp3files.txt” MkdirMake Directory, e.g: “mkdir /temp/myfiles/ RmdirRemove Directory 7

8 Commands for Navigating the Linux Filesystems COMMANDDESCRIPTION Pwd“Print Working Directory”. Shows the current location in the directory tree. Cd “Change Directory” e.g. cd /usr/src/linux Cd ~“~” is an alias for your home directory. (Shortcut to HOME) Cd..Move up one Directory. Cd -Return to previous directory. LsList all files in the current directory, in column format. Ls List all the files in the specified directory. Ls –lList files in “long” format, one file per line. WcPrint the number of newlines, words, and bytes in files e.g: “wc –l file1.txt” SortSort lines of text files e.g: “sort file1.txt” 8

9 Ls –aList all files, including “hidden” files. Hidden files are those files that begin with a “.”, e.g. The.bash_history file in your home directory. Ls –ld A “long” list of “directory”, but instead of showing the directory contents, show the directory’s detailed information. Ls /usr/bin/d*List all files whose names begin the letter “d” in the usr/bin directory. 9

10 Finding Things CommandDescription WhichShows the full path of shell commands found in your path. e.g: “which grep” WhereisLocates the program, source code, and manual page for a command (if all information is available). e.g: “which ls” LocateA quick way to search for files anywhere on the file system. e.g: “locate Music” FindA very powerful command, but sometimes tricky to use. It can be used to search for files matching certain patterns, as well as many other types of searches. e.g: “find music” ManShow all Information about the command. e.g: “man ls” HelpShows the available option for that command e.g: “ls –help” 10

11  Vi Editor is used for editing the documents, it can read and write the text files. 11 Vi Editor CommandDescription ViThis command opens the “vi Editor” in the terminal. iPress the “I” key for INSERT MODE (Now you can write anything). escPress the “esc” key to Exit the Insert Mode. :w This key is used to write the file in the pwd. :wq To exit after writing the file in the pwd Vi To open the file in the vi editor. (Press “i” key to edit the file). :q!Quit without saving

12 Informational Commands CommandDescription PsLists currently running process (programs). WShow who is logged on and what they are doing. whoamiShow the User Id logged in IdPrint your user-id and group id’s DfReport filesystem disk space usage (“Disk Free”) DuDisk Usage in a particular directory. “du –s” provides a summary for the current directory. TopDisplay CPU process in a full-screen GUI (Type “Q” to quit). Uname –aPrints system information to the screen (Kernel version, machine type,etc.) 12

13 Other Utilities CommandDescription ClearClear the screen EchoDisplay text on the screen (Useful when writing shell scripts). e.g: echo “Hello World” MoreDisplay a file, or program output one page at a time. e.g: more mp3files.txt Ls –l | more LessAn improved replacement for the “more” command. Allows you to scroll backwards as well as forwards. Grep Search for a pattern in a file or program output. e.g: grep “nfs” /etc/services (This looks for any line that contains the string “nfs” in the file “/etc/services” and displays only those lines. prPrint a file or program output. e.g: “lpr mp3files.txt” mailTo read and write mail Eg: mail 13

14 su“Switch User”. Allows you to switch to a another user’s account temporarily. The Default account to switch to is the root/superuser account. Examples: su -Switch the root account. su- -Switch to root, and log in with root’s environment su larry -Switch to Larry’s account 14

15  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 15 Shell Script

16  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 16

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

18 cat >while a=0 while [ $a -lt 10 ] Do echo $a a=`expr $a + 1` done 18 Write a shell Script to print 10 numbers

19  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 19 Tree Structure of Directories

20 Shortcuts to Make it all Easier! ShortcutDescription Up/Down Arrow KeysScroll through your most recent commands “History” commandShow your complete command history. Tab CompletionIf you type a partial command or filename that the shell recognizes, you can have it automatically completed for you if press the Tab key. Complete recent commands with “!”Try this: Type “!” followed by the first couple of letters of a recent command and press Enter! e.g: find /usr/bin –type f –name m\* …and now type: ! Fi Search your command history with CTRL- R Press CTRL-R and then type any portion of a recent command. It will search command for you. Scrolling the screen with Shift- Page Up and Page Down Scroll back and forward through terminal. 20


Download ppt "Introduction to Linux Commands By:- GAGAN KUMAR C.S.E 7 TH SEMESTER 3710103 1."

Similar presentations


Ads by Google