A Basic Introduction to the Linux Commandline

Slides:



Advertisements
Similar presentations
By: Tony Andrews.  Linux directory ordering system  Navigating and creating directories ◦ Listing directories and files ◦ Creating directories ◦ Changing.
Advertisements

Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Lab6 CPCS361 I.Mona Alshehri. Working with Files and Directories Creating files Create a file with the cat command type the command cat > name_of_file.
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 By Darcy Tatlock. 1. Successful Log Into Unix To actively manipulate your website you need to be logged in. Without being logged in you cannot enter.
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.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
The file structure and related utilities CS240 Computer Science II.
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”
© Crown copyright Met Office An Introduction to Linux PRECIS Workshop, University of Reading, 23rd – 27th April 2012.
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.
Essential Unix at ACEnet Joey Bernard, Computational Research Consultant.
Unix Basics Chapter 4.
Interacting with a UNIX computer: Navigating through the directory tree.
Carnegie Mellon Linux Boot Camp Jenna MacCarley, Peter Pearson, Shashank Goyal 9/19/2015.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Chapter Two Exploring the UNIX File System and File Security.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
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.
The Genome Analysis Centre Building Excellence in Genomics and Computational Bioscience.
Λειτουργικά Συστήματα – 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,
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Using the “CLI” Unix / Linux Preparation Course June 9, 2013 Lusaka, Zambia.
Linux Commands C151 Multi-User Operating Systems.
File and Folder CLI Commands 12/24/ Agenda Overview of OS functions and the SHELL Internal v External Commands Command History Making & Modifying.
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.
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.
CS 120 Extra: The CS1 Server Tarik Booker CS 120.
Learning Unix/Linux Based on slides from: Eric Bishop.
UNIX Basics Matt Hayward October 18, 2016 LS560 – Information Technology for information professionals.
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
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
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
UNIX Basics Internet Technology.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Exploring the UNIX File System and File Security
Operating Systems and Using Linux
Web Programming Essentials:
Tutorial of Unix Command & shell scriptS 5027
Introduction Paul Flynn
Command line.
CSE 303 Concepts and Tools for Software Development
Module 6 Working with Files and Directories
Lab 2: Terminal Basics.
January 26th, 2004 Class Meeting 2
Presentation transcript:

A Basic Introduction to the Linux Commandline

Hubble Bubble Before we begin in the office Linux if often likened to scene from Hamlet. Linux is not only case sensitive, but also follows exacting syntax meaning if you put in PUPPY tails when you only need puppy tails, or the eye of newt goes in before the tears of a cat, either nothing will happen or something totally unexpected.

Accessing the Terminal Now you have started into a in the GUI, in many ways this is very similar to the Windows or Mac OSX Operating Systems. To get the most out of Linux you will want to access the terminal from time to time. To do this you will need to look for the below icon on the launch bar on the left. Win & Mac are entirely GUI. Linux Command line is the first stepping stone to the HPC systems at NBI

Accessing the Terminal This will result in a window like this. Win & Mac are entirely GUI. Linux Command line is the first stepping stone to the HPC systems at NBI

Basic flags, commands and getting around. The Basics Basic flags, commands and getting around. They have the option of playing with the commands as I talk about them or waiting to use them at the exercise step. Either way note that Linux is case sensitive

The Basics Commands So now we are in the Terminal how do we get the computer to do something? You give the computer a command. Start with some of the informative commands then move onto navigational commands.

The Basics Command Details who Commands Command Details who This will display information about who is logged on, both yourself and others. whoami This will display information about the current user i.e. You! ls ls is short hand for LiSt. It will display all the visible files and sub directories within the directory that you are currently in. The files will be listed alphabetically by default but this can be altered with flags. pwd This will Print the Working Directory. A fancy way of asking the computer to display information about where you are and what directory you are currently working in. apropos Keyword This command followed by a keyword will provide you with information on commands that are related to that keyword. man Command This will provide you with the electronic manual for the given command. Highlight the PWD command, LS command and MAN command

The Basics Commands man Command When you get stuck with a command then man is your friend. Its manual pages display a description, instructions of its use and how all the flags will interact with this command. man ls – this will provide you with the manual for the ls command as displayed below.

The Basics Commands

The Basics Flags Using the commands pwd and ls you can gather information about the digital world around you, using flags will give you even more control. We will place the flags behind the ls command for demonstrative purposes

The Basics Flag Details ls -a Flags Flag Details ls -a LiSt All – This will list all of the files in the directory including the hidden dot files. ls -l LiSt Long – This will list all the files and/or subdirectories with detailed information such as file size, date modified etc. ls -t LiSt Time – This will sort the list into a chronological order based on modification time. ls -tu This list will list them chronologically based on the last access date. ls -R This list will include the content of subdirectories. ls –S LiSt Size – This list will be based on the size order. ls –h LiSt Human – this will make the list file sizes in human readable format for example the size would be 1.0MB instead of 1004638 ls -r LiSt Reversed – This will list the files in a reverse alphabetical order.

The Basics It is possible to combine flags for instance ls –alh would display all files including hidden in the long format human readable.

The Basics Getting Around The commands for getting around the directories and file structures are really simple. Inverted tree like design with the root directory at the top, the user home directory and other essential folders below that, and the general directories/subdirectories below this.

The Basics Getting Around

