UNIX 101 - ITaP Research Computing

1y ago
7 Views
2 Downloads
1.46 MB
73 Pages
Last View : 29d ago
Last Download : 3m ago
Upload by : Casen Newsome
Transcription

UNIX 101Gladys K. Andino, Daniel Dietz, Steve Kelley, Boyu Zhang, Xiao ZhuResearch Computing, ITaPPurdue UniversityContents1 LOGGING IN52 BASIC UNIX62.1UNIX BASICS REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62.2FILES AND DIRECTORIES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62.2.1FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62.2.2DIRECTORIES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72.2.3FILE PATHS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72.2.4DIRECTORY STRUCTURE AND FILESYSTEMS . . . . . . . . . . . . . . . . . . . . . . . . . . .82.3GETTING STARTED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82.4NAVIGATION SHELL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92.5MAKING DIRECTORIES2.6COPYING FILES AND DIRECTORIES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.7MOVING DIRECTORIES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.8CREATING AND EDITING FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.9VIEWING CONTENTS OF THE FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.9.1less . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.9.2more . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.9.3cat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.9.4head . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.9.5tail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

2.9.6grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.10 DELETING FILES AND DIRECTORIES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.10.1 rmdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.10.2 rm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.11 FILE TRANSFER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.11.1 SAMBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.11.2 SCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 ADVANCED FILE MANIPULATION COMMANDS3.13.23.33.422FILE PERMISSIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.1.1chmod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.1.2chown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.1.3chgrp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25COMPRESSING FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.2.1tar ARCHIVING/EXTRACTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.2.2gzip COMPRESSION/EXTRACTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.2.3zip ARCHIVING/EXTRACTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27BACKING UP FILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.3.1ACCOUNTS AND DIRECTORIES ON FORTRESS . . . . . . . . . . . . . . . . . . . . . . . . . . . 283.3.2USING hsi AND hatr TO ARCHIVE/EXTRACT FILES FROM FORTRESS . . . . . . . . . . . . . 28PIPES AND REDIRECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 INTRODUCTION TO BASH PROGRAMMING304.1MAKE A SCRIPT EXECUTABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.2A SIMPLE SHELL SCRIPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.3SIMPLE VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.4COMMAND LINE ARGUMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.5SCRIPT SUMMARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322

5 REGULAR EXPRESSIONS AND ADVANCED COMMANDS5.133REGULAR EXPRESSIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.1.1INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.1.2SUPER SIMPLE EXPRESSIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.1.3CHARACTER GROUPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.1.4QUANTIFIERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365.1.5CHARACTER CLASSES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385.1.6NEGATION AND ESCAPING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395.1.7ANCHORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395.1.8GROUPING AND CAPTURING5.1.9PUTTING IT ALL TOGETHER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405.1.10 REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.25.3TEXT SCULPTING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.2.1grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.2.2awk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.2.3sed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47ADVANCED COMMANDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.3.1COUNTING LINES WITH ’wc’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.3.2EXTRACTING SECTIONS FROM EACH LINE OF INPUT WITH ’cut’ . . . . . . . . . . . . . 495.3.3SORTING FILES WITH ’sort’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.3.4SELECTING UNIQUE LINES IN A SORTED FILE WITH ’uniq’ . . . . . . . . . . . . . . . . . 515.3.5ADVANCED PIPES AND REDIRECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525.3.6LOOPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535.3.7COMMAND SUBSTITUTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546 BASH PROGRAMMING546.1SHELL BASICS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546.2SHELL TYPES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566.3VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576.3.1VARIABLE TYPES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576.3.2CREATING VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586.3.3EXPORTING VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583

