Linux Bash Shell Cheat Sheet

Similar documents
Unix Sampler. PEOPLE whoami id who

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

Introduction to Mac OS X

UNIX / Linux commands Basic level. Magali COTTEVIEILLE - September 2009

USEFUL UNIX COMMANDS

Basic Linux & Package Management. Original slides from GTFO Security

Command Line - Part 1

An Introduction to the Linux Command Shell For Beginners

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Tutorial 0A Programming on the command line

A UNIX/Linux in a nutshell

Thirty Useful Unix Commands

Training Day : Linux

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Command Line Crash Course For Unix

INASP: Effective Network Management Workshops

Open Source Computational Fluid Dynamics

ICS 351: Today's plan

Cygwin command line windows. Get that Linux feeling - on Windows

Command-Line Operations : The Shell. Don't fear the command line...

Linux System Administration on Red Hat

Partek Flow Installation Guide

Backup of ESXi Virtual Machines using Affa

Tutorial Guide to the IS Unix Service

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX)

Hands-On UNIX Exercise:

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

Linux+ Guide to Linux Certification, Third Edition. Chapter 11 Compression, System Backup, and Software Installation

UNIX Tutorial for Beginners

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

CPSC 2800 Linux Hands-on Lab #7 on Linux Utilities. Project 7-1

Attix5 Pro Server Edition

AN INTRODUCTION TO UNIX

Linux Overview. Local facilities. Linux commands. The vi (gvim) editor

New Lab Intro to KDE Terminal Konsole

Installation Guide for WebSphere Application Server (WAS) and its Fix Packs on AIX V5.3L

L01 Introduction to the Unix OS

Cassandra Installation over Ubuntu 1. Installing VMware player:

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

PMOD Installation on Linux Systems

HP-UX Essentials and Shell Programming Course Summary

CS197U: A Hands on Introduction to Unix

Hadoop Installation MapReduce Examples Jake Karnes

Recommended File System Ownership and Privileges

Unix Scripts and Job Scheduling

ULTEO OPEN VIRTUAL DESKTOP V4.0

A Crash Course on UNIX

Setting up PostgreSQL

Installing IBM Websphere Application Server 7 and 8 on OS4 Enterprise Linux

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger

Partitioning. Files on the Hard Drive. Administration of Operating Systems DO2003. Partition = Binder with index. Write file = Insert document

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on:

OpenGeo Suite for Linux Release 3.0

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Procedure to Create and Duplicate Master LiveUSB Stick

SEO - Access Logs After Excel Fails...

Using Secure4Audit in an IRIX 6.5 Environment

Hadoop Basics with InfoSphere BigInsights

UNIX (LINUX) PRACTICAL 1 INTRODUCTION

Configuring MailArchiva with Insight Server

Open Source, Incremental Backup for Windows, Step By Step. Tom Scott BarCampLondon2, 17/2/07

Introduction to Operating Systems

Computing Service G72. File Transfer Using SCP, SFTP or FTP. many leaflets can be found at:

Unix/Linux Forensics 1

QUICK START BASIC LINUX AND G++ COMMANDS. Prepared By: Pn. Azura Bt Ishak

CS 103 Lab Linux and Virtual Machines

CS Unix Tools & Scripting Lecture 9 Shell Scripting

Do it Yourself System Administration

How to install PowerChute Network Shutdown on VMware ESXi 3.5, 4.0 and 4.1

BIGPOND ONLINE STORAGE USER GUIDE Issue August 2005

Unix the Bare Minimum

GeBro-BACKUP. Die Online-Datensicherung. Manual Pro Backup Client on a NAS

Red Hat Certifications: Red Hat Certified System Administrator (RHCSA)

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Integrating Apache Web Server with Tomcat Application Server

Installing Virtual Coordinator (VC) in Linux Systems that use RPM (Red Hat, Fedora, CentOS) Document # 15807A1-103 Date: Aug 06, 2012

