Basics Linux
Basics Linux
Basics Linux
What is Linux
wc emacs
● Bird’s eye view bash
multitasking
tcsh
cat device file grep
access
Hardware system
sh
Kernel awk
sort
Shell
Utilities
Who is Linux
&
● Linux is an O/S core originally
written by Linus Torvalds. Now ● A set of programs written by
almost 10,000 developers Richard Stallman and others.
including major technology They are the GNU utilities.
companies like Intel and IBM.
When is Linux?
~1991
Where is Linux
● Research/High-Performance Compute
○ Google, Amazon, NSA, 100% of TOP500 Super-computers.
Remote Server
Connection Protocols and Software
Remote Connections: Remote Graphics: Data Transfer:
Secure SHell X-Windowing Secure File Transfer Protocol
(SSH) (X, X-Win) (SFTP)
● Recommended: MobaXterm
○ Download: http://mobaxterm.mobatek.net/
● Alternatives:
○ SSH/X-Windows: X-Win32
https://www.bu.edu/tech/services/support/desktop/distribution/xwindows/
○ SFTP: Filezilla
https://filezilla-project.org/
● X-Windows: XQuartz
○ Download: https://www.xquartz.org/
○ Note: This install requires a logout.
● X-Windows: X11
○ Built in to Linux
○ Use your package manager.
[username@scc1 ~]$ cd ~
[username@scc1 ~]$ tar xf /scratch/linux-materials.tar
[username@scc1 ~]$ ls
c data haystack scripts
Linux Interaction
Shell, Prompt, Commands and System Use
Linux: The Shell
● Program that interprets commands and sends them to the OS
● Provides:
○ Built-in commands
○ Programming control structures
○ Environment variables
[username@scc1 ~]$
For more information about any command, use man or info (e.g. “man ls”)
Commands: Hands-On
Example: cal –j 3 1999. “cal” is the command, “-j” is an option (or switch), “3”
and “1999” are arguments/parameters.
… at its heart is the idea that the power of a system comes more from the
relationships among programs than from the programs themselves. Many
UNIX programs do quite trivial things in isolation, but, combined with other
programs, become general and useful tools.
Commands: Selected text processing utilities
● awk Pattern scanning and processing language
● cat Display file(s)
● cut Extract selected fields of each line of a file
Just a few of the
● diff Compare two files commands for
● grep Search text for a pattern text processing
● head Display the first part of files
● less Display files on a page-by-page basis
● sed Stream editor (esp. search and replace)
● sort Sort text files
● split Split files
● tail Display the last part of a file
● tr Translate/delete characters
● uniq Filter out repeated lines in a file
● wc Line, word and character count
Variables and Environment Variables
● Environment variables are shared with programs that the shell runs.
Bash variables
● To create a new variable, use the assignment operator ‘=‘
We use pathnames to refer to files and directories in the Linux file system.
● Examples:
○ cd /usr/local Change directory to /usr/local/lib
○ cd ~ Change to home directory (could just type ‘cd’)
○ pwd Print working (current) directory
○ cd .. Change directory to the “parent” directory
○ cd / Change directory to the “root”
○ ls –d pro* Listing of only the directories starting with “pro”
The ls Command
● Useful options for the “ls” command:
○ ls -a List all files, including hidden files beginning with a “.”
○ ls -ld * List details about a directory and not its contents
○ ls -F Put an indicator character at the end of each name
○ ls –l Simple long listing
○ ls –lR Recursive long listing
○ ls –lh Give human readable file sizes
○ ls –lS Sort files by file size
○ ls –lt Sort files by modification time (very useful!)
Some Useful File Commands
● cp [file1] [file2] copy file
● mkdir [name] make directory
● rmdir [name] remove (empty) directory
● mv [file] [destination] move/rename file
● rm [file] remove (-r for recursive)
● file [file] identify file type
● less [file] page through file
● head -n N [file] display first N lines
● tail -n N [file] display last N lines
● ln –s [file] [new] create symbolic link
● cat [file] [file2…] display file(s)
● tac [file] [file2…] display file in reverse order
● touch [file] update modification time
● od [file] display file contents, esp. binary
Manipulating files and directories
● Examples:
○ cd # The same as cd ~
○ mkdir test
○ cd test
○ echo ‘Hello everyone’ > myfile.txt
○ echo ‘Goodbye all’ >> myfile.txt
○ less myfile.txt
○ mkdir subdir1/subdir2 # Fails. Why?
○ mkdir -p subdir1/subdir2 # Succeeds
○ mv myfile.txt subdir1/subdir2
○ cd ..
○ rmdir test # Fails. Why?
○ rm –rf test # Succeeds
Symbolic links
● Sometimes it is helpful to be able to access a file from multiple locations
within the hierarchy. On a Windows system, we might create a “shortcut.” On
a Linux system, we can create a symbolic link:
● Examples:
○ find ~ -name bu –type d # search for “bu” directories in ~
○ find . –name my-file.txt # search for my-file.txt in .
○ find ~ -name ‘*.txt’ # search for “*.txt” in ~
● Quiz:
○ Can you use find to locate a file called “needle” in your haystack directory?
○ Extra credit: what are the contents of the “needle” file?
Processes & Job Control
Processes and Job Control
● As we interact with Linux, we create numbered instances of running programs
called “processes.” You can use the ‘ps’ command to see a listing of your
processes (and others!). To see a long listing, for example, of all processes
on the system try:
● To see all the processes owned by you and other members of the class, try:
● Also, try running ‘jobs’ to see any jobs running in the background from this
bash shell.
● To kill the job, use the ‘kill’ command, either with the five-digit process id:
○ kill 54356
● Or, you can use the job number (use ‘jobs’ to see list) with ‘%’:
○ kill %1
Backgrounding a running job with C-z and ‘bg’
● Sometimes you start a program, then decide to run it in the background.
[username@scc1 scripts]$ bg
[1]+ ./countdown 200 > c.out &
[username@scc1 scripts]$
Editors
Regular expressions
● Many Linux tools, such as grep and sed, use strings that describe sequences
of characters. These strings are called regular expressions.
Here are some examples: