Terminal emulator
~/.bashrc
Note
Explain architecture: | |
---|---|
built in commands vs. external binaries | |
Demo commands: | Directory movement and file manipulation: Cd, pwd, ls, rm, mv, touch |
User info: | id, whoami, w |
Pipes: | redirection (pipe.txt, redirect.txt) |
Special variables: | |
$?, $$ (pid.sh), !!, !*, !$ |
ls
, cd
, cat
, echo
man <program>
test@x230 ~ $ tree
.
├── Documents
│ ├── Code
│ │ └── scripts
│ │ └── test.sh
│ ├── School
│ └── Work
└── Pictures
├── manatee.gif
└── turtle.png
6 directories, 5 files
Note
Permissions discussed later.
$ ls -l
$ chmod +x $filename
$ ./$filename
Arguments (or flags) are extra information that you pass to a script or program when you call it. They tell it in more detail what you want to do.
$ ls -a -l
$ ls -al
$ ls -si
$ ls --si
.
means current directory..
means parent directory~
) means your homedir (/home/$username
)/
separates directories (not \
)/
is root directory, so ~
expands to /home/$username/
test@x230 ~ $ ls
Documents Pictures
test@x230 ~ $ cd Documents/
test@x230 ~/Documents $ ls
Code School Work
test@x230 ~/Documents $ pwd
/home/test/Documents
Note
root directory is not to be confused with a home directory for the root account
\
to use them literally~/.bashrc
Tab completion
Automation > Typing > Mouse
ctrl+c kills or quits process
read what's on your screen; it'll help you
test@x230 ~ $ tree
.
├── Documents
│ ├── Code
│ │ └── scripts
│ │ └── test.sh
│ ├── School
│ └── Work
└── Pictures
├── manatee.gif
└── turtle.png
6 directories, 5 files
the manual (rtfm):
$ man <program>
$ man man
use /phrase
to search for phrase
in the document; n
for next match
and N
for previous match
else:
$ <program> --help
Man pages, blogs you find by Googling, StackOverflow
For your future self as well
Start now
It's okay to ask.
Contributions = expertise + time
Don't waste experts' time, but do build your expertise.
What's Linux?
I have the script test.py
. How do I run it?
How do you list all the files in the current directory?
Give 2 ways to change directory to your home directory.
$ whoami # your username
$ who # who is logged in?
$ w # who is here and what are they doing?
$ id # user ID, group ID, and groups you're in
$ cat /etc/passwd
# username:x:UID:GID:GECOS:homedir:shell
$ useradd $USER # vs adduser, the friendly Ubuntu version
$ userdel $USER
$ passwd
# GECOS: full name, office number and building, office phone extension,
# home phone number (General Electric Comprehensive Operating System)
$ chfn # change GECOS information; only works sometimes
$ finger # tells you someone's GECOS info
/etc/shadow
, not /etc/passwd
test@x230 ~ $ ls -l /etc/ | grep shadow
-rw-r----- 1 root shadow 1503 Nov 12 17:37 shadow
$ sudo su -
$ cat /etc/shadow
daemon:*:15630:0:99999:7:::
bin:*:15630:0:99999:7:::
sys:*:15630:0:99999:7:::
mail:*:15630:0:99999:7:::
# name:hash:time last changed: min days between changes: max days
# between changes:days to wait before expiry or disabling:day of
# account expiry
$ chage # change when a user's password expires
sudo
$ su $USER # become user, with THEIR password
$ su # become root, with root's password
$ sudo su - # use user password instead of root's
$ sudo su $USER # become $USER with your password
$ groupadd
$ usermod
$ groupmod
$ cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
# group name:password or placeholder:GID:member,member,member
Note
To give yourself sudo powers do the following:
Add your user to the wheel
group using gpasswd
.
As the root user, use visudo
and uncomment this line:
pcwheel ALL=(ALL) ALL
Save the file and now you should have sudo!
We'll cover sudo in more depth at a later time.
Nearly everything
test@x230 ~ $ ls -il
total 8
2884381 drwxrwxr-x 5 test test 4096 Nov 6 11:46 Documents
2629156 -rw-rw-r-- 1 test test 0 Nov 13 14:09 file.txt
2884382 drwxrwxr-x 2 test test 4096 Nov 6 13:22 Pictures
.jpg
, .txt
, .doc
$ file $FILENAME # tells you about the filetype
test@x230 ~ $ file file.txt
file.txt: ASCII text
test@x230 ~ $ file squirrel.jpg
squirrel.jpg: JPEG image data, JFIF standard 1.01
$ ls -l
drwxrwxr-x 5 test test 4096 Nov 6 11:46 Documents
-rw-rw-r-- 1 test test 0 Nov 13 14:09 file.txt
drwxrwxr-x 2 test test 4096 Nov 6 13:22 Pictures
+-----+--------+-------+
| rwx | Binary | Octal |
+-----+--------+-------+
| --- | 000 | 0 |
| --x | 001 | 1 |
| -w- | 010 | 2 |
| -wx | 011 | 3 |
| r-- | 100 | 4 |
| r-x | 101 | 5 |
| rw- | 110 | 6 |
| rwx | 111 | 7 |
+-----+--------+-------+
user & group
# Change the owner of myfile to "root".
$ chown root myfile
# Likewise, but also change its group to "staff".
$ chown root:staff myfile
# Change the owner of /mydir and subfiles to "root".
$ chown -hR root /mydir
# Make the group devops own the bootcamp dir
$ chgrp -R devops /home/$yourusername/bootcamp
drwxrwxr-x 5 test test 4096 Nov 6 11:46 Documents
-rw-rw-r-- 1 test test 0 Nov 13 14:09 file.txt
drwxrwxr-x 2 test test 4096 Nov 6 13:22 Pictures
---------- ------- ------- -------- ------------ -------------
| | | | | |
| | | | | File Name
| | | | +--- Modification Time
| | | +------------- Size (in bytes)
| | +----------------------- Group
| +-------------------------------- Owner
+---------------------------------------------- File Permissions
-
is a normal file
d
is a directory
b
is a block device
$ touch foo # create empty file called foo
Take care of installation and removal of software
Core Functionality: * Install, Upgrade & uninstall packages easily * Resolve package dependencies * Install packages from a central repository * Search for information on installed packages and files * Pre-built binaries (usually) * Find out which package provides a required library or file
Popular Linux Package Managers * .deb / APT + dpkg (used by Debian, Ubuntu, Linux Mint) * .rpm / YUM + rpm (used by RedHat, CentOS, Fedora)
Languages sometimes have their own package management suite
Can be useful for using newer versions of packages
They each fill a specific niche and have their own pros and cons.
grep
as an example$ wget http://mirrors.kernel.org/gnu/grep/grep-2.15.tar.xz
$ tar -Jxvf grep-2.15.tar.xz
$ cd grep-2.15
$ ./configure --prefix=$HOME/programs/
$ make
$ make install
git
packagegit
packageread example output of ls -al
read output of yum or aptitude search
Note
Switch to a terminal and show example
Use irssi or weechat in screen
# This step is optional, but persistent IRC is cool
$ ssh <username>@<preferred shell host>
# start screen with the name 'irc'
$ screen -S irc
# start your client in the 0th window of the screen session
$ irssi
# or
$ weechat-curses
# exit irc screen with CTRL+a, CTRL+d
# exit ssh session with CTRL+d or 'exit'
# to get back to irc:
$ ssh <username>@<preferred shell host>
$ screen -dr IRC
/connect irc.freenode.net
/nick <myawesomenickname>
/msg nickserv register <password> <email>
/nick <myawesomenickname>
/msg nickserv identify <password>
/join #osu-lug
/join #devopsbootcamp
/list : |
|
---|---|
/topic : | tells you the current channel's topic |
/names : | tells you who's here |
/me does thing`
/say $thing
/join, /part, /whois <nick>, /msg, /help <command>
Note that nothing shows up in the channel when you run a /whois
command; it
shows up either in your status buffer or your conversation with the person.
12:04 -!- _test_ [~test@c-50-137-46-63.hsd1.or.comcast.net]
12:04 -!- ircname : Example User
12:04 -!- channels : #ExampleChannel
12:04 -!- server : moorcock.freenode.net [TX, USA]
12:04 -!- hostname : c-50-137-46-63.hsd1.or.comcast.net 50.137.46.63
12:04 -!- idle : 0 days 0 hours 2 mins 38 secs [signon: Wed Nov 6
12:00:30
2013]
12:04 -!- End of WHOIS
Tab-complete works on nicknames. use it.
Highlight when people say your name
Symbols are not part of names; they mark status in channel (such as @)
Logging (expect it); `/set autolog on`
to get back, screen -dr IRC
Can you use man screen
to find out what the d and r flags mean?
SCREEN(1) SCREEN(1)
NAME
screen - screen manager with VT100/ANSI terminal emulation
SYNOPSIS
screen [ -options ] [ cmd [ args ] ]
screen -r [[pid.]tty[.host]]
screen -r sessionowner/[[pid.]tty[.host]]
Manual page screen(1) line 1 (press h for help or q to quit)
Lurk more
Show that you're worth helping
/topic
Pastebin code
Choose your nick carefully
tail
hat
nick
netsplit
kick/ban/k-line
o/
AND \o
high fives/me &
means afkHow do you reconnect to a screen session?
Give an example of something which you should not do in IRC