Linux Command Basics I Tony Kombol.

Slides:



Advertisements
Similar presentations
Tony Kombol.  A program that  receives commands from a text input device (e.g. keyboard)  passes them to the operating system to perform  In the.
Advertisements

Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Chapter One The Essence of UNIX.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
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
Very Quick & Basic Unix Steven Newhouse Unix is user-friendly. It's just very selective about who its friends are.
Linux Files and Directories. Linux directories Linux system are arranged in what is called a hierarchical directory structure. This means that they are.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Linux Commands LINUX COMMANDS.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
 Adnan Niazi November UNIX Lecture Goals  Goal 1: Know basic UNIX commands and their use.  Goal 2: Understand the basic structure of a common.
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”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
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.
Unix Basics Chapter 4.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
Linux+ Guide to Linux Certification, Third Edition
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Chapter 1 : The Linux System Part 2 Lecture 2 11/14/
Introduction to Programming Using C An Introduction to Operating Systems.
The Genome Analysis Centre Building Excellence in Genomics and Computational Bioscience.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Linux Commands C151 Multi-User Operating Systems.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Tony Kombol.  man  on-line user manual  man command_you_want_info_on  type q to exit  examples:  for ls (list directory) ▪ man ls  for cp (copy)
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
The Unix File sytem. Introduction Tree structure …
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.
Learning Unix/Linux Based on slides from: Eric Bishop.
A Basic Introduction to the Linux Commandline
Department of Computer Engineering
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Introduction to Unix May 24, 2008 Rabat, Morocco Hervey Allen
Lecture 2 Working with Files and Directories
Unix Shells.
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:
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Web Programming Essentials:
Tutorial of Unix Command & shell scriptS 5027
Shells, Help, and Paths.
Linux Shell Script Programming
Command line.
CSE 303 Concepts and Tools for Software Development
Module 6 Working with Files and Directories
Lab 2: Terminal Basics.
Linux Commands LINUX COMMANDS.
A shell is a user interface.
January 26th, 2004 Class Meeting 2
Presentation transcript:

Linux Command Basics I Tony Kombol

Computers and Terminals

Shells

What "the shell“ is that? A program that receives commands from an input device (e.g. keyboard) passes them to the operating system to perform In the “old days”, it was the only user interface available on a Unix computer Nowadays users have choice: Graphical User Interfaces (GUIs) Command Line interfaces (CLIs) using a shell bash is the most common shell on Linux systems Stands for Bourne Again Shell Enhanced version of the original Bourne shell program Several shell programs available on a typical Linux system csh – “C shell” ksh – “Korn Shell: tcsh – c shell extentions zsh – korn shell extentions

What's xterm, gnome-terminal, konsole, etc.? "Terminal emulators" Programs that put a window in a GUI and let you interact with the shell As if it was a CLI Many different terminal emulators available Most Linux distributions supply several xterm, rxvt, konsole, kvt, gnome-terminal, nxterm, eterm

Starting a Terminal Window managers usually start a terminal from a menu Look through the list of programs to find terminal emulator KDE "konsole" and "terminal" on the Utilities menu Gnome "color xterm," "regular xterm," and "gnome-terminal" on the Utilities menu Start up as many of these as you want Many of different terminal emulators All do the same thing Give you access to a shell session You will probably develop a preference for one, based on the different bells and whistles each one provides

PSA: You're not logged in as root, are you? Don't operate the computer as the “superuser” A.k.a.: root Only become the superuser when absolutely necessary Doing otherwise is: Dangerous Stupid Poor taste Create your user accounts now!

Linux File Systems

File System Organization Linux system files are arranged in a hierarchical directory structure A tree-like pattern of directories Called folders in other systems May contain files and other directories First directory is the root directory Root directory contains files and other directories (subdirectories) Each directory may contain: More files and subdirectories And so on and so on…

Typical Linux file directory structure

Inspecting directories and files

Looking Around Handy commands: ls cat more less file List files and directories Has several options cat Sends file contents to standard output more File contents sent to the screen one page at a time less View text files similar to man Allows scrolling up and down file Classify a file's contents

Examples of the ls command Result ls List the files in the working (current)directory ls dir List the files in the dir directory ls /bin List the files in the /bin directory ls -l List the files in the working directory in long format ls -l /etc /bin List the files in the /bin directory and the /etc directory in long format ls -la .. List all files (even ones with names beginning with a period character, which are normally hidden) in the parent of the working directory in long format

ls common options -a: all -d: directory -l: long -U: do not sort Files starting with “.” are not listed by default -d: directory List directories only, not the contents -l: long List major fields: permissions, group, owner, size, date, name -U: do not sort

Example: ls -l (Long All Format)

Detail Explanation File Name Modification Time Size Group Name of the file or directory Modification Time Last time the file was modified Time and Day are shown If the last modification occurred more than six months in the past, the date and year are displayed Size Size of the file in bytes Group Name of the group that has file permissions in addition to the file's owner

Detail Explanation Owner File Permissions (10 characters) Name of the user who owns the file File Permissions (10 characters) First character is the type of file "-" indicates a regular (ordinary) file "d" indicates a directory Some other special indicators Next nine represent the file's access permissions First set of three characters represent the read, write, and execution rights of the file's owner r, w and x respectively Next set of three characters represent the rights for UIDs of the file's group Final set of three represent the rights granted to everybody else (the world)

Viewing File Contents

cat conCATinate file Can also list the contents files to a terminal Good for listing the contents of a file to a printing terminal Great for listing the contents of short files to a screen: [me@linuxbox me]$ cat .bashrc Sends the contents of the ".bashrc" file to the standard out It works well with piping cat filename | some.program pipe symbol

