Basic Linux/UNIX Commands The symbol of Linux. Unix doesn’t really care where you log in from, though some system administrators might. Logging in Log.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Linux Installation and Administration Lesson 2 Tutor: George Papamarkos.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Introducing UNIX EMBnet slide 1 Introducing the UNIX Operating System.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Linux Directory Navigation. File & Directory Commands This is a minimal list of Unix commands that you must know for file management: ls (list) mkdir.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
Essential Unix at ACEnet Joey Bernard, Computational Research Consultant.
Unix Basics Chapter 4.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
Agenda Chapter 1: Linux (Unix) Features Commands (Chapters 2 & 3) Command Structure / Command line editing man, passwd, cal, date, whereis, which Working.
Linux+ Guide to Linux Certification, Second Edition
PROGRAMMING PROJECT POLICIES AND UNIX INTRO Sal LaMarca CSCI 1302, Fall 2009.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Reading None.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
November 5, 2015CIS 118 Intro to UNIX What’s a Unix? Unix is an Operating System Designed for high-traffic usage Many variants –Linux, BSD: free versions.
1May 16, 2005 Week 2 Lab Agenda Command Line FTP Commands Review More UNIX commands to learn File name expansion - * Introduction of vi.
Linux+ Guide to Linux Certification, Third Edition
Introduction to Programming Using C An Introduction to Operating Systems.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
1 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Learning basic Unix command It 325 operating system.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
CMSC 104, Version 8/061L03OperatingSystems.ppt Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Introducing the UNIX Operating System.
Chapter 11 Command-Line Master Class
Prepared by: Eng. Maryam Adel Abdel-Hady
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Lecture 2 Working with Files and Directories
Some Linux Commands.
C151 Multi-User Operating Systems
The Command Prompt Commands are the way to “do things” in Unix
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands:
CSE 374 Programming Concepts & Tools
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Web Programming Essentials:
Tutorial of Unix Command & shell scriptS 5027
Introduction Paul Flynn
Linux Shell Script Programming
January 26th, 2004 Class Meeting 2
LPI Linux Certification
Presentation transcript:

Basic Linux/UNIX Commands The symbol of Linux

Unix doesn’t really care where you log in from, though some system administrators might. Logging in Log in from anywhere you have permission Have graphical output sent anywhere you have permission You must have a username (login id) to use a unix system This identifies you to the system so it can manage your work properly. Every user is a member of one or more groups of users. This helps the system manage different types of user properly.

Connecting to embnet.org Connected. Welcome to the Bioinformatics Course. Login: Logging in Connect to the unix machine using a suitable program on your local machine. Telnet Xterm Secure Shell Kermit Other terminal emulators username unix is case sensitive. username is not the same as Username or USERNAME Password: unix doesn’t show anything on the screen as you type your password. The system will be unavailable on friday afternoon for maintenance. You have new mail. ~> You may get some messages here from the system administrator.

~> The prompt can be customised to look how you wish your present location The shell or command line Several different shells but they behave more or less the same the machine you are logged in to 1. The Prompt. your username

The shell or command line 2. Commands ~> The shell breaks the command up into individual words ls -ald *.txt The first word is a command ls -ald *.txt The subsequent words form a list of arguments to the command arguments beginning with - are options ls -ald *.txt * is a special character. It means ‘any group of characters’ (including none). The shell finds all the filenames that match anything.txt and adds them to the list of arguments By default the boundary between words is a space. To get the shell to treat a phrase that includes spaces as a single word, put it in quotes like this: 'my word' or "my word". Options control how the program runs. '-a -l -d' is equivalent to ' -ald'

String or Dollar Treat the next word as a variable and write out its value Backslash. Change the meaning of the next character. Pipe. Pass the output of the command on the left as the input to the command on the right. Redirect the commands output, eg. to a file Redirect a commands input. eg. from a file instead of the keyboard. Semicolon Seperate commands typed in together. More Special Characters *?" ' &|>< ``$\ Any group of characters including none. Any single character.word delineationCause the process to run in the background Backticks (not '). Take the output of the command as an argument Some special characters can lose their special meaning if they are inside quotes. ;

Organization "Everything is a file" An ordinary file contains data. A directory contains other files. A link is a file that is a shortcut to another file. The data could be an image, a document, a set of instructions (a program) or any fixed information. This is also known as a folder on some systems. A directory can contain other directories (which are then known as sub-directories.) Files can have more than one name, and be in different directories at the same time There are many other types of file. You don't need to worry about these. You probably won't come across one in normal use of the system.

