Introduction to the command-line
Francis Kayiwa
kayiwa@catchyname:~$ whoami
kayiwa
kayiwa@catchyname:~$ env
_=/usr/bin/env
TWITTER=kayiwa
EMAIL=kayiwa@pobox.com
PRESENTATION_NAME="Introduction to the command-line"
Code_of_conduct="http://code4libnys.github.io/2016/"
dritchie@cliwkshp:~$ passwd
Changing password for dritchie.
(current) UNIX password:
getting in and out
passwd
online help
man
dritchie@cliwkshp:~$ man -k spell
aspell-autobuildhash (8) - Autobuilding aspell hash files for some dicts.
...
ispell-wrapper (1) - smart wrapper for ispell
man 1 ispell-wrapper
ISPELL-WRAPPER(1) ISPELL-WRAPPER(1)
NAME
ispell-wrapper - smart wrapper for ispell
SYNOPSIS
ispell-wrapper [--emacs=name] [--language=regexp] [--dry-run] [ispell options] file
dritchie@cliwkshp:~$ man man
MAN(1) Manual pager utils MAN(1)
NAME
man - an interface to the on-line reference manuals
SYNOPSIS
man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m system[,...]] [-M path]
[-S list] [-e extension] [-i|-I] [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P
pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification] [-p string] [-t]
[-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
man -k [apropos options] regexp ...
man
help
dritchie@cliwkshp:~$ <command> -h
dritchie@cliwkshp:~$ <command> --help
dritchie@cliwkshp:~$ ispell-wrapper -h
Usage: ispell [-dfile | -pfile | -wchars | -Wn | -t | -n | -H | -x | -b | -S | -B | -C | -P | -m | -Lcontext | -M | -N | -Ttype | -ktype kws | -Fpgm | -V] file .....
ispell [-dfile | -pfile | -wchars | -Wn | -t | -n | -H | -Ttype | -ktype kws | -Fpgm] -l
ispell [-dfile | -pfile | -ffile | -Wn | -t | -n | -H | -B | -C | -P | -m | -Ttype | -ktype kws | -Fpgm] [-a | -A]
ispell [-dfile] [-wchars | -Wn] -c
ispell [-dfile] [-wchars] -e[1-4]
ispell [-dfile] [-wchars] -D
ispell -v
Whenever a word is found that is not in the dictionary,
it is printed on the first line of the screen. If the dictionary
contains any similar words, they are listed with a number
next to each one. You have the option of replacing the word
completely, or choosing one of the suggested words.
apropos
dritchie@cliwkshp:~$ apropos "text editor"
Exercises
1. Use the online manual to find which command line editors are available
2. Use the online manual to find out how to list files
Files and directories
pwd
dritchie@cliwkshp:~$ pwd
/home/dritchie
Files and directories
ls
dritchie@cliwkshp:~$ ls --help
dritchie@cliwkshp:~$ ls -l
dritchie@cliwkshp:~$ ls -a
dritchie@cliwkshp:~$ ls -latg
dritchie@cliwkshp:~$ ls -hitlar
Files and directories
cat, more, less
dritchie@cliwkshp:~$ cat /etc/motd
dritchie@cliwkshp:~$ more /etc/motd
dritchie@cliwkshp:~$ less /etc/motd
Files and Directories
cp
dritchie@cliwkshp:~$ man cp
dritchie@cliwkshp:~$ ls
dritchie@cliwkshp:~$ cp cli_workshop/data_files/22631-0.txt .
dritchie@cliwkshp:~$ ls
Files and Directories
mv
dritchie@cliwkshp:~$ mv 22631-0.txt timbuctoo.txt
dritchie@cliwkshp:~$ timbuctoo.txt Desktop/timbuctoo.txt
Files and Directories
rm
dritchie@cliwkshp:~$ touch new_file_to_purge.txt
dritchie@cliwkshp:~$ ls
dritchie@cliwkshp:~$ rm -i new_file_to_purge.txt
Files and Directories
chmod
dritchie@cliwkshp:~$ chmod o+w 22631-0.txt
dritchie@cliwkshp:~$ chmod g-w 22631-0.txt
dritchie@cliwkshp:~$ chmod 700 22631-0.txt
dritchie@cliwkshp:~$ chown :belllabs 22631-0.txt
Files and Directories
cd, mkdir, pwd
dritchie@cliwkshp:~$ cd
dritchie@cliwkshp:~$ cd /usr/bin
dritchie@cliwkshp:~$ cd ~/Desktop
dritchie@cliwkshp:~$ mkdir ~/Desktop/cliworkshop
dritchie@cliwkshp:~$ pwd
Exercises
- Specify three ways how `dritchie`may go from /usr/bin to his home directory.
- Using the cp command make a copy of the 22361-0.txt to the /tmp directory
- Instead of using the rm command how can `dritchie` move the 22361-0.txt file to the /tmp directory
- How can `dritchie` change the permission on the 22361-0.txt file so anyone can read it?
- How can dritchie make his Desktop directory so no one except he can read it?
Editing Files
emacsmg, nano,vimvi
Shell Interface
file redirection
dritchie@cliwkshp:~$ sort < cli_workshop/data_files/library-visits.csv > sorted.csv
dritchie@cliwkshp:~$ in2csv cli_workshop/data_files/Evidovane-knihovny.xls > converted_file.csv
Shell Interface
pipes
dritchie@cliwkshp:~$ sort --help | less
dritchie@cliwkshp:~$ in2csv --help | less
Shell Interface
alias
dritchie@cliwkshp:~$ alias whereami='ls al && pwd'
dritchie@cliwkshp:~$ alias please='sudo'
dritchie@cliwkshp:~$ alias md='mkdir -p'
Exercises
dritchie@cliwkshp:~$ w
dritchie@cliwkshp:~$ who
dritchie@cliwkshp:~$ ls
dritchie@cliwkshp:~$ !1
dritchie@cliwkshp:~$ cd /tmp
dritchie@cliwkshp:~$ !3
dritchie@cliwkshp:~$ !c
dritchie@cliwkshp:~$ !w
1. If a user logs into a Unix system and types the following input to the shell, list the commands executed by the shell for each of the history substitutions:
Misc. Unix Commands
echo
dritchie@cliwkshp:~$ echo print this line of text to standard output
dritchie@cliwkshp:~$ echo -n print this line with the flag
dritchie@cliwkshp:~$ echo --help
dritchie@cliwkshp:~$ echo -e "1,a\n2,b\n3,c" > file.csv
dritchie@cliwkshp:~$ sudo echo "docnow ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Misc. Unix Commands
who
dritchie@cliwkshp:~$ who
Misc. Unix Commands
date
dritchie@cliwkshp:~$ date --help
dritchie@cliwkshp:~$ date
dritchie@cliwkshp:~$ date --set "4 AUGUST 2016 1:40 PM"
Misc. Unix Commands
cal
dritchie@cliwkshp:~$ cal --help
dritchie@cliwkshp:~$ cal 1999
Misc. Unix Commands
bc
dritchie@cliwkshp:~$ bc --help
dritchie@cliwkshp:~$ bc
Misc. Unix Commands
wc
dritchie@cliwkshp:~$ cat ~/cli_workshop/data_files/names.txt
dritchie@cliwkshp:~$ wc --help
dritchie@cliwkshp:~$ wc ~/cli_workshop/data_files/names.txt
dritchie@cliwkshp:~$ wc -cw ~/cli_workshop/data_files/names.txt
Misc. Unix Commands
script
dritchie@cliwkshp:~$ script
Script started, file is typescript
dritchie@cliwkshp:~$ pwd
/home/dritchie
dritchie@cliwkshp:~$ cal
July 2016
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
dritchie@cliwkshp:~$ echo -e "one\ntwo\nthree" | wc -l
3
dritchie@cliwkshp:~$ who
kayiwa pts/9 2016-07-25 19:37
dritchie@cliwkshp:~$ exit
Script done, file is typescript
Misc. Unix Commands
du
dritchie@cliwkshp:~$ du --help
dritchie@cliwkshp:~$ du -h ~/Desktop
dritchie@cliwkshp:~$ du -sh ~ | sort -n > ~/diskusage
Misc. Unix Commands
sudo
dritchie@cliwkshp:~$ sudo --help
dritchie@cliwkshp:~$ sudo -l
dritchie@cliwkshp:~$ visudo
Unix Filters
sort
dritchie@cliwkshp:~$ sort --help
dritchie@cliwkshp:~$ sort -r -k2 ~/cli_workshop/data_files/operatingsystemlist
Unix Filters
tee
dritchie@cliwkshp:~$ tee --help
dritchie@cliwkshp:~$ pwd > file
dritchie@cliwkshp:~$ cat file
dritchie@cliwkshp:~$ pwd | tee file.txt
Unix Filters
grep
dritchie@cliwkshp:~$ grep --help
dritchie@cliwkshp:~$ cat cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ grep -F BSD cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ grep -F -v BSD cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ grep -E '.en+' cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ grep -E 'll*' cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ grep -E '[no]' cli_workshop/data_files/operatingsystemlist
Unix Filters
awk
dritchie@cliwkshp:~$ awk --help
dritchie@cliwkshp:~$ date
dritchie@cliwkshp:~$ date | awk '{print $2 $3}'
dritchie@cliwkshp:~$ date | awk '{ print $2" "$3}'
dritchie@cliwkshp:~$ who
dritchie@cliwkshp:~$ who | awk '{print $1}'
Unix Filters
head
dritchie@cliwkshp:~$ head --help
dritchie@cliwkshp:~$ cat cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ head -2 cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ head -2 cli_workshop/* | cat
Unix Filters
tail
dritchie@cliwkshp:~$ tail --help
dritchie@cliwkshp:~$ cat cli_workshop/data_files/operatingsystemlist
dritchie@cliwkshp:~$ tail -2 cli_workshop/data_files/operatingsystemlist
Unix Filters
cut
dritchie@cliwkshp:~$ cut --help
dritchie@cliwkshp:~$ cat ~/cli_workshop/data_files/cut_example.txt
dritchie@cliwkshp:~$ cut -c4 ~/cli_workshop/data_files/cut_example.txt
dritchie@cliwkshp:~$ cut -c4-6 ~/cli_workshop/data_files/cut_example.txt
Communication and File Archiving
tar
dritchie@cliwkshp:~$ tar --help
dritchie@cliwkshp:~$ tar cvpf /tmp/desktop.tar ~/Desktop/
Communication and File Archiving
gzip, zcat, gunzip
dritchie@cliwkshp:~$ gzip --help
dritchie@cliwkshp:~$ gzip -c -r ~/Desktop/ > /tmp/desktop.gz
dritchie@cliwkshp:~$ zcat /tmp/desktop.gz | less
Introduction to the command-line
By Francis Kayiwa
Introduction to the command-line
- 817