linux for beginners - computer sciencehays/tectalks/2018-02-02-linux-for-begin… · 2018-02-02...

23
Linux for Beginners Windows users should download putty or bitvise: https://putty.org/

Upload: others

Post on 16-Nov-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Linux for BeginnersWindows users should download putty or bitvise:

https://putty.org/

Page 2: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Brief History

• UNIX (1969) written in PDP-7 assembly, not portable, and designed for programmers as a reaction by Bell Labs to Multics (GE, MIT, and Bell)

• Ken Thomson developed B—machine independent programming language• Dennis Ritchie rewrote UNIX in C (1972)• Multi-tasking, multi-user, time-sharing• Two main flavors, BSD and System V• All proprietary

Page 3: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Brief History

• Began as a server OS as a free (as in beer) alternative to UNIX™

• Strictly speaking, only the kernel is Linux (1991), most of the software on linux systems is GNU (started 1983 by Richard Stallman, not free like beer)

• Monolithic kernel as opposed to a microkernel used in Minix (1987) and GNU Hurd (1990) ¡huge debate online!

• https://en.wikipedia.org/wiki/Tanenbaum%E2%80%93Torvalds_debate

• GNU Hurd released 0.9 in 2016

Page 4: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write
Page 5: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Philosophy of UNIX

• Write programs that do one thing and do it well.• Write programs to work together.• Write programs to handle text streams, because that is a universal interface.

-Peter Salus in A Quarter-Century of Unix (1994)• A command is followed by flags and parameters separated by white space• Pretty much every thing is treated as a file, and this allows a standard API for

I/O on all linux systems

Page 6: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

User Interaction

• Unlike DOS, MacOS, Windows, the user interacts with ”just another program”

• Command line interaction via one of the many shells available (korn, csh, sh, bash, zsh—you all should probable learn zsh, but I’ll be talking about bash)

• Graphic User Interface via one of the many X11 windowing systems (gnome, KDE, Xfce) or Unity (in ubuntu, although they are going back to gnome)

Page 7: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

If you want to play along

• If you're on windows, use putty to connect to hayesville.cs.unc.edu with your onyen and password. If you're on a mac, open terminal and connect with ssh. If you on linux, why are you here?ssh [email protected]

• Once you're there, you can run this command to see what shell you're running:echo $0

Page 8: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

bash

• Brian Fox began bash in 1988 at FSF riffing off the bourne shell (sh)

• Bash is the Bourne Again shell

• Some commands you will use are baked into bash, most are not

• Bash is the default shell on hayesville. Our default in CS is tcsh, but we're changing that to bash. If you want a different shell with us, send email to help, but do some research into bash and zsh first. I recommend you go to zsh.

Page 9: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Filesystem

• No drive letters

• “root” of the filesystem is / --everything hangs off of that• Files are represented by inode numbers. You can have softlinks and hardlinks• / separates files and directories

ls: lists the contents of a directorypwd: outputs the current pathcd changes directories. means this directory, .. means this directory abovetree: outputs the directory tree from where you are

Page 10: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Directories

• There's a lot of variety in usage

• /etc is for system wide configuration files

• /home is for home directories

• /media is where one usually mounts external media like USB sticks

• /tmp is for temporary files

• /dev stores handles to devices (which look like files)

Page 11: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Directories

• Where is software installed?

• /usr is where the distro software goes

• /opt is one place 3rd party software goes

• /usr/local is where software you build goes

• ./bin and ./sbin are for binaries and system binaries

• ./etc is where most configuration files go

Page 12: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Try these

• Try running these commands in your terminal session on hayesville

• To see where you are:pwd

• To list your home directory showing all files/directories in long format:ls –la

• To list files/directories in the dir above you:ls ..

• To see the files/directories at the top of the directory treels /

Page 13: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Try These

• List the contents of a file of a with cat:cat .profile

• Display a line of text with echo:echo "my beautiful string"

• Print out the number of lines, words and bytes in a filewc .profile

• Make a directory in your home dir:mkdir ~/temp-dir

Page 14: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Linux Filesystem Permissions

• Three permission groups: user, group, others• Three permission types: read, write, execute• Use the chown command to set the user:group for a file/directory:

chown hays:wheel example-file.txt• Use the chmod command to set permissions,:

chmod u+x script.sh• You can also set permission with octal numbers: r=4, w=2, x=1, So to set a file to

permissions on file1 to read _rwxr_____, you would enterchmod 740 file1

Page 15: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

root

• On hayesville, you have no administrative privileges

• If you did, you could run sudo to run commands as root:sudo apt update; sudo apt upgrade(The semicolon ends a command string, so that’s two commands)

• You can also become root:sudo –i

Page 16: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Key Concept: Standard I/O

• One input stream, one output string and maybe one error string• stdin, stdout, stderr—Originally keyboard and screen, but then abstracted• Can be redirected—remember pretty much everything is treated as a file• This command echoes the string inside the quotes into a file named tmp.txt:

echo "This nice string goes into a file" > tmp.txt• Use >> to append to a file• Input can also be redirected:

cat < tmp.txt• What happens if you type this:

> tmp.txt

Page 17: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Key Concept: Pipes

• You can use the | character to pipe the output of one command to another

• This line uses the ls command to list files and the output is passed to sed, which replaces each a, e, i, and o with a u: ls -la | sed -e "s/[aeio]/u/g"

• The -a with ls outputs all files—files beginning with a dot are usually hidden

• sed is Streaming Editor, you use it to edit a text stream

Page 18: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Processes

• Running progams are called processes, and they can be parents/children

• Add & to the end of a command to throw a process in the background• ps -A will show a list of all processes• ps -f will show a list of processes in fuller format, -F even fuller format• top shows the most active processes in a list that updates• Processes run under a user, real or system, and have process IDs• kill is a program used to force a process to stop• ^c will try to stop the foreground process

Page 19: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Misc

• Tab expansion

• History

• tail

• less

• find

• grep

Page 20: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Going further

• man pages!• Read this: http://catb.org/~esr/faqs/smart-questions.html• Check out the sources at the end of the slide deck• If you want to play with ubuntu, you can download the stock image, burn it to an

optical disk and boot to that and play with it live.• Even better, download virtual box from Oracle and install ubuntu in a virtual

machine (we can do a talk on that if there’s interest). After it's installed make a snapshot. Whenever you get ready to try something new, make a snapshot. Snapshots are your new best friend.

Page 21: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

One more thing

• Our home dirs on most cs machines and the ones on login.its.unc.edu are in in AFS, which is not part of the standard filesystems used in linux. In afs, unix file system permission settings are almost meaningless, afs has it's own set of Access Control Lists and control access to directories including home directories.

• More info on AFS and our systems is in the help articles on the cs.unc.eduweb site

Page 22: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Reading

• https://en.wikipedia.org/wiki/GNU/Linux_naming_controversy• http://www.tldp.org/guides.html• https://www.tecmint.com/subscribe-to-blog/• https://web.archive.org/web/20120131042028/http://code.google.com/ed

u/tools101/index.html• https://linuxconfig.org/• https://www.server-world.info/en/

Page 23: Linux for Beginners - Computer Sciencehays/TecTalks/2018-02-02-Linux-for-begin… · 2018-02-02  · Philosophy of UNIX •Write programs that do one thing and do it well. •Write

Training

• http://cs.unc.edu/help-article/it-training-opportunities/

• Next week, we have an intro to git talk. Knowing a bit about git is a prereqfor the workshops on the CloudApps (docker) system we’ll have later this semester….

• lynda.com has some nice courses on git