Organization of the file system / The top of the file system is the directory '/', commonly known as the root directory bin usr etc home Several subdirectories under the root directory username Another subdirectory. project seq2seq1seq3seq4 letterprot An example users home directory with a subdirectory and several files Any file in the file system can be uniquely identified by describing the path to it from the root directory. /home/username/prot/ home /home/username/prot username /home/username/prot prot

Organization of the file system / binusretchome username project seq2seq1seq3 seq4 letterprot Any process is located somewhere in the filesystem The command ' pwd ' will tell you where. ~>pwd /home/username '~' is a unix shortcut meaning 'your home directory'

Looking at the file system / binusretchome username project seq2seq1seq3 seq4 letterprot ' ls ' lists the files in a directory or directories ~>ls protletterproject ~> project: seq1seq2seq3seq4 ls project Without an argument, ls lists all the files that don't start with. in the current directory There are many options to ls that allow you to select and control the information it presents.

Basic shell commands - ls ls: list existing files in current directory –Short listing: ls –List all files: ls –a –Detailed long list: ls –l –All of the above: ls -al

Moving around the file system / binusretchome username project seq2seq1seq3 seq4 letterprot ' directory ' is the directory to which you want to move. The name can be written as the full path (from root) or as the relative path (from your current directory) You can move to a different directory with the command ' cd directory ' ~>cd /home/username/project ~/project>pwd /home/username/project ~>cd project ~/project>pwd /home/username/project ~/project>cd.. '..' means the parent directory. '.' means the current directory... ~>pwd /home/username ~> repeat using the relative path

Basic shell commands - cd cd – changing directory –To a subdirectory: cd Desktop –Giving a complete path: cd /home/ /Desktop –To the next directory above: cd..

Changing the file system / binusretchome username project seq2seq1seq3 seq4 letterprot You can create a new subdirectory in the current directory with the command ' mkdir directory ' ~>mkdir model ~> model

Changing the file system / binusretchome username project seq2seq1seq3 seq4 letterprot You can delete an empty subdirectory with the command ' rmdir directory ' ~>rmdir model model ~> model You can delete a file with the command ' rm file ' rm prot ~> You can delete a subdirectory and its contents with the command ' rm -rf directory '

More about files: filenames Filenames can contain any normal text character including spaces and special characters. Filenames can be almost any length. It is best to stick to a-z, A-Z, _, -, and numbers. It is best to keep them short as it saves typing. If a filename contains a special character or a space you may need to put quotes around the whole path. Special characters in filenames can cause problems with some programs.

You can view the contents of one or more files a page at a time on the screen with the command: ' more file1 file2...' You can print the first few lines of a file with the command: ' head file1 file2...' More about files: reading files You can print the contents of one or more files to the screen with the command: ' cat file1 file2...' cat prints the whole file at once, so a file longer than just a few lines will run off the top of your screen. more will let you search through a file, go backwards and forwards and has many other functions. The last few lines can be viewed with 'tail'

More about files: editing files You can change the content of text files and create new files with a text editor. Text editors edit text. They do not try to format the text like word processors. PICO A novice friendly basic text editor used as standard on many systems. Start with the command ' pico filename ' EMACS A powerful editing environment which can be programmed. It has many modes for auto layout of program code. Start with the command ' emacs filename ' VI A powerful editor which can be somewhat confusing for newcomers. It is designed for rapid editing of text files and programming. Start with the command ' vi filename '

If newfilename is a directory, then the file will be copied to ' newfilename/oldfilename ' You can copy a file with the command ' cp oldfilename newfilename ' ~> letterproject ~> More about files: copying files ls cp letter draft ~>ls draftletterproject ~> Warning: If a file called newfilename already exists then it will be overwritten. The command ' mv oldfilename newfilename ' can be used to rename a file

~> To copy file: letter ' from linus to dir1 subdirectory of your course account More about files: copy files Scp – Secure Copy (remote file copy program) letterproject ~> ls scp letter course:dir1 ~> scp course:myfile. ~> scp -r mydir course: To copy file: myfile from your course account to your home directory on linus password: letter 100% |*************************| 9 To recursively copy : mydir from your course homedirectory to your account on linus

Grep – power search utility - Basics The grep program searches a file or files for lines that have a certain pattern. The syntax is: > grep pattern file(s) The simplest use of grep is to look for a pattern consisting of a single word. It can be used in a pipe so that only those lines of the input files containing a given string are sent to the standard output. If you don't give grep a filename to read, it reads its standard input; that's the way all filter programs work: runs ls -l to list your directory. The standard output of ls -l is piped to grep, which only outputs lines that contain the string "Aug" (that is, files that were last modified in August). Because the standard output of grep isn't redirected, those lines go to the terminal screen. ~> ls -l | grep "Aug" -rw-rw-rw- 1 john doc Aug 6 14:10 ch02 -rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07 -rw-rw-r-- 1 john doc 2488 Aug 15 10:51 intro -rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros %

The sort command arranges lines of text alphabetically or numerically sort doesn't modify the file itself; it reads the file and writes the sorted text to the standard output. sort arranges lines of text alphabetically by default.

~> More about files: sort Afghani Cuisine Tio Pepe's Peppers Bangkok Wok Sushi and Sashimi Mandalay Big Apple Deli Isle of Java Sweet Tooth ~> more food sort food Afghani Cuisine Bangkok Wok Big Apple Deli Isle of Java Mandalay Sushi and Sashimi Sweet Tooth Tio Pepe's Peppers ~>

Usage: sort – [general options] –o [outfile] –[key interpretation options] –t[char] –k[keydef]…[filenames] Option: -n Sort numerically (example: 10 will sort after 2), ignore blanks and tabs. -r Reverse the order of sort. -f Sort upper- and lowercase together. +x Ignore first x fields when sorting. -m Merges several input files

~> ls -l | grep "Aug" | sort +4n Sort, grep, ls ~> ls -l | grep "Aug" | sort +4n -rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros -rw-rw-r-- 1 john doc 2488 Aug 15 10:51 intro -rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07 -rw-rw-rw- 1 john doc Aug 6 14:10 ch02 ~> This pipe sorts all files in your directory modified in August by order of size, and prints them to the terminal screen. The sort option +4n skips four fields (fields are separated by blanks) then sorts the lines in numeric order. So, the output of ls (actually, the output of grep) is sorted by the file size (the fifth column, starting with 1605). Both grep and sort are used here as filters to modify the output of the ls -l command. If you wanted to this listing to someone, you could add a final pipe to the mail command. Or you could print the listing by piping the sort output to your printer command (like lp or lpr). What does this do?

Permissions determine who can read, write, or execute a given file. More about files: permissions Every file is protected to a greater or lesser extent. Owner Group World The user who owns the file All the other users in the system. Files can have read, write or execute permission for each of the three types of user. Other users in the same group as the user who owns the file.

You can view the permissions for a file by listing it in long format with the command ' ls -l filename ' ~>ls -l letter -rwxr--r-- 1 username users 6048 Aug 17 16:07 letter The letter l The file type: - - ordinary file d - directory l - link (shortcut) Permissions for the owner -rwxr--r-- Permissions for the owners group -rwxr--r-- Permissions for everyone else -rwxr--r--username The user who owns the file users The files group 6048 The files size Aug 17 16:07 The date the file was last modified letter The files name More about files: permissions

~> You can change the permissions for a file with the command ' chmod change filename ' -rwxr--r-- 1 username users 6048 Aug 17 16:07 letter ~> More about files: permissions ls -l letter chmod o-r letter For whom you are changing permissions: o - other g - group u - user a - all chmod o-r letter Permissions being changed: r - read permission w - write permission x - execute (run) permission chmod o-r letter How you are changing permissions: - - remove these permissions + - add these permissions = - set permissions to this ~> -rwxr username users 6048 Aug 17 16:07 letter ~> ls -l letter change is the modification you want to make to the files permissions

You can get help on a command by using the command ' man command' Getting help This will bring up the manual page and show it to you screen by screen If you do not know what a command is called, use the option ' -k ' to get a list of commands that may be relevant 'man -k word' Try using the options '-h', '-help', or '--help' if you can't find the man page. This will find all manual pages containing word in the short description of the command.

Finding commands quickly ~> history :55 more food :58 sort food ~> less.bash_history ~> In Linux history | grep man :04 man scp :05 history | grep man List of all commands previously typed with the word “man”

Finding commands quickly > history > less.bash_history > history | grep man –You see a list of all the commands you type with the word man in them

Process Management ~> ps PID TTY TIME CMD pts/27 0:00 tcsh ~> top ~> Ctrl-C to break out kill last pid: 22413; load averages: 1.14, 1.20, :19: processes:1064 sleeping, 2 running, 17 zombie, 2 stopped, 4 on cpu CPU states: % idle, % user, % kernel, % iowait, % swap Memory: 4096M real, 3310M swap in use, 7852M swap free PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND lakshmin M 20M cpu0 3: % netscape root M 42M cpu3 114: % Xsun root K 1536K cpu1 612: % top Kill [-s signal] | -p] [–a] PID