6.46.56.66.76.3.4SPECIAL VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586.3.5CONSTATN VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596.3.6ARRAY VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60OPERATIONS ON VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616.4.1STRING OPERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616.4.2ARITHMETIC OPERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63QUOTING CHARACTERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646.5.1ESCAPE CHARACTERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646.5.2SINGLE QUOTES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656.5.3BACKTICKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656.5.4DOUBLE QUOTES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65CONDITIONALS AND LOOPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666.6.1test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666.6.2if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676.6.3for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686.6.4while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696.6.5break, continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69INPUT AND OUTPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706.7.1STDIN, STDOUT, AND STDERR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706.7.2FILE I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727 ACKNOWLEDGEMENTS73WHAT WE WILL LEARNThis is an introduction to using UNIX systems. In this workshop we will be talking about UNIX concepts, tools, andtechniques for effectively using UNIX systems. We will be using Purdue systems to demonstrate these topics, but the skillslearned are applicable for any UNIX system.PREREQUISITESInformation Technology at Purdue (ITaP) provides shared cluster computing infrastructures for researchers at Purdue.There are many computing clusters that are available for Purdue faculty and students. The Radon cluster will be usedduring today’s workshop.4

To start using the Radon cluster you will need an account. All workshop attendees will have their account set up beforethe workshop. They can use their Purdue Career Account username and password to log in.1LOGGING INWe will be using the Radon cluster: https://www.rcac.purdue.edu/compute/radon/You can log onto its front-end/job-submission system (radon.rcac.purdue.edu) using your Purdue Career Account login andpassword. Logging into Radon requires an SSH client if you are using Windows, but Mac/Linux have these built into theirOS. There are several Windows SSH clients available for download.Microsoft Windows: PuTTY is an extremely small download of a free, full-featured SSH client. SecureCRT is a commercial SSH client which is freely available to Purdue students, faculty, and staff with a Purduecareer account. As an exercise we will download PuTTY and log in to the cluster1. Use Google to search for the word “putty”2. Click the PuTTY Download Page3. Download putty.exe4. Wait for the download to finish then double click putty.exe5. In the “Host Name” box type radon.rcac.purdue.edu6. Click YES when the program asks if you want to cache the security key7. Use your career account credentials to log inMac OS X: The SSH command is pre-installed. You may start a local terminal window from ”Applications Utilities”. Log in using ssh username@radon.rcac.purdue.edu, where username is your Purdue Career Account login.Linux / Solaris / AIX / HP-UX / Unix: The ssh command is pre-installed.5

2BASIC UNIXUNIX is a text oriented operating system that has been around since the 70s, and is the primary operating system used athigh performance computing facilities, as well as underlying the Mac OSX graphical operating system. You interact withthe computer via a shell.A shell is a program that inputs Unix commands from the keyboard and relays them to the Unix system for execution.Shells typically include various shortcuts for users to use in stating their commands, and also a programming feature, inwhich users can make programs out of sets of their commands.There are several UNIX shells, but the most common is probably bash (Bourne again shell), but differences between shellsare not very important unless you are going to write shell scripts to automate your work. In this workshop we are onlyintroducing the smallest possible set of commands needed to work in a UNIX environment – some of the references belowgive much more detail and an introduction to shell scripting.2.1UNIX BASICS REFERENCES Unix tutorial for beginners, http://www.ee.surrey.ac.uk/Teaching/Unix Unix tutorial, http://evomics.org/learning/unix-tutorial Introduction to Unix, http://www.doc.ic.ac.uk/ wjk/UnixIntro A quick introduction to Unix, http://en.wikibooks.org/wiki/A Quick Introduction to Unix2.2FILES AND DIRECTORIESFiles and directories are two important constructs in UNIX (and most operating systems). They contain your documents,images, code, programs, OS, etc. Everything in UNIX is built on files and directories.filesystem is a collection of files and directories stored on a single physical device. These are often called “drives” inWindows. The terms are interchangeable but filesystem is typically used in UNIX.As an example, we will get our first look at files and directories by copying the workshop files. Type the command:Let’s run our first command and grab workshop files. Type the command: cp -r /depot/itap/unix101-2016 .Please note that the dot (.) exists at the end of the command. We will discuss files, directories, and the details of thiscommand in more detail later.2.2.1FILESFiles simply store information. There are two basic types of files: Text (documents, code)6

