Unix Command-Line Processing Unix Directories Files
Unix Command-Line Processing
Useful Commands Permissions tar More Commands Working Remotely
L435/L555
Emacs
Dept. of Linguistics, Indiana University Fall 2014
1 / 22
What is Unix?
Unix Command-Line Processing Unix Directories Files Useful Commands
Unix is an operating system, like DOS or Windows
Permissions tar
I
developed in 1969 by Bell Labs
I
works well for single computers as well as for servers
Working Remotely
I
underlying operating system for Macs
Emacs
More Commands
Linux: open source version of Unix (mostly for PCs)
2 / 22
Directory Structure
Unix Command-Line Processing Unix Directories
directory = folder I
directory structure: tree structure
Files Useful Commands Permissions
Important directories: I I I
tar
home directory: your private directory (/Users/guest)
More Commands
root node: / important directories on a Mac:
Working Remotely
I I I I
Emacs
/Applications /Users /Volumes /Volumes/Data/
3 / 22
Unix
Graphical Representation
Command-Line Processing Unix Directories Files Useful Commands
/
Permissions tar
Applications
Users
Volumes
More Commands Working Remotely
md7 guest ...
Data
Emacs
ar en de multilingual ...
4 / 22
Useful Commands for Directories I
I
I
list files in current directory:
Unix
ls
Directories
list files with more information:
Files
ls -l
Useful Commands
change directories:
cd I
two possibilities to specify : I
I
I
Unix Command-Line Processing
from root:
Permissions tar More Commands Working Remotely Emacs
cd /Users/md7 from where we are: cd ../md7 .. means ’go up’
go back to home directory:
cd I
show the directory where you are:
pwd 5 / 22
Useful Shortcuts
Unix Command-Line Processing Unix Directories Files Useful Commands
TAB completion If you start typing a command or filename, then press TAB, the shell will complete the word for you – as far as possible.
Permissions tar More Commands Working Remotely
Command history
Emacs
The shell keeps a history of your commands. To scroll through them, simply press the up arrow key.
6 / 22
Looking at Files
Unix Command-Line Processing Unix Directories
I
I
display contents of file in terminal:
Files
cat
Useful Commands
display page by page:
Permissions
less
tar
I I I I I I I
I
next page: space bar quit: q go to beginning of file: g go to end of file: G search forward: / + hit return search backward: ? + hit return in search: next found occurrence: n
More Commands Working Remotely Emacs
Likewise, there is the more command
7 / 22
Looking at Files More Commands
Unix Command-Line Processing Unix Directories Files
I
display beginning of file (normally 10):
head I
display X beginning lines of file:
head -X
Useful Commands Permissions tar More Commands Working Remotely
I
display end of file (normally 10):
Emacs
tail I I
I
tail -X : display X ending lines tail +X : display all lines starting at X
count number of lines, words, characters in a file:
wc
8 / 22
Unix
More Useful Commands
Command-Line Processing Unix Directories
I
I
list files that end in ’.txt’:
Files
ls *.txt
Useful Commands
make directory:
Permissions
mkdir subdirectory: mkdir results in your home directory: mkdir
tar More Commands
∼/results
Working Remotely Emacs
I
copy a file from one location to another:
cp I
copy a file to the directory ’results’ in your home directory:
cp dates.txt
∼/results
9 / 22
More Useful Commands (2)
Unix Command-Line Processing Unix
I
I
sort your file:
sort
Files
sort (numbers) in numeric order:
Useful Commands
sort -n I
I
Directories
Permissions tar
find a word in a file and display all the lines in which it occurred:
Working Remotely
grep
Emacs
More Commands
find a word in a file and display all the lines in which it occurred and save results into a file in your home directory:
grep > ∼/ I
example:
grep linguistic mycorp.txt > ∼/res.txt
10 / 22
Tangent: How to Find out More
Unix Command-Line Processing Unix Directories Files
What other options are there for sorting? The man command lets you see documentation on whatever unix command is in question I
Find information:
Useful Commands Permissions tar More Commands Working Remotely Emacs
man man sort | less
11 / 22
Tangent: grep & egrep
Unix Command-Line Processing Unix Directories Files Useful Commands Permissions
grep is commonly used, but doesn’t offer a full RE syntax I
For that, use egrep (extended grep)
tar More Commands Working Remotely
Bonus: what does grep stand for?
Emacs
12 / 22
More Useful Commands (3)
Unix Command-Line Processing Unix Directories Files
I
delete lines (adjacent) with identical content:
uniq I
delete lines (adjacent) with identical content, but list how many were there:
uniq -c I
Useful Commands Permissions tar More Commands Working Remotely Emacs
display differences between two files
diff
13 / 22
Unix
Permission System I
Command-Line Processing
ls -l
-rw-r--r-drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x
Unix
1 15 3 4 35
root root root root root
admin admin admin admin admin
168724 510 102 136 1190
Nov 9 2003 Aug 31 2006 Aug 4 2004 Mar 2 2007 Feb 18 15:23
Jokes.pdf ar cs de en
Directories Files Useful Commands Permissions tar More Commands
I
change permissions:
chmod : user = u; group= g; others = o; all = a; : read = r; write = w; execute = x; I
Working Remotely Emacs
example: give user write permissions for file ’hello.txt’:
chmod u+w hello.txt I
example: deny others write and execute permissions for directory ’test’:
chmod o-wx test 14 / 22
Packing and Unpacking Files
Unix Command-Line Processing Unix
I
pack a file:
gzip I
I
results in .gz
unpack file:
gunzip .gz I
Directories Files Useful Commands Permissions tar More Commands
’pack’ more than one file:
Working Remotely
tar cvf .tar
Emacs
I
unpack:
tar xvf .tar I
tar and gzip:
tar cvzf .tgz I
unpack:
tar xvzf .tgz
15 / 22
More on Copy and Move
Unix Command-Line Processing Unix Directories
I
I
copy a file from one location to another:
Files
cp
Useful Commands
move a file from one location to another:
mv I
I
Permissions tar More Commands
rename a file:
Working Remotely
mv
Emacs
remove a file:
rm I
remove a directory including contents:
rm -r
16 / 22
Important Shortcuts in Paths
Unix Command-Line Processing Unix Directories Files Useful Commands Permissions
I
.. (go) up one directory . here
Working Remotely
I
∼ home directory
Emacs
I
tar More Commands
17 / 22
Translate
Unix Command-Line Processing Unix Directories Files
I
exchange characters for others:
tr ’aeiou’ ’X’ < tr ’aeiou’ ’AEIOU’ <
Useful Commands Permissions tar More Commands
I
collapse characters (squeeze):
tr -s ’J’ < I
Working Remotely Emacs
exchange complement of characters for others:
tr -c ’a-z’ ’\n’ < \n is a linebreak
18 / 22
Putting Commands Together
Unix Command-Line Processing Unix Directories
I
< use following filename as input file
I
> use following filename as output file
I
| use output of preceding command as input for following commands
Files Useful Commands Permissions tar More Commands Working Remotely Emacs
I
example:
cat | tr ’A-Z’ ’a-z’ | sort >
19 / 22
Remote Login
Unix Command-Line Processing Unix Directories Files Useful Commands
I
login: ssh husernamei@hmachinenamei
tar
e.g.
Working Remotely
Permissions
More Commands
ssh
[email protected]
Emacs
I
logout:
exit
20 / 22
Remote Copy
Unix Command-Line Processing Unix Directories
I
I
Files
to copy a local file to (your home directory) on another machine:
Useful Commands
scp : e.g. scp vm.pos nlp.indiana.edu:
tar
to copy a file from another machine to the current directory:
Permissions
More Commands Working Remotely Emacs
scp :/ . e.g. scp nlp.indiana.edu:/Volumes/Data/en/ penntreebankv3/readme.all . (in one line!)
21 / 22
Emacs
Unix Command-Line Processing Unix Directories
I
I
I
emacs is a fairly basic text editor that can be run in a window or in the shell to start emacs:
Permissions
emacs
tar
to quit:
Ctrl-x Ctrl-c I
Files Useful Commands
More Commands Working Remotely Emacs
save:
Ctrl-x Ctrl-s I
search:
Ctrl-s Other shell editors include vim and nano
22 / 22