2014-10-20
Learning a few UNIX commands can be useful. Since it’s the ‘default’ programming language that pops up when you run the Terminal, it’s worth knowing a few of the more basic commands: These are sorted by ‘difficulty’ - you should know the first ones first.
cd
- changes the current directory.cd ~
- changes where you are to HOME directorycd Documents
- goes one file deeper into the ‘Documents’ foldercd ..
- goes up one directoryls
- list files or directories in current directoryls -la
- uses the options ‘-l’ (list in detail) and ‘-a’ (show hidden files)pwd
- print working directory. Shows where you are (relative to the root folder)
cp
- copycp anchovy.txt fishes/anchovy.txt
- creates a copy of the file under the ‘fishes’ directory.cp -r
- copy recursively. Useful for directories.
cp -r anchovy fishes/anchovy
- copies all the anchovy-related files from the folder ‘anchovy’rm
- removerm platypus.txt
- deletes the specified filermdir
- remove directorymv
- movemv anchovy.txt fishes/anchovy.txt
- moves & removes the file.mv anchovy.txt sardine.txt
mkdir
- creates a new directorymkdir pelicans
mkdir -p
- creates a series of new directories.
mkdir -p Pelecanidae/Pelicans/Great-White-Pelican
man
- find the manualman man
man pwd
cat
- show pure text version of the file.cat gerbil_name.txt
- simply outputs text: ‘Fred’less
- outputs text with more features.less encyclopedia.txt
- won’t crash & is still usefulsort
- guess what this one does…diff
- shows the differences between two filesdiff red_spotted_woodpecker.txt lesser_woodpecker.txt
whereis
chmod
chmod 755
, which is rwx
for the Owner but only rw
for other users.grep
I’ve written a quick primer on UNIX file permissions here
Grep’s a fairly big topic:
grep "some string" filename
grep "REGEX" filename
grep -i "some string" filename
- case insensitiveFlags are optional parameters that you can pass in to a shell command. We’ve met some already; here’re two: ls -la
. You can see a full list of available options under the man
page of the commands.