Binary (images, executables)Every file has metadata associated with it. The metadata contains the name, timestamps and permissions.2.2.2DIRECTORIESDirectories are collections of files and directories. They are analogous and interchangeable with “folders” typically usedin Windows. Directories and folders are the same thing but the term “directories” is typically used in UNIX.Much like files, directories have metadata associated with them. Similarly, the metadata contains the name, timestamps,and permissions.2.2.3FILE PATHSIn UNIX all files and directories have a path. The “path” of directories you must follow in order to find the file. Directoriesin the path to a file are separated by a / in sername/file.txtFile extensions don’t matter in UNIX. Unlike Windows, UNIX systems do not look at file extension to determine file type.It is not a bad convention, however, to give your files appropriate file extensions to help you and others identify the filetype easily.File paths may be written as relative or absolute paths.Absolute paths are the paths to files starting at the root of the system. They begin with / to denote the path starts at theroot. They are a guaranteed way to get you to your files.Relative paths are the paths to files starting at your current location. You can indicate current directory with . (dot) andparent directory as . (dot dot). The path can break if you start in the wrong place, and thus, are relative paths.Some examples comparing relative and absolute paths, assuming current location is /home/ddietz:Relative ute /home/ddietz/file.txt7

2.2.4DIRECTORY STRUCTURE AND FILESYSTEMSIn UNIX the root of the system is /. Unfortunately, there is no strong analogy to this in Windows. In Windows you havedistinct filesystems (C:, D:, F:, etc.) representing distinct sets of files and directories.In UNIX all filesystems are all represented under /. Under here, filesystems may be mounted anywhere in the structure.On a simple UNIX system there may only be a single filesystem (/ then only contains a single filesystem), but on clustersand large systems there are multiple don//scratch/conte/2.3FilesystemRoot OS, single hard drive on login or compute nodeFilesystem with hundreds of hard disks, home directoriesLarge file system (couple terabytes) for research dataExtremely fast filesystem for working/temporary dataExtremely fast filesystem for working/temporary dataGETTING STARTEDThe data files required for this workshop are located in a public directory in the Research Data Depot. You need tohave this in your home directory before you start. You can copy the directory by a simple command given below (justreplace username with your Purdue career account). You need to first log into Radon, e.g. ssh username@radon.rcac.purdue.eduthen, follow the next steps:1. Type in the following: cp -r /depot/itap/unix101-2016 username/BACKUP2. Press enter.a. Note: the command is case sensitive.3. Once your cursor (command prompt) comes back to the original position, type: ls (will explain this command later)4. Press enter5. You should see now: lsunix101-2016 BACKUP8

2.4NAVIGATION SHELLThis section will introduce you to some basic file/directory navigation and manipulation techniques.Which directory/location are you in?pwd (print working directory) command: prints working directoryType in the following: pwdNow you should see /home/username/, where username should be your Purdue career account.pwd command returns you the present working directory, this means, you are now working in the username directory,which is located in home directory. The directory that you will be in after logging in is your home directory.Note: for further reference you can also avoid writing the full path to your home directory by using ( ) tilde mark in frontof your username. username same as /home/usernamePresent directory is represented as . (dot) and parent directory is represented as . (dot dot).What files are here?ls command: list files in current directory-l-h-t-along listing, includes file date and sizeshow file sizes in human readable termsshow the newest files firstincludes hidden files, parent and current directoriesType in the following: lsBACKUP unix101-2016 ls -lhtdrwxr-xr-x 5 gandino entm 201 Feb 16 17:05 BACKUPdrwxr-xr-x 5 gandino entm 201 Feb 16 17:02 unix101-2016How do I move from one directory to another directory?cd (change directory) command: jump from one directory to another.Type in the following:9

