Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Similar documents
Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Practical Session 0 Introduction to Linux

Linux Shell Script. J. K. Mandal

LOG ON TO LINUX AND LOG OFF

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Chapter 4. Unix Tutorial. Unix Shell

Introduction to the UNIX command line

Laboratory 1 Semester 1 11/12

Essential Linux Shell Commands

UNIX Essentials Featuring Solaris 10 Op System

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

Useful Unix Commands Cheat Sheet

CHAPTER 1 UNIX FOR NONPROGRAMMERS

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

The Unix Shell & Shell Scripts

Unix Introduction to UNIX

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Command Line Interface The basics

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Basic Linux (Bash) Commands

Files

2) clear :- It clears the terminal screen. Syntax :- clear

FILE MAINTENANCE COMMANDS

UNIX Shell Programming

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Basic Linux Command Line Interface Guide

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

CENG393 Computer Networks Labwork 1

Linux Tutorial. Ken-ichi Nomura. 3 rd Magics Materials Software Workshop. Gaithersburg Marriott Washingtonian Center November 11-13, 2018

Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application. Questions:

Mills HPC Tutorial Series. Linux Basics I

A Brief Introduction to the Linux Shell for Data Science

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Linux/Cygwin Practice Computer Architecture

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Basic Linux Command Line Interface Guide

Std: XI CHAPTER-3 LINUX

Part 1: Basic Commands/U3li3es

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Introduction to Linux Workshop 1

1. The Mac Environment in Sierra Hall 1242

Software I: Utilities and Internals. What is UNIX?

Physics REU Unix Tutorial

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

CMPT 300. Operating Systems. Brief Intro to UNIX and C

1. The Mac Environment in SIE 1222

Lab Working with Linux Command Line

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces

Introduction to Linux

CSE 15L Winter Midterm :) Review

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

Problem Set 1: Unix Commands 1

Introduction: What is Unix?

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

AMS 200: Working on Linux/Unix Machines

UNIX ASSIGNMENT 1 TYBCA (Sem:V)

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Week 2 Lecture 3. Unix

Introduction to Linux Environment. Yun-Wen Chen

The Unix Shell. Pipes and Filters

Introduction to Supercomputing

Common File System Commands

The Directory Structure

Using the Unix system. UNIX Introduction

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Helpful Tips for Labs. CS140, Spring 2015

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Shell Programming Overview

CSCI 2132 Software Development. Lecture 4: Files and Directories

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

Tutorial 1: Unix Basics

Introduction to Linux for BlueBEAR. January

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

9.2 Linux Essentials Exam Objectives

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Advanced Linux Commands & Shell Scripting

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

h/w m/c Kernel shell Application s/w user

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

PROGRAMMAZIONE I A.A. 2015/2016

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Conditional Control Structures. Dr.T.Logeswari

Transcription:

Basic UNIX Commands BASIC UNIX COMMANDS 1. cat command This command is used to create a file in unix. $ cat >filename This command is also used for displaying contents in a file. $ cat filename 2. ls command It displays the list of files in the current working directory. $ ls cse04.c gfd.c fdsg 3. rm command This command is used to remove an existing file. $ rm filename 4. wc commad This command is used to count the number of lines characters & words in a file. $ wc filename 5. pwd command This command is used to know the current working directory. $ pwd 6. date command This command is used to display the current date,year,month,day &time. $ date 7. echo command This command is used to print the message on the display.

$ echo text 8. cal command This command is used to display the specified month or year calendar. $ cal month 9. who command This command is used to display the date & terminal type of all the users who are currently logged into a system $ who 10.who am I command This command is used to display the logging details of the user who worked in that terminal. $ who am i 11. bc command This command is used to perform mathematical calculations. $ bc operation 12. tputclear command This command is used to clear the screen & place the $ prompt at the top most of the screen. $ tput clear 13. tty command This command is used to display the device type of the terminal. $ tty 14. mkdir command This command is used to create a new directory. $ mkdir filename 15. man command If we get stuck on something, and cannot find an expert to help,we can print any manual page on our terminal with the command man command-name. $ man who 16. head and tail command

The head command is used to display the initial part of a text file. This can be thought of aa a complement command to the tail command. which displays the last part of a text file. By default head command displays first 10 lines of a file and tail command the last lines. $ head [-count] filename. $ head -4 friends jude jacob raju prem will display the first four lines of a file called friends. $ tail [+ - number] filename $ tail +5 friend will display from the 5th line from the beginning of the file. $ tail -5 friend will display from the 5th line from the end of the file. 17. cd command It is used to change the current directory to the other directory specified. $ cd jac $ pwd /jac 18. rmdir command It is used to remove the directory.it requires the directory to be empty. $ rmdir directoryname 19. cat command It helps us to list the contents of a file we specify. If we do not specify the name of the file,it takes input from the standard input. If we want to display the contents of a file abc. The command is $ cat abc Try try until you succeed. To create a file called mat, $ cat > mat Hi!have a nice day Ctrl+d

In order to append data to the same file,use cat command with the >> symbol. 20. cp command It is used to create duplicate copies of ordinary files. $ cp file success success is the file to which the contents of the file has to be copied.if the name of the file already exists,the original contents are erased and the contents of the file are written on the success. 21. ln link command It is used to establish an additional filename for the same ordinary file. $ ln ordinary_filename additional_filename $ ln red rose Advantage of this command is that several users can have access to a common data file.any modification in the additional file or ordinary file reflects in both of them. 22. mv command It is used to rename and move ordinary and directory files. To do this we need both execute and write permissions. Renaming, $ mv aaa bbb To move the contents of the file old to the new,the syntax is: $ mv old new

