Basics of UNIX

Total Page:16

File Type:pdf, Size:1020Kb

Basics of UNIX Basics of UNIX August 27, 2011 1 Connecting to a UNIX machine from {UNIX, Mac, Windows} See the file on bspace on connecting remotely to SCF. More generally, the department computing FAQs is the place to go for answers to questions about SCF. For questions not answered there, the SCF help page requests: “please report any problems regarding equipment or system software to the SCF staff by sending mail to ’trouble’ or by re- porting the problem directly to room 498/499. For information/questions on the use of application packages (e.g., R, SAS, Matlab), programming languages and libraries send mail to ’consult’. Questions/problems regarding accounts should be sent to ’manager’.” Note that for the purpose of this class, questions about application packages, languages, li- braries, etc. can be directed to me (not consult). 2 Files and directories 1. Files are stored in directories (aka folders) that are in a (inverted) directory tree, with “/” as the root of the tree 2. Where am I? > pwd 3. What’s in a directory? > ls > ls -a > ls -al 1 4. Moving around > cd /home/paciorek/teaching/243 > cd ~paciorek/teaching/243 > cd ~/teaching/243 > cd 243 # provided I am in ’teaching’ > cd .. > cd - 5. Copying and removing > cp > cp -r > cp -rp # preserves timestamps and other metainfo (VERY handy for tracing your workflows if you move files between machines) > mkdir > rm > rm -r > rm -rf # CAREFUL! To copy between machines, we can use scp, which has similar options to cp: > scp file.txt [email protected]:~/research/. > scp [email protected]:/data/file.txt ~/research/renamed.txt 6. File permissions: ls -al will show the permissions for the ’user’, ’group’, ’other’ • to allow a file to be executed as a program: > chmod ugo+x myProg # myProg should be compiled code or a shell script • to allow read and write access to all: > chmod ugo+rw code.q • to prevent write access: > chmod go-w myThesisCode.q 7. Compressing files 2 • the zip utility compresses in a format compatible with zip files for Windows: > zip files.zip a.txt b.txt c.txt • gzip is the standard in UNIX: > gzip a.txt b.txt c.txt # will create a.txt.gz, b.txt.gz, c.txt.gz • tar will nicely wrap up entire directories: > tar cvf files.tar myDirectory > tar cvfz files.tgz myDirectory • To unwrap a tarball > tar xvf files.tar > tar xvfz files.tgz • To peek into a zipped (text) file: > gzip -cd file.gz | less > zcat file.zip | less 3 A variety of UNIX tools/capabilities Many UNIX programs are small programs (tools, utilities) that can be combined to do complicated things. 1. For help on a UNIX program, including command-line utilities like ls, cp, etc. > man cp 2. What’s the path of an executable? > which R 3. Tools for remotely mounting the filesystem of a remote UNIX machine/filesystem • Samba protocol - see “How can I mount my home directory” on SCF Help Desk FAQs • MacFUSE • Linux: > cd; mkdir scf # create a directory as a mountpoint > sshfs bilbo.berkeley.edu: /home/paciorek/scf # mount the remote filesystem > fusermount -u ~/scf # to unmount 3 4. Cloud storage: Dropbox and other services will mirror directories on multiple machines and on their servers 5. Doing something at the UNIX command line from within R: > system(“ls -al”) 6. Editors • traditional UNIX: emacs, vi • Windows: WinEdt • Mac: Aquamacs Emacs • Be careful in Windows - file suffixes are often hidden • For statistical computing, we need an editor, not a word processor, because we’re going to be operating on files of code and data files, for which word processing formatting gets in the way. 7. Basic emacs: • emacs has special modes for different types of files: R code files, C code files, Latex files – it’s worth your time to figure out how to set this up on your machine for the kinds of files you often work on – For working with R, ESS (emacs speaks statistics) mode is helpful. This is built in to Aquamacs emacs. • To open emacs in the terminal window rather than as a new window, which is handy when tunneling the graphical emacs window is slow or impossible: > emacs -nw file.txt 8. Files that provide info about a UNIX machine: • /proc/meminfo • /proc/cpuinfo • /etc/issue • Example: how do I find out how many processors a machine has: > grep processor /proc/cpuinfo 9. There are (free) tools in UNIX to convert files between lots of formats (pdf, ps, html, latex, jpg). This is particularly handy when preparing figures for a publication. My computing tips page lists a number of these. 4 Table 1. Helpful emacs control sequences. Sequence Result C-x,C-c Close the file C-x,C-s Save the file C-x,C-w Save with a new name C-s Search ESC Get out of command buffer at bottom of screen C-a Go to beginning of line C-e Go to end of line C-k Delete the rest of the line from cursor forward C-space, then move to end of block Highlight a block of text C-w Remove the highlighted block, putting it in the kill buffer C-y (after using C-k or C-w) Paste from kill buffer (’y’ is for ’yank’) 5 The bash shell and UNIX utilities September 7, 2011 Sections with more advanced material that are not critical for those of you just getting started with UNIX are denoted (***). Note that it can be difficult to distinguish what is shell-specific and what is just part of UNIX. Some of the material here is not bash-specific but general to UNIX. Reference: Newham and Rosenblatt, Learning the bash Shell, 2nd ed. 1 Shell basics The shell is the interface between you and the UNIX operating system. When you are working in a terminal window (i.e., a window with the command line interface), you’re interacting with a shell. There are multiple shells (sh, bash, csh, tcsh, ksh). We’ll assume usage of bash, as this is the default for Mac OSX and on the SCF machines and is very common for Linux. 1. What shell am I using? > echo $SHELL 2. To change to bash on a one-time basis: > bash 3. To make it your default: > chsh /bin/bash /bin/bash should be whatever the path to the bash shell is, which you can figure out using which bash Shell commands can be saved in a file (with extension .sh) and this file can be executed as if it were a program. To run a shell script called file.sh, you would type ./file.sh. Note that if you just typed file.sh, the shell will generally have trouble finding the script and recognizing that it is executable. 1 2 Tab completion When working in the shell, it is often unnecessary to type out an entire command or file name, because of a feature known as tab completion. When you are entering a command or filename in the shell, you can, at any time, hit the tab key, and the shell will try to figure out how to complete the name of the command or filename you are typing. If there is only one command in the search path and you’re using tab completion with the first token of a line, then the shell will display its value and the cursor will be one space past the completed name. If there are multiple commands that match the partial name, the shell will display as much as it can. In this case, hitting tab twice will display a list of choices, and redisplay the partial command line for further editing. Similar behavior with regard to filenames occurs when tab completion is used on anything other than the first token of a command. Note that R does tab completion for objects (including functions) and filenames. 3 Command history By using the up and down arrows, you can scroll through commands that you have entered previ- ously. So if you want to rerun the same command, or fix a typo in a command you entered, just scroll up to it and hit enter to run it or edit the line and then hit enter. Note that you can use emacs-like control sequences (C-a, C-e, C-k) to navigate and delete characters, just as you can at the prompt in the shell usually. You can also rerun previous commands as follows: > !-n # runs the nth previous command > !xt # runs the last command that started with ’xt’ If you’re not sure what command you’re going to recall, you can append :p at the end of the text you type to do the recall, and the result will be printed, but not executed. For example: > !xt:p You can then use the up arrow key to bring back that statement for editing or execution. You can also search for commands by doing C-r and typing a string of characters to search for in the search history. You can hit return to submit, C-c to get out, or ESC to put the result on the regular command line for editing. 4 Basic UNIX utilities Table 1 shows some basic UNIX programs, which are sometimes referred to as filters. The general syntax for a UNIX program is 2 Table 1. UNIX utilities. Name What it does tail shows last few lines of a file less shows a file one screen at a time cat writes file to screen wc counts words and lines in a file grep finds patterns in files wget downloads files from the web sort sorts a file by line nl numbers lines in a file diff compares two files uniq removes repeated (sequential) rows cut extracts fields (columns) from a file > command -options argument1 argument2 ..
Recommended publications
  • Introduction to Command Line and Accessing Servers Remotely
    Introduction to command line and accessing servers remotely Marco Büchler, Emily Franzini, Greta Franzini, Maria Moritz eTRAP Research Group Göttingen Centre for Digital Humanities Institute of Computer Science Georg August University Göttingen, Germany DH Estonia 2015 - Text Reuse Hackathon 20. Oktober 2015 Who am I? • 2001/2 Head of Quality Assurance department in a software company • 2006 Diploma in Computer Science on big • scale co-occurrence analysis • 2007- Consultant for several SMEs in IT sector • 2008 Technical project management of eAQUA project • 2011 PI and project manager of eTRACES project • 2013 PhD in „Digital Humanities“ on Text Reuse • 2014- Head of Early Career Research Group eTRAP at Göttingen Centre for Digital Humanities DH Estonia 2015 - Text Reuse Hackathon 20. Oktober 2015 Agenda 1) Connecting to the server 2) Some command line introduction DH Estonia 2015 - Text Reuse Hackathon 20. Oktober 2015 Connecting to the server 1) Windows: Start Putty 2) Mac + Linux: Open a terminal 3) Connecting to server via ssh -l <login> 192.168.11.4 4) Enter password DH Estonia 2015 - Text Reuse Hackathon 20. Oktober 2015 Which folder am I on the server? Command: pwd (parent working directory) Usage: pwd <ENTER> Example: pwd <ENTER> DH Estonia 2015 - Text Reuse Hackathon 20. Oktober 2015 Which files and directories are contained in my pwd? Command: ls (list) Usage: ls -l <FOLDER> <ENTER> // list all files and directory one on each line ls -la <FOLDER> <ENTER> // show also hidden files ls -lh <FOLDER> <ENTER> // show e.g. files sizes in human- friendly version Example: ls -l <ENTER> ls -lh /home/mbuechler <ENTER> DH Estonia 2015 - Text Reuse Hackathon 20.
    [Show full text]
  • Download the Specification
    Internationalizing and Localizing Applications in Oracle Solaris Part No: E61053 November 2020 Internationalizing and Localizing Applications in Oracle Solaris Part No: E61053 Copyright © 2014, 2020, Oracle and/or its affiliates. License Restrictions Warranty/Consequential Damages Disclaimer This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. Warranty Disclaimer The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. Restricted Rights Notice If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial
    [Show full text]
  • Unix/Linux Command Reference
    Unix/Linux Command Reference .com File Commands System Info ls – directory listing date – show the current date and time ls -al – formatted listing with hidden files cal – show this month's calendar cd dir - change directory to dir uptime – show current uptime cd – change to home w – display who is online pwd – show current directory whoami – who you are logged in as mkdir dir – create a directory dir finger user – display information about user rm file – delete file uname -a – show kernel information rm -r dir – delete directory dir cat /proc/cpuinfo – cpu information rm -f file – force remove file cat /proc/meminfo – memory information rm -rf dir – force remove directory dir * man command – show the manual for command cp file1 file2 – copy file1 to file2 df – show disk usage cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it du – show directory space usage doesn't exist free – show memory and swap usage mv file1 file2 – rename or move file1 to file2 whereis app – show possible locations of app if file2 is an existing directory, moves file1 into which app – show which app will be run by default directory file2 ln -s file link – create symbolic link link to file Compression touch file – create or update file tar cf file.tar files – create a tar named cat > file – places standard input into file file.tar containing files more file – output the contents of file tar xf file.tar – extract the files from file.tar head file – output the first 10 lines of file tar czf file.tar.gz files – create a tar with tail file – output the last 10 lines
    [Show full text]
  • Linux Software User's Manual
    New Generation Systems (NGS) Linux Software User’s Manual Version 1.0, September 2019 www.moxa.com/product © 2019 Moxa Inc. All rights reserved. New Generation Systems (NGS) Linux Software User’s Manual The software described in this manual is furnished under a license agreement and may be used only in accordance with the terms of that agreement. Copyright Notice © 2019 Moxa Inc. All rights reserved. Trademarks The MOXA logo is a registered trademark of Moxa Inc. All other trademarks or registered marks in this manual belong to their respective manufacturers. Disclaimer Information in this document is subject to change without notice and does not represent a commitment on the part of Moxa. Moxa provides this document as is, without warranty of any kind, either expressed or implied, including, but not limited to, its particular purpose. Moxa reserves the right to make improvements and/or changes to this manual, or to the products and/or the programs described in this manual, at any time. Information provided in this manual is intended to be accurate and reliable. However, Moxa assumes no responsibility for its use, or for any infringements on the rights of third parties that may result from its use. This product might include unintentional technical or typographical errors. Changes are periodically made to the information herein to correct such errors, and these changes are incorporated into new editions of the publication. Technical Support Contact Information www.moxa.com/support Moxa Americas Moxa China (Shanghai office) Toll-free: 1-888-669-2872 Toll-free: 800-820-5036 Tel: +1-714-528-6777 Tel: +86-21-5258-9955 Fax: +1-714-528-6778 Fax: +86-21-5258-5505 Moxa Europe Moxa Asia-Pacific Tel: +49-89-3 70 03 99-0 Tel: +886-2-8919-1230 Fax: +49-89-3 70 03 99-99 Fax: +886-2-8919-1231 Moxa India Tel: +91-80-4172-9088 Fax: +91-80-4132-1045 Table of Contents 1.
    [Show full text]
  • Programming IBM PASE for I 7.1
    IBM IBM i Programming IBM PASE for i 7.1 IBM IBM i Programming IBM PASE for i 7.1 Note Before using this information and the product it supports, be sure to read the information in “Notices,” on page 71. This edition applies to IBM AIX 6 Technology Level 1 and to IBM i 7.1 (product number 5770-SS1) and to all subsequent releases and modifications until otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor does it run on CISC models. © Copyright IBM Corporation 2000, 2010. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents IBM PASE for i ............ 1 Using IBM PASE for i native methods from What's new for IBM i 7.1 .......... 1 Java ............... 28 PDF file for IBM PASE for i ......... 2 Working with environment variables .... 28 IBM PASE for i overview .......... 3 Calling IBM i programs and procedures from IBM PASE for i concepts ......... 3 your IBM PASE for i programs ....... 29 IBM PASE for i as a useful option for application Calling ILE procedures ........ 29 development ............. 4 Examples: Calling ILE procedures .... 31 Installing IBM PASE for i .......... 5 Calling IBM i programs from IBM PASE for i 37 Planning for IBM PASE for i ......... 6 Example: Calling IBM i programs from Preparing programs to run in IBM PASE for i ... 7 IBM PASE for i .......... 37 Analyzing program compatibility with IBM PASE Running IBM i commands from IBM PASE for for i ...............
    [Show full text]
  • Unix/Linux Command Reference
    Unix/Linux Command Reference .com File Commands System Info ls – directory listing date – show the current date and time ls -al – formatted listing with hidden files cal – show this month's calendar cd dir - change directory to dir uptime – show current uptime cd – change to home w – display who is online pwd – show current directory whoami – who you are logged in as mkdir dir – create a directory dir finger user – display information about user rm file – delete file uname -a – show kernel information rm -r dir – delete directory dir cat /proc/cpuinfo – cpu information rm -f file – force remove file cat /proc/meminfo – memory information rm -rf dir – force remove directory dir * man command – show the manual for command cp file1 file2 – copy file1 to file2 df – show disk usage cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it du – show directory space usage doesn't exist free – show memory and swap usage mv file1 file2 – rename or move file1 to file2 whereis app – show possible locations of app if file2 is an existing directory, moves file1 into which app – show which app will be run by default directory file2 ln -s file link – create symbolic link link to file Compression touch file – create or update file tar cf file.tar files – create a tar named cat > file – places standard input into file file.tar containing files more file – output the contents of file tar xf file.tar – extract the files from file.tar head file – output the first 10 lines of file tar czf file.tar.gz files – create a tar with tail file – output the last 10 lines
    [Show full text]
  • File System Design Approaches
    File System Design Approaches Dr. Brijender Kahanwal Department of Computer Science & Engineering Galaxy Global Group of Institutions Dinarpur, Ambala, Haryana, INDIA [email protected] Abstract—In this article, the file system development design The experience with file system development is limited approaches are discussed. The selection of the file system so the research served to identify the different techniques design approach is done according to the needs of the that can be used. The variety of file systems encountered developers what are the needed requirements and show what an active area of research file system specifications for the new design. It allowed us to identify development is. The file systems researched fell into one of where our proposal fitted in with relation to current and past file system development. Our experience with file system the following four categories: development is limited so the research served to identify the 1. The file system is developed in user space and runs as a different techniques that can be used. The variety of file user process. systems encountered show what an active area of research file 2. The file system is developed in the user space using system development is. The file systems may be from one of the FUSE (File system in USEr space) kernel module and two fundamental categories. In one category, the file system is runs as a user process. developed in user space and runs as a user process. Another 3. The file system is developed in the kernel and runs as a file system may be developed in the kernel space and runs as a privileged process.
    [Show full text]
  • The Linux Command Line
    The Linux Command Line Fifth Internet Edition William Shotts A LinuxCommand.org Book Copyright ©2008-2019, William E. Shotts, Jr. This work is licensed under the Creative Commons Attribution-Noncommercial-No De- rivative Works 3.0 United States License. To view a copy of this license, visit the link above or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042. A version of this book is also available in printed form, published by No Starch Press. Copies may be purchased wherever fine books are sold. No Starch Press also offers elec- tronic formats for popular e-readers. They can be reached at: https://www.nostarch.com. Linux® is the registered trademark of Linus Torvalds. All other trademarks belong to their respective owners. This book is part of the LinuxCommand.org project, a site for Linux education and advo- cacy devoted to helping users of legacy operating systems migrate into the future. You may contact the LinuxCommand.org project at http://linuxcommand.org. Release History Version Date Description 19.01A January 28, 2019 Fifth Internet Edition (Corrected TOC) 19.01 January 17, 2019 Fifth Internet Edition. 17.10 October 19, 2017 Fourth Internet Edition. 16.07 July 28, 2016 Third Internet Edition. 13.07 July 6, 2013 Second Internet Edition. 09.12 December 14, 2009 First Internet Edition. Table of Contents Introduction....................................................................................................xvi Why Use the Command Line?......................................................................................xvi
    [Show full text]
  • K15569543: Producing a TMM Diagnostic Core File
    K15569543: Producing a TMM diagnostic core file Support Solution Original Publication Date: Oct 22, 2019 Update Date: Aug 12, 2020 Details Description F5 Support may ask you to produce a Traffic Management Microkernel (TMM) core file on the BIG-IP system to establish the state of TMM process during an event. You should perform this task only when asked to do so by F5 Support. Important: The BIG-IP system will temporarily fail to process traffic as it recovers from TMM restarting, and devices configured as a high availability (HA) pair may fail over. Additionally, on platforms with a large memory capacity, the system will respond slowly while it writes several gigabytes of data to the disk and compresses the core file. This process may take several minutes to complete. When the core file compression is complete, the unit returns to normal operation and restarts the TMMs. Environment BIG-IP F5 Support has requested a TMM diagnostic core file Adequate amount of disk space for the diagnostic core file K14403: Maintaining disk space on the BIG-IP system Cause None Recommended Actions To produce a TMM diagnostic core file, perform the following: 1. Disable the watchdog process K13539: Disabling the watchdog process to perform a core dump (11.x - 15.x) 2. Log in to the BIG-IP command line 3. Determine which tmm processes are running on the system, enter the following command: ps ax | grep -i tmm Note: Most BIG-IP platforms are enabled with Clustered Multiprocessing (CMP) and run multiple TMM 3. instances. Example: If a system has two instances of tmm running, output appears similar to the following: 5736 ? S 0:00 runsv tmm 12325 ? S 0:00 /usr/bin/tmipsecd --tmmcount 12 12327 ? S 0:00 /etc/bigstart/scripts/tmm.start /var/run 12 6 0 0 --platform E101 -m -s 21853 16379 ? SLl 17:22 tmm.0 -T 6 --tmid 0 --npus 12 --platform E101 -m -s 21853 16380 ? SLl 17:31 tmm.6 -T 6 --tmid 6 --npus 12 --platform E101 -m -s 21853 17707 pts/0 S+ 0:00 grep -i tmm Note: In this example, the two tmm instances are tmm.0 and tmm.6 4.
    [Show full text]
  • Unix (And Linux)
    AWK....................................................................................................................................4 BC .....................................................................................................................................11 CHGRP .............................................................................................................................16 CHMOD.............................................................................................................................19 CHOWN ............................................................................................................................26 CP .....................................................................................................................................29 CRON................................................................................................................................34 CSH...................................................................................................................................36 CUT...................................................................................................................................71 DATE ................................................................................................................................75 DF .....................................................................................................................................79 DIFF ..................................................................................................................................84
    [Show full text]
  • Converting a Hebrew Code Page CP1255 to the UTF-8 Format
    LIBICONV – An Interface to Team Developer By Jean-Marc Gemperle Technical Support Engineer November, 2005 Abstract ..................................................................................... 3 Introduction............................................................................... 3 What Is LIBICONV?.................................................................... 4 Obtaining and Building LIBICONV for Win32.............................. 4 A DLL Interface to Team Developer............................................ 4 Team Developer ICONV Samples and Tests................................ 5 A Brief Description of the Application......................................... 6 Converting a Hebrew Code Page CP1255 to the UTF-8 Format................................................................................. 7 Converting the Generated UTF-8 Back to the CP1255 Hebrew Code Page .............................................................. 8 Chinese ISO-2022-CN-EXT to UTF-8 .................................... 9 ISO-8859-1 to DOS 437..................................................... 10 ISO-8859-1 to WINDOWS-1250 Cannot Convert ............... 11 ISO88591 to WINDOWS-1250 Using Translit .................... 11 Conclusions .............................................................................. 12 Abstract This technical white paper proposes an interface from GUPTA Team Developer to the GNU LIBICONV allowing a Team Developer programmer to convert their documents to a different form of encoding. See http://www.gnu.org/software/libiconv/
    [Show full text]
  • AIX Globalization
    AIX Version 7.1 AIX globalization IBM Note Before using this information and the product it supports, read the information in “Notices” on page 233 . This edition applies to AIX Version 7.1 and to all subsequent releases and modifications until otherwise indicated in new editions. © Copyright International Business Machines Corporation 2010, 2018. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About this document............................................................................................vii Highlighting.................................................................................................................................................vii Case-sensitivity in AIX................................................................................................................................vii ISO 9000.....................................................................................................................................................vii AIX globalization...................................................................................................1 What's new...................................................................................................................................................1 Separation of messages from programs..................................................................................................... 1 Conversion between code sets.............................................................................................................
    [Show full text]