more Allows file contents or piped output to be sent to the screen one page at a time To list the contents of the "/etc/services" file to the screen one page at a time using more: [me@linuxbox me]$ more /etc/services To perform a directory listing of all files and pipe the output of the listing using more: [me@linuxbox me]$ ls -al | more If the directory listing is longer than a page, it will be shown one page at a time Cannot scroll back <Enter> - advance one line <Space> - advance one page

less Displays text files Similar to the more command Friendlier than cat or more Best for bigger files Similar to the more command User can page up and down through the file Invoked by simply typing: [me@linuxbox me]$ less text_file Display the contents of the file Use the command q to get out

file Examines a file and reports what type of data it contains Handy to know before choosing tool to do something with it Command form: [me@linuxbox me]$ file name_of_file Has many options: -bciknsvzL -f namefile -m magicfiles

File Type Description Viewable as text? ASCII text The name says it all yes Bourne-Again shell script text A bash script ELF 32-bit LSB core file A core dump file (a program will create this when it crashes) no ELF 32-bit LSB executable An executable binary program ELF 32-bit LSB shared object A shared library GNU tar archive A tape archive file. A common way of storing groups of files. no, use tar tvf to view listing gzip compressed data An archive compressed with gzip HTML document text A web page JPEG image data A compressed JPEG image PostScript document text A PostScript file RPM A Red Hat Package Manager archive no, use rpm -q to examine contents Zip archive data An archive compressed with zip

File Manipulation Copying, moving, etc.

Manipulating Files Work with file and directories cp mv rm mkdir copy files and directories mv move or rename files and directories rm remove files and directories mkdir create directories

cp Copies files and directories In its simplest form, it copies a single file: [me@linuxbox me]$ cp file1 file2 Can also be used to copy multiple files to a different directory: [me@linuxbox me]$ cp file1 file2 file3 dir

Other useful examples of cp Command Results cp file1 file2 Copies the contents of file1 into file2. If file2 does not exist, it is created; otherwise, file2 is overwritten with the contents of file1. cp -i file1 file2 As above, but if file2 exists, the user is prompted before it is overwritten with the contents of file1. cp file1 dir1 Copy the contents of file1 (into a file named file1) inside of directory dir1. cp -R dir1 dir2 Copy the contents of the directory dir1. If directory dir2 does not exist, it is created. Otherwise, it creates a directory named dir1 within directory dir2.

mv Performs two different functions depending on how it is invoked Moves one or more files to a different directory Renames a file or directory To move files to a different directory: [me@linuxbox me]$ mv file1 file2 file3 dir To rename a file: [me@linuxbox me]$ mv filename1 filename2

Examples of mv and some options Command Results mv file1 file2 If file2 does not exist, then file1 is renamed file2. If file2 exists, its contents are replaced with the contents of file1. mv -i file1 file2 As above, but if file2 exists, the user is prompted before it is overwritten with the contents of file1. mv file1 file2 file3 dir1 The files file1, file2, file3 are moved to directory dir1. dir1 must exist or mv will exit with an error. mv dir1 dir2 If dir2 does not exist, then dir1 is renamed dir2. If dir2 exists, the directory dir1 is created within directory dir2.

rm Deletes (removes) files [me@linuxbox me]$ rm file Can also be used to delete a directory and its contents: [me@linuxbox me]$ rm -r directory

Examples of rm and its options include Command Results rm file1 file2 Delete file1 and file2. Will not delete directories. rm -i file1 file2 As above, but the user is prompted before each file is deleted. rm -r dir1 dir2 Directories dir1 and dir2 are deleted along with all of their contents.

Danger: Be careful with rm! Once a file is deleted with rm, it's gone! Linux does not have an undelete command rm can inflict terrific damage on a system if not careful Particularly when used with wildcards Before using rm with wildcards, try this helpful trick: Assume files are named file1things, file2things, file3things… Construct the command using ls instead of rm ls file* It lists:file1things, file2things, … filewings, filers, … Then try ls file*ings It lists:file1things, file2things, … filewings, … By doing this the effect of your wildcards can be seen before deleting the files After testing and verifying the command with ls, recall the command with the up-arrow key and then substitute rm for ls in the command rm file*th*

mkdir Used to create directories [me@linuxbox me]$ mkdir directory

HELP! me if you can…

man Almost all UNIX and Unix-like operating systems have extensive documentation Known as man pages Short for "manual pages“ Use man to display the pages Each page is a self-contained document Usage examples [me@linuxbox me]$ man man [me@linuxbox me]$ man ls

apropos Don’t know the name of a command? apropos some_key_word Will return names of commands With some_key_word in the man description files

--help Many commands support the --help option Get help for that command One stream of data Not as readable as man Example: get extra help for the ls command: ls --help

Other

Shell helps: The shell can help you with your typing! Autocomplete: Tab key Start a command or file name Hit Tab If what you typed is unique up to that point bash will complete the rest of the typing! If not unique a second tab will show matching options Recall: The up arrow will recall previous commands The down arrow moves back

Wrap-up

Top Linux Commands for Newbies cat Prints file contents to standard output. Good for listing the contents of short files to the screen. It works well with piping. echo Displays whatever you type in after echo on a new line in the command prompt. ls List the content of the current directory. It is the basic command to list contents of the file system. cd Change directory man Start the manual viewer. man stands for manual, so “man page” really means it’s manual page. Most Linux commands have manual pages that describe how the command is utilized. find Use the find command to find your files. head Show the first lines of a file (default is 10 lines) tail Show the last lines of a file (default is 10 lines) mv Use to move or rename files