Determining File Sizes and Space Usage ~> df Filesystem 1k-blocks Used Available Use% Mounted on /dev/md/dsk/d % / swap % /var/run /dev/md/dsk/d % /export/home linux:/export/home % /net/linux/ export/home ~> df -h

FTP – File Transfer Protocol ~> Connected to ftp.ncbi.nih.gov. 220 FTP Server ready. Name (ftp.ncbi.nih.gov:huynh): ftp ftp.ncbi.nih.gov anonymous 230 Anonymous access granted, restrictions apply. 331 Anonymous login ok, send your complete address as your password. Password: ftp> bin 200 Type set to I ftp> ls -l ftp> cd blast ftp> ls -l 200 PORT command successful. 150 Opening ASCII mode data connection for file list. dr-xr-xr-x 12 ftp anonymous 4096 May 20 17:04 blast dr-xr-xr-x 3 ftp anonymous 4096 Mar 2 20:50 cgap dr-xr-xr-x 4 ftp anonymous 4096 Jun 12 18:33 cn3d dr-xr-xr-x 11 ftp anonymous 4096 Dec entrez dr-xr-xr-x 5 ftp anonymous 4096 Jan 15 21:35 fa2htgs dr-xr-xr-x 11 ftp anonymous Jun 26 07:01 genbank dr-xr-xr-x 15 ftp anonymous 4096 Jun 19 14:22 genomes dr-xr-xr-x 7 ftp anonymous 4096 Feb 14 23:06 mmdb dr-xr-xr-x 4 ftp anonymous Jun 26 07:36 ncbi-asn1 dr-xr-xr-x 73 ftp anonymous 4096 May 17 20:34 pub dr-xr-xr-x 2 ftp anonymous 4096 Dec pubmed dr-xr-xr-x 11 ftp anonymous 4096 Mar 7 17:07 refseq dr-xr-xr-x 59 ftp anonymous 4096 May 15 21:45 repository dr-xr-xr-x 6 ftp anonymous 4096 Apr 26 19:27 sequin dr-xr-xr-x 16 ftp anonymous 4096 Jun 14 22:32 snp dr-xr-xr-x 2 ftp anonymous 4096 Jan tech-reports dr-xr-xr-x 12 ftp anonymous 4096 Dec toolbox 226 Transfer complete. remote: -l 1092 bytes received in seconds (46.86 Kbytes/s) ftp> ls -l ftp> cd executables ftp> ls -l ftp> mget blast.linux.tar.Z mget blast.linux.tar.Z? y 200 PORT command successful. 150 Opening BINARY mode data connection for blast.linux.tar.Z ( bytes). 226 Transfer complete. local: blast.linux.tar.Z remote: blast.linux.tar.Z bytes received in 4.3 seconds ( Kbytes/s) ftp> ftp> ls -l 200 PORT command successful. 150 Opening ASCII mode data connection for file list. dr-xr-xr-x 2 ftp anonymous 4096 Jun blasturl dr-xr-xr-x 3 ftp anonymous 4096 Jul 1 09:46 db dr-xr-xr-x 2 ftp anonymous 4096 Feb 26 22:59 demo dr-xr-xr-x 3 ftp anonymous 4096 Apr documents dr-xr-xr-x 5 ftp anonymous 4096 Jun 21 19:19 executables dr-xr-xr-x 3 ftp anonymous 4096 Dec fmerge dr-xr-xr-x 2 ftp anonymous 4096 Aug matrices dr-xr-xr-x 3 ftp anonymous 4096 Jun network dr-xr-xr-x 12 ftp anonymous 4096 Jun 18 22:49 server dr-xr-xr-x 2 ftp anonymous 4096 Jul 1 15:59 temp 226 Transfer complete. remote: -l 645 bytes received in seconds (12.05 Kbytes/s) ftp> ls 200 PORT command successful. 150 Opening ASCII mode data connection for file list. old special README.bls README.imp blast.hpux11.tar.Z blast.hpux11.tar.gz blast.AIX-powerpc.tar.Z blast.hqx blastz.exe blast.solaris.tar.Z blast.solarisintel.tar.Z blast.linux.tar.Z blast.sgi.tar.Z blast.sgi32.tar.Z blast.macosx.tar.gz blast-FreeBSD-4.5-i386.tar.gz blast.alphaOSF1.tar.Z delme 226 Transfer complete. 311 bytes received in seconds (8.05 Kbytes/s) ftp>

Useful literature Learning the UNIX operating system - O'Reilly Press UNIX Quickguide - EMBnet Running Linux, 3 rd Edition – O’Reilly Press

Useful Online Resource

Extra Slides