The Basics Command Details cd .. Getting Around Command Details cd .. Change Directory - to one level up the tree. cd ~ Change Directory - to the home directory mkdir Directory Make DIRectory – this creates a new directory within the current working directory rmdir Directory ReMove DIRectory – This will remove the named directory, It must be both empty of files and within the current working directory rmdir –r Directory ReMove DIRectory – the r flag on this command will along with its contents rm –i Directory ReMove – the i flag on this command will make it so there is user interaction, i.e. the computer will ask for confirmation rm –ir Directory ReMove – the combination ir will remove all files within the directory and ask for confirmation for each file within it. mv filename new_filename MoVe – This will move the file to a new location cp filename new_filename CoPy – This will make a copy of the file under the specified name. Highlight the space in the CD .. Command and that .. Means the parent directory Advise that they might need to use shift+| or ¬ to get the ~

The Basics Getting Around One thing to note is that you cannot move directly between directories on the same level using the cd command alone, you have to either go up a layer using the cd .. then cd to the directory or combine the commands.

The Basics Getting Around You can take this one step further and add in further sub directory if known that you want to go to. cd ../”Sub Dir 2”/Results

The Basics Getting Around You can also use the absolute path of the directory if you know it. Absolute paths are always from the root directory In this case it would be cd /usr/usr1/Dir/”Sub Dir 2”

The Basics Making Folders mkdir filename - Will create a new directory or folder with the specified name assuming that one by this name does not already exist. This directory will be created within the directory you are currently occupying. This is assuming that the directory doesn’t all ready exist

The Basics Removing Files & Folders rm filename – This will delete a file. Using flags with this can speed up the deleting process by automating it and removing the need for user confirmation. rmdir directoryname – This will delete a directory as long as the directory is empty

The Basics Moving Files mv filename – This can move one or more files to a new directory $cd results $ls Result1.c Result2.c Result3.c Result4.c invalid results/ $mv * invalid results/ This will move all the files out of the results directory and move it to the invalid results folder. (you’ll learn about * later)

The Basics Moving Files mv filename – even though this is the move command it can also be used to rename a file or directory $ls sample.txt $mv sample.txt sample1.txt sample1.txt

The Basics Copying Files cp filename /new/location/. – this will copy a file to the specified location. cp filename /new/location/newname – this will copy a file to the specified location under a new name. cp -R /original/location /new/location/. – this will copy a folder and all its contents to the specified location.

The Basics Linking Files ln –s filename linkname – this will create symbolic link, or softlink. This acts very much like a shortcut file in a GUI pointing to the file or directory defined in filename and with the name defined in linkname

The Basics Permissions chmod or Change Mode is used to change the permissions on a file. These changes can be either adding or removing permissions. These permissions are split into 3 groups of 4

The Basics Permissions Read (r) Write (w) Executable (x)

Anyone who is not one of the above. (o) All users (a) The Basics Permissions Owner (u) Group (g) Anyone who is not one of the above. (o) All users (a)

The Basics Examples chmod u+rwx (gives the owner full control) Permissions Examples chmod u+rwx (gives the owner full control) chmod a+x ( gives all users execute permissions) chmod g-x (removes write permissions from the group) chmod a-w (removes write permissions from all)

The Basics Compressing Files and Folders You can compress your files and folders using tar / gzip and pigz. This is especially important for saving space on servers, or for reducing the overall size when copying the file to/from somewhere else.

The Basics Compressing tar cvzf nameofarchive.tar.gz c – create Compressing Files and Folders Compressing tar cvzf nameofarchive.tar.gz c – create v – verbose output z – filter the archive through gzip f – use the following name for the archive

The Basics Extracting tar xvzf nameofarchive.tar.gz x – extract Compressing Files and Folders Extracting tar xvzf nameofarchive.tar.gz x – extract v – verbose output z – filter the archive through gzip f – use the following name for the archive

The Basics Text Editors nano Nano is a text editing program similar to notepad/word. You start the editor with the simple command nano. If you want to open an existing file then it is nano filename When the program is running you should be presented with a screen looking something like this.

The Basics Text Editors

The Basics Text Editors Using the shortcuts listed at the bottom of the screen you can navigate around the file. To save and close the text file when you are done press Ctrl+X

Wildcards, auto completes, command history, quick recall… The Basics Wildcards, auto completes, command history, quick recall… Could do with some words of advice/caution when using 'rm', especially with wildcards. e.g. take extra care when deleting relative paths, even the in the current dir, in case you are not where you think you are. Use 'pwd' to check if necessary. Also, the carpenter's rule .... "measure twice, cut once" ... check your command, flags and paths twice before you hit the enter key.

The Basics When searching for files or directories with similar characters or strings in their names you can use one of two wildcards * and ? ? is used to match a single character * is used to match multiple characters When combining these commands with flags you are able to perform many different functions. A prime example would be the rm flag allowing you to delete multiple files and directories with a similar name. When typing in commands and you need to insert a file name you can increase the speed and accuracy by using the tab key to autocomplete. This works best when you are using highly unique filenames, for less unique file names it will only partially complete the file name, up to the point it no longer becomes unique The up and down arrow keys will recall previously typed commands and the left and right keys will allow you to edit them. The history command will also allow you to see a list of previously typed commands. Could do with some words of advice/caution when using 'rm', especially with wildcards. e.g. take extra care when deleting relative paths, even the in the current dir, in case you are not where you think you are. Use 'pwd' to check if necessary. Also, the carpenter's rule .... "measure twice, cut once" ... check your command, flags and paths twice before you hit the enter key.

The Summary Linux is not scary, it’s just taking you out of your comfort zone of GUI based operating systems. The Linux community is superb and there are thousands upon thousands of helpful guides, forums and users out there willing to share knowledge and help the new Linux user.

The Summary

Image description Credit: photographer