Linux System Administration. System Administration Tasks

SNMP Upgrade Procedure for NV Transmitters

The Linux Operating System and Linux-Related Issues

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS)

LSN 10 Linux Overview

CPE111 COMPUTER EXPLORATION

User Manual - Help Utility Download MMPCT. (Mission Mode Project Commercial Taxes) User Manual Help-Utility

stub (Private Switch) Solaris 11 Operating Environment In the Solaris 11 Operating Environment, four zones are created namely:

How To Use The Librepo Software On A Linux Computer (For Free)

RecoveryVault Express Client User Manual

VERSION 9.02 INSTALLATION GUIDE.

webmethods Certificate Toolkit

NERSP: Saving File Space and Reducing File Storage Charges

How to upload - copy PowerChute Network Shutdown installation files to VMware VMA from a PC

Online Backup Linux Client User Manual

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics:

Installing Proview on an Windows XP machine

Lab 1 Beginning C Program

Online Backup Client User Manual

Setting up Radmind For an OSX Public Lab

Using Dedicated Servers from the game

Transcription:

freeworld.posterous.com Linux Bash Shell Cheat Sheet (works with about every distribution, except for apt-get which is Ubuntu/Debian exclusive) Legend: Everything in <> is to be replaced, ex: <filename> --> ilovepeanuts.txt Don't include the '=' in your commands '..' means that more than one file can be affected with only one command ex: rm file.txt file2.txt movie.mov....

Basic Terminal Shortcuts Basic file manipulation CTRL L = Clear the terminal cat <filename> = show content of file CTRL D = Logout (less, more) SHIFT Page Up/Down = Go up/down the terminal head = from the top CTRL A = Cursor to start of line -n <#oflines> <filename> CTRL E = Cursor the end of line CTRL U = Delete left of the cursor tail = from the bottom CTRL K = Delete right of the cursor -n <#oflines> <filename> CTRL W = Delete word on the left CTRL Y = Paste (after CTRL U,K or W) mkdir = create new folder TAB = auto completion of file or command mkdir mystuff.. CTRL R = reverse search history mkdir mystuff/pictures/..!! = repeat last command CTRL Z = stops the current command (resume with fg in foreground or bg in background) cp image.jpg newimage.jpg = copy and rename a file Basic Terminal Navigation ls -a = list all files and folders ls <foldername> = list files in folder ls -lh = Detailed list, Human readable ls -l *.jpg = list jpeg files only ls -lh <filename> = Result for file only cd <foldername> = change directory if folder name has spaces use cd / = go to root cd.. = go up one folder, tip:../../../ cp image.jpg <foldername>/ = copy to folder cp image.jpg folder/sameimagenewname.jpg cp -R stuff otherstuff = copy and rename a folder cp *.txt stuff/ = copy all of *<file type> to folder mv file.txt Documents/ = move file to a folder mv <foldername> <foldername2> = move folder in folder mv filename.txt filename2.txt = rename file mv <filename> stuff/newfilename mv <foldername>/.. = move folder up in hierarchy rm <filename>.. = delete file (s) rm -i <filename>.. = ask for confirmation each file du -h: Disk usage of folders, human readable rm -f <filename> = force deletion of a file du -ah: files & folders, Human readable rm -r <foldername>/ = delete folder du -sh: only show disc usage of folders touch <filename> = create or update a file pwd = print working directory ln file1 file2 = physical link man <command> = shows manual (RTFM) ln -s file1 file2 = symbolic link