cd unix101-2016/basic commands/ ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K Feb-rw-r----- 1 gandino entm 46M Feb-rwxr-xr-x 1 gandino entm 1.3G Feb-rwxr-xr-x 1 gandino entm 197M Feb-rwxr-xr-x 1 gandino entm 1.3G xtsequences.fastaSP R1.fastqSP R1.listSP R2.fastqChanges your present location to the parent directory using:cd .The directory which is up one level in the directory tree can be referred to as .Type in the following: cd . lsbasic commands protein scripts ShakespeareFew more ways to do the same thing: cd unix101-2016/basic commands/ ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K Feb 16 17:02-rw-r----- 1 gandino entm 46M Feb 17 13:59-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02-rwxr-xr-x 1 gandino entm 197M Feb 16 17:02-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02 cd # going back to the home directory lsBACKUP unix101-2016basic-unix.txtsequences.fastaSP R1.fastqSP R1.listSP R2.fastq cd unix101-2016/basic commands/ ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K Feb 16 17:02-rw-r----- 1 gandino entm 46M Feb 17 13:59-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02-rwxr-xr-x 1 gandino entm 197M Feb 16 17:02-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02 cd /home/gandino/ # going back to the home lsBACKUP unix101-2016basic-unix.txtsequences.fastaSP R1.fastqSP R1.listSP R2.fastqdirectory10

2.5MAKING DIRECTORIESHow to create a directory?mkdir command: (make directory) can be used.Type in the followings: unix101-2016/basic commands/ ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K-rw-r----- 1 gandino entm 46M-rwxr-xr-x 1 gandino entm 1.3G-rwxr-xr-x 1 gandino entm 197M-rwxr-xr-x 1 gandino entm 7:02basic-unix.txtsequences.fastaSP R1.fastqSP R1.listSP R2.fastq mkdir NEW DIRECTORY ls -lhtotal 3.4G-rw-r--r-- 1 gandino entmdrwxr-xr-x 2 gandino entm-rw-r----- 1 gandino entm-rwxr-xr-x 1 gandino entm-rwxr-xr-x 1 gandino entm-rwxr-xr-x 1 gandino 7:0217:0217:02basic-unix.txtNEW DIRECTORYsequences.fastaSP R1.fastqSP R1.listSP R2.fastq2.1K046M1.3G197M1.3GA good practice in UNIX is to not use spaces in your directory name or any other special characters beside “ ” or “-”.We’ll begin to see why over the next couple of chapters.Alternatively, you can also directly specify the path where you want to create your new folder, e.g.,Note: just replace username with your Purdue career account.mkdir /home/username/basic commands/NEW DIRECTORY2.6COPYING FILES AND DIRECTORIESHow to copy a file or a directory?cp (copy) command: copy a file. When using this command you have to provide both the source file and destination file.cp [OPTIONS] SOURCE DESTINATIONType in the following:11

pwd/home/gandino/unix101-2016/basic commands/ cd unix101-2016/NEW DIRECTORY ls# Note: this directory should be empty! pwd/home/gandino/unix101-2016/basic commands/NEW DIRECTORY cp ./basic-unix.txt . lsbasic-unix.txYou can also specify the absolute path of the source and/or destination file. To know more about any command you canuse man command, which opens the “manual” of the command you specify, e.g., man cpThis opens the manual for the cp command. Take a look at the manual of the cp command (use arrow keys to move topor bottom of the page). To exit, press ‘q’.OPTIONS are optional parameters that can be used to accomplish more from the same command e.g. by using option -iwith the regular cp command, you can always make sure that you are not overwriting the existing file while copying.When copying directories make sure to use the option -R, -r, or --recursive to copy directories recursively, what thismeans is that every file and subdirectories inside that directory will be copied.Type in the following: cp -R ./././BACKUP BACKUP FILES ls -lhtotal 28Kdrwxr-xr-x 6 gandino entm 109 Feb 18 16:35 BACKUP FILES-rw-r--r-- 1 gandino entm 2.1K Feb 18 16:30 basic-unix.txt2.7MOVING DIRECTORIESHow to move a file or a directory?mv (move) command is used to move a file or a directory. Like the cp command, you need to provide both the source fileand destination file.mv SOURCE DESTINATIONAbsolute path also works fine. Some of the options used by cp command also work with mv command.Type in the following:12