Study of Unix Editor & Shell Programming vi Editor Command Description vi file start at line 1 of file vi +n file start at line n of file vi + file start at last line of file Saving files and quitting vi Command Description :w save (write out) the file being edited :w file save as file :w! file save as an existing file :q quit vi :wq save the file and quit vi :x save the file if it has changed and quit vi :q! quit vi without saving changes Moving the cursor Keys pressed Effect h left one character l or <Space> right one character k up one line j or <Enter> down one line b left one word w right one word ( start of sentence ) end of sentence 1G top of file ng line n G G end of file <Ctrl>W first character of insertion <Ctrl>U up ½ screen <Ctrl>D down ½ screen <Ctrl>B up one screen

<Ctrl>F Inserting text Keys pressed a A i I o O down one screen Text inserted after the cursor after last character on the line before the cursor before first character on the line open line below current line open line above current line Searching for text Search Finds /and next occurrence of ``and'', for example, ``and'', ``stand'',``grand''?and previous occurrence of ``and'' /^The next line that starts with ``The'', for example, ``The'',``Then'', ``There'' /end$ next line that ends with ``end'' / [bb]ox next occurrence of ``box'' or ``Box'' An Introduction to the Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. Its features include control-flow primitives, parameter passing, variables and string substitution. The shell can modify the environment in which commands run. Input and output can be redirected to files, and processes that communicate through `pipes' can be invoked. Commands are found by searching directories in the file system in a sequence that can be defined by the user. Commands can be read either from the terminal or from a file, which allows command procedures to be stored for later use.

C Shell Commands The C shell provides the following built-in commands: # Marks a command. $ Access variable with $ symbol break case cd chdir continue default echo eval exec exit foreach glob goto if read repeat switch time Resumes execution after the loop. Defines a label in a switch command. Changes directory. Changes directory, same as cd. Continues a loop. Specifies the default case in a switch. Writes arguments to the standard output of the shell. Evaluates a command. Executes the command in the current shell. Exits the shell. Specifies a looping control statement and execute a sequence of commands until reaching an end command. Writes arguments to the standard output of the shell, like the echo command, but without the new line. Continues execution after the specified label. Executes a command if condition met. Get the input from the user Repeats the execution of a command. Starts a switch. Displays the time used to execute commands. Control flow structures - for The for loop notation is recognized by the shell and has the general form for name in w1 w2... do command-list done

A command-list is a sequence of one or more simple commands separated or terminated by a newline or semicolon. Furthermore, reserved words like do and done are only recognized following a newline or semicolon. name is a shell variable that is set to the words w1 w2... in turn each time the command-list following do is executed. If in w1 w2... is omitted then the loop is executed once for each positional parameter; that is, in $* is assumed. Another example of the use of the for loop is the create command whose text is for(( initialization ; condition ; increment or decrement )) do... done Control flow structures - case The general form of the case command is case $a in 1)... 2)... 3)... 4)... *)... Esac A multiple way branch is provided for by the case notation. For example, case $# in 1) cat >>$1 ;; 2) cat >>$2 <$1 ;; *) echo \'usage: append [ from ] to\' ;; esac is an append command. When called with one argument as append file $# is the string 1 and the standard input is copied onto the end of file using the cat command. append file1 file2

appends the contents of file1 onto file2. If the number of arguments supplied to append is other than 1 or 2 then a message is printed indicating proper usage. Control flow structures - while The actions of the for loop and the case branch are determined by data available to the shell. A while or until loop and an if then else branch are also provided whose actions are determined by the exit status returned by commands. A while loop has the general form while Condition do commands done The value tested by the while command is the exit status of the last simple command following while. Each time round the loop command-list1 is executed; if a zero exit status is returned then command-list2 is executed; otherwise, the loop terminates. For example, while Condition do... shift done is equivalent to for Condition do done shift is a shell command that renames the positional parameters $2, $3,... as $1, $2,... and loses $1. Another kind of use for the while/until loop is to wait until some external event occurs and then run some commands. In an until loop the termination condition is reversed. For example, until test Condition -f file do commands done will loop until file exists. Control flow structures - if

Also available is a general conditional branch of the form, if Condition then command-list else command-list fi that tests the value returned by the last simple command following if. A multiple test if command of the form if Condition then command else if Condition then command else if Condition command fi fi fi may be written using an extension of the if notation as, if Condition then command elif Condition then command elif Condition command fi

Compiling your C programs under Unix Compiling a single source file and to run cc helloworld.c If you list files in the current directory, you should find that this has produced a program called a.out. You can then run it by typing:./a.out where the "./" specifies a filename in the current directory. Now let's suppose that you want to give your executable program the name "sayhello", rather than the default name "a.out", use the "-o" option to tell cc what filename to create. And of course, to run it you would type: cc -o sayhello helloworld.c./sayhello Compiling multiple source files in one statement To compile the program, making the executable sayhello, type: cc -o sayhello greet.c hello.c world.c Compiling multiple source files separately In fact in the above examples, cc does three things: preprocessing compiling linking With the "-c" flag, you can make it stop after the compile stage. Type: cc -c greet.c cc -c hello.c cc -c world.c It has produced "object files", greet.o, hello.o, world.o. Object files have undergone compilation, but have not yet been built into an executable program which you can run.

To link them together, making the executable sayhello, type: cc -o sayhello greet.o hello.o world.o To run,./sayhello it should tell you: Hello, world Now suppose that you want your program to print "Hello, world." (with a full stop). Edit the file greet.c, changing the line: into To recompile the program, type: printf("%s, %s\n",word1,word2); printf("%s, %s.\n",word1,word2); cc -c greet.c cc -o sayhello greet.o hello.o world.o