Researching Files The slow method (sometimes very slow): locate <text> = search the content of all the files locate <filename> = search for a file sudo updatedb = update database of files Extract, sort and filter data grep <sometext> <filename> = search for text in file -i = Doesn't consider uppercase words -I = exclude binary files grep -r <text> <foldername>/ = search for file names with occurrence of the text find = the best file search tool (fast) With regular expressions: find -name <filename> find -name text = search for files who start with the word text grep -E ^<text> <filename> = search start of lines find -name *text = end with the word text grep -E <0-4> <filename> =shows lines containing numbers 0-4 Advanced Search: grep -E <a-za-z> <filename> = retrieve all lines with alphabetical letters Search from file Size (in ~) find ~ -size +10M = search files bigger than.. (M,K,G) sort = sort the content of files sort <filename> = sort alphabetically Search from last access sort -o <file> <outputfile> = write result to a file find -name <filetype> -atime -5 ('-' = less than, '+' = more than and nothing = exactly) Search only files or directory s find -type d --> ex: find /var/log -name "syslog" -type d find -type f = files More info: man find, man locate sort -r <filename> = sort in reverse sort -R <filename> = sort randomly sort -n <filename> = sort numbers wc = word count wc <filename> = nbr of line, nbr of words, byte size -l (lines), -w (words), -c (byte size), -m (number of characters) cut = cut a part of a file -c --> ex: cut -c 2-5 names.txt (cut the characters 2 to 5 of each line) -d (delimiter) (-d & -f good for.csv files) -f (# of field to cut) more info: man cut, man sort, man grep

Time settings (continued) date = view & modify time (on your computer) crontab = execute a command regularly -e = modify the crontab View: -l = view current crontab date +%H --> If it's 9 am, then it will show 09 -r = delete you crontab date +%H:%M:%Ss = (hours, minutes, seconds) In crontab the syntax is %Y = years <Minutes> <Hours> <Day of month> <Day of week (0-6, Modify: 0 = Sunday)> <COMMAND> MMDDhhmmYYYY Month Day Hours Minutes Year ex, create the file movies.txt every day at 15:47: 47 15 * * * touch /home/bob/movies.txt sudo date 031423421997 = March 14 th 1997, 23:42 * * * * * --> every minute at 5:30 in the morning, from the 1 st to 15 th each month: Execute programs at another time 30 5 1-15 * * at midnight on Mondays, Wednesdays and Thursdays: use 'at' to execute programs in the future 0 0 * * 1,3,4 every two hours: Step 1, write in the terminal: at <timeofexecution> ENTER 0 */2 * * * ex --> at 16:45 or at 13:43 7/23/11 (to be more precise) every 10 minutes Monday to Friday: or after a certain delay: */10 * * * 1-5 at now +5 minutes (hours, days, weeks, months, years) Step 2: <ENTER COMMAND> ENTER repeat step 2 as many times you need Step 3: CTRL D to close input atq = show a list of jobs waiting to be executed atrm = delete a job n <x> ex (delete job #42) --> atrm 42 Execute programs in the background Add a '&' at the end of a command ex --> cp bigmoviefile.mp4 & nohup: ignores the HUP signal when closing the console (process will still run if the terminal is closed) ex --> nohup cp bigmoviefile.mp4 sleep = pause between commands jobs = know what is running in the background with ';' you can chain commands, ex: touch file; rm file you can make a pause between commands (minutes, hours, days) fg = put a background process to foreground ex --> touch file; sleep 10; rm file <-- 10 seconds ex: fg (process 1), f%2 (process 2) f%3,...

Process Management Create and modify user accounts w = who is logged on and what they are doing sudo adduser bob = root creates new user sudo passwd <AccountName> = change a user's password tload = graphic representation of system load average sudo deluser <AccountName> = delete an account (quit with CTRL C) addgroup friends = create a new user group ps = Static process list delgroup friends = delete a user group -ef --> ex: ps -ef less -ejh --> show process hierarchy usermod -g friends <Account> = add user to a group -u --> process's from current user usermod -g bob boby = change account name usermod -ag friends bob = add groups to a user withtop = Dynamic process list out loosing the ones he's already in While in top: q to close top File Permissions h to show the help k to kill a process chown = change the owner of a file CTRL C to top a current terminal process kill = kill a process You need the PID # of the process ps -u <AccountName> grep <Application> Then kill <PID>...... kill -9 <PID> = violent kill killall = kill multiple process's ex --> killall locate extras: sudo halt <-- to close computer sudo reboot <-- to reboot ex --> chown bob hello.txt chown user:bob report.txt = changes the user owning report.txt to 'user' and the group owning it to 'bob' -R = recursively affect all the sub folders ex --> chown -R bob:bob /home/daniel chmod = modify user access/permission simple way u = user g = group o = other d = directory (if element is a directory) l = link (if element is a file link) r = read (read permissions) w = write (write permissions) x = execute (only useful for scripts and programs)