pwd/home/gandino/unix101-2016/basic commands/NEW DIRECTORY cd . pwd/home/gandino/unix101-2016/basic commands/ mv NEW DIRECTORY/basic-unix.txt . ls NEW DIRECTORY/BACKUP FILESmv can also be used to rename files and directoriesmv OLDNAME NEWNAME pwd/home/gandino/unix101-2016/basic commands/ mv basic-unix.txt new basic-unix.txt ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K Feb 16 17:02drwxr-xr-x 2 gandino entm 30Feb 18 17:19-rw-r----- 1 gandino entm 46M Feb 17 13:59-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02-rwxr-xr-x 1 gandino entm 197M Feb 16 17:02-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:022.8new basic-unix.txtNEW DIRECTORYsequences.fastaSP R1.fastqSP R1.listSP R2.fastqCREATING AND EDITING FILESHow to create and edit a file on the server itself?nano new fileThis text editor lets you edit a file. While you can prepare a file on your local computer or laptop and transfer it to theserver, it is usually more convenient to create and edit the file on the server itself. There are many editors available (forinstance vi, emacs, pico and nano), if you are familiar with an editor, feel free to use the one you are already familiarwith.If you aren’t familiar with a UNIX editor, we recommend that you use nano. An advantage of nano are that the commandsto “Exit” the editor and “WriteOut” a file are shown at the bottom of the screen (ˆ indicates Ctrl should be held downwhile typing the letter).The basics of nano are simple (see figure): type nano at the command prompt to start the editor type your commands into the screen move around with the arrow keys if necessary13

save your file with the ˆo key, and provide a name for the file quit the editor with ˆxHow to create and edit a file using Notepad ?Notepad is a text editor and source code editor for use with Microsoft Windows. Notepad supports tabbed editing,which allows working with multiple open files in a single window. It is also an open source editor with nice features (likesyntax highlighting).14

2.9VIEWING CONTENTS OF THE FILESThere are various commands to print the contents of the file in bash. Most of these commands are often used in specificcontexts. All these commands when executed with filenames display the contents on the screen. Most common ones areless, more, cat, head and tail.2.9.1less pwd/home/gandino/unix101-2016/basic commands/ ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K Feb 16 17:02drwxr-xr-x 2 gandino entm 30Feb 18 17:19-rw-r----- 1 gandino entm 46M Feb 17 13:59-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02-rwxr-xr-x 1 gandino entm 197M Feb 16 17:02-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02 less new basic-unix.txtnew basic-unix.txtNEW DIRECTORYsequences.fastaSP R1.fastqSP R1.listSP R2.fastq15

Displays file contents on the screen with line scrolling (to scroll you can use ‘arrow’ keys, ‘PgUp/PgDn’ keys, ‘space bar’ or‘Enter’ key). When you are done press ‘q’ to exit.You can search a pattern inside of the screen using /pattern. Try this: /UNIX16

2.9.2moreLike less command, also, displays file’s content on the screen with line scrolling but uses ‘space bar’ or ‘Enter’ key toscroll. When you are done press ‘q’ to exit.more FILENAME2.9.3catThis is the simplest form of displaying contents. It catalogs the entire contents of the file on the screen. In case of largefiles, entire file will scroll on the screen without pausing.cat FILENAME2.9.4headDisplays only the starting lines of a file. The default is first ten lines. But, any number of lines can be displayed using -noption (followed by required number of lines).17

head FILENAME2.9.5tailSimilar to head, but displays the last 10 lines. -n option can be used to change this. More information about any of thesecommands can be found in the man pages.tail FILNAME2.9.6grepgrep is one of the most commonly used commands in UNIX and it is commonly used to filter a file/input, line by line,against a pattern (e.g., to print each line of a file which contains a match for pattern).General syntax:grep [OPTIONS] PATTERN FILENAME(if given no file, it reads from the standard input)Like any other command there are various options available for this command. Most useful options include:pattern–i-l-c-wignore case for the pattern matching.lists the file names containing the pattern (instead of match)counts the number of matches for a patternforces the pattern to match an entire wordSome typical scenarios to use grep: Extracting specific line(s) from the simulation output Stripping header/footer/comments lines from an input file Selecting files of interest (with -l) Counting number of occurrences of a string or pattern in a file (with –c)A handy trick for bioinformaticians: how many sequences are in a FASTA-formatted file? By definition, each sequencerecord in a FASTA file has one line of description that always starts with , followed by multiple lines of sequence itself.Each sequence record ends when the next line starting with appears:So counting number of sequences in FASTA-file is as easy asgrep -c ’ˆ ’ FILENAME pwd/home/gandino/unix101-2016/basic commands/ grep -c ' ' sequences.fasta3192518