File Permissions (continued) '+' means add a right '-' means delete a right '=' means affect a right ex --> chmod g+w somefile.txt (add to current group the right to modify somefile.txt) more info: man chmod Flow redirection Flow Redirection (continued) terminal output: Alex Cinema Code Game Ubuntu Another example --> wc -m << END Chain commands Redirect results of commands: '>' at the end of a command to redirect the result to a file ex --> ps -ejh > process.txt '>>' to redirect the result to the end of a file Redirect errors: '2>' at the end of the command to redirect the result to a file ex --> cut -d, -f 1 file.csv > file 2> errors.log '2>&1' to redirect the errors the same way as the standard output ' ' at the end of a command to enter another one ex --> du sort -nr less Archive and compress data Archive and compress data the long way: Step 1, put all the files you want to compress in the same folder: ex --> mv *.txt folder/ Step 2, Create the tar file: tar -cvf my_archive.tar folder/ Read progressively from the keyboard -c : creates a.tar archive -v : tells you what is happening (verbose) <Command> << <wordtoterminateinput> -f : assembles the archive into one file ex --> sort << END <-- This can be anything you want > Hello Step 3.1, create gzip file (most current): > Alex gzip my_archive.tar > Cinema to decompress: gunzip my_archive.tar.gz > Game > Code Step 3.2, or create a bzip2 file (more powerful but slow): > Ubuntu bzip2 my_archive.tar > END to decompress: bunzip2 my_archive.tar.bz2

Archive and compress data (continued) Installing software step 4, to decompress the.tar file: tar -xvf archive.tar archive.tar Archive and compress data the fast way: gzip: tar -zcvf my_archive.tar.gz folder/ decompress: tar -zcvf my_archive.tar.gz Documents/ bzip2: tar -jcvf my_archive.tar.gz folder/ decompress: tar -jxvf archive.tar.bz2 Documents/ When software is available in the repositories: sudo apt-get install <nameofsoftware> ex--> sudo apt-get install aptitude If you download it from the Internets in.gz format (or bz2) - Compiling from source Step 1, create a folder to place the file: mkdir /home/username/src <-- then cd to it Step 2, with 'ls' verify that the file is there (if not, mv../file.tar.gz /home/username/src/) Show the content of.tar,.gz or.bz2 without decompressing it: Step 3, decompress the file (if.zip: unzip <file>) gzip: <-- gzip -ztf archive.tar.gz Step 4, use 'ls', you should see a new directory bzip2: Step 5, cd to the new directory bzip2 -jtf archive.tar.bz2 Step 6.1, use ls to verify you have an INSTALL file, tar: then: more INSTALL tar -tf archive.tar If you don't have an INSTALL file: Step 6.2, execute./configure <-- creates a makefile tar extra: Step 6.2.1, run make <-- builds application binaries tar -rvf archive.tar file.txt = add a file to the.tar Step 6.2.2 : switch to root --> su Step 6.2.3 : make install <-- installs the software You can also directly compress a single file and view the file Step 7, read the readme file without decompressing: Step 1, use gzip or bzip2 to compress the file: gzip numbers.txt Step 2, view the file without decompressing it: zcat = view the entire file in the console (same as cat) zmore = view one screen at a time the content of the file (same as more) zless = view one line of the file at a time (same as less)