2.10DELETING FILES AND DIRECTORIESHow to remove a file or a directory?2.10.1rmdirThe rmdir (remove directory) command is used to delete directories from the system. rmdir DIRECTORYThe directory should be empty before you use the rmdir command.2.10.2rmrm(remove) command is used to delete directories or files from the system.rm FILESome useful options include:-r-frecursively delete filesdelete forcefully pwd/home/gandino/unix101-2016/basic commands/ ls -lhtotal 3.4G-rw-r--r-- 1 gandino entm 2.1K Feb 16 17:02drwxr-xr-x 2 gandino entm 30Feb 18 17:19-rw-r----- 1 gandino entm 46M Feb 17 13:59-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02-rwxr-xr-x 1 gandino entm 197M Feb 16 17:02-rwxr-xr-x 1 gandino entm 1.3G Feb 16 17:02new basic-unix.txtNEW DIRECTORYsequences.fastaSP R1.fastqSP R1.listSP R2.fastq rm NEW DIRECTORY/ # this directory it's not empty!rm: cannot remove NEW DIRECTORY/': Is a di

Linux / Solaris / AIX / HP-UX / Unix: The ssh command is pre-installed. 5. 2 BASIC UNIX UNIX is a text oriented operating system that has been around since the 70s, and is the primary operating system used at high performance computing facilities, as well as underlying the Mac OSX graphical operating system. You interact with

Related Documents:

Unix 101: Introduction to UNIX (i.e. Unix for Windows Users) Mark Kegel September 7, 2005 1 Introduction to UNIX (i.e. Unix for Windows Users) The cold hard truth · this course is NOT sponsored by the CS dept. · you will not receive any credit at all introduce ourselv

UNIX and POSIX APIs: The POSIX APIs, The UNIX and POSIX Development Environment, API Common Characteristics. UNIT – 2 6 Hours UNIX Files: File Types, The UNIX and POSIX File System, The UNIX and POSIX File Attributes, Inodes in UNIX

Unix was originally developed in 1969 by a group of AT&T employees Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs. There are various Unix variants available in the market. Solaris Unix, AIX, HP Unix and BSD are a few examples. Linux is also a flavor of Unix which is freely available.

This is a standard UNIX command interview question asked by everybody and I guess everybody knows its answer as well. By using nslookup command in UNIX, you can read more about Convert IP Address to hostname in Unix here. I hope this UNIX command interview questions and answers would be useful for quick glance before going for any UNIX or Java job interview.

UNIX Files: File Types, The UNIX and POSIX File System, The UNIX and POSIX File Attributes, Inodes in UNIX System V, Application Program Interface to Files, UNIX Kernel Support for Files, Relationship of C Stream Pointers and File Descriptors, Directory Files, Hard and Symbolic Links. UNIT – 3 7 Hours

UNIX operating system, we will try to place our observations in a wider context thanjustthe UNIXsystem or one particular version of the UNIX system. UNIX system security is neither better nor worse than that of other systems. Any system that provides the same facilities as the UNIX system will necessarily have similar hazards.

UNIX system services UNIX kernel in C computer SH The shell (sh) is a program (written in C) that interprets commands typed to it, and carries out the desired actions. The shell is that part of Unix that most users see. Therefore there is a mistaken belief that sh is Unix. sh is an applications program running under Unix

Piano 2019 & 2020 Piano 2019 & 2020 GRADE 1 THREE PIECES: one chosen by the candidate from each of the three Lists, A, B and C: COMPOSER PIECE / WORK / ARRANGER PUBLICATION (PUBLISHER) 1 Attwood Theme (from Theme and Variations, Sonatina No. 4 in D) Piano Exam Pieces 2019 & 2020, Grade 1 (ABRSM) 2 Duncombe Minuet in C (from First Book of Progressive Lessons) Piano Exam Pieces 2019 & 2020 .