Command line interface
Here's a tonne of terminal commands that all web developers should be familiar with...
Permissions
//To run a command
sudo
// then type in password for the computer
//To access a directory
sudo su
// then type in password for the computer
Show/hide hidden files (on a mac)
//Show
defaults write com.apple.Finder AppleShowAllFiles TRUE;
killall Finder
//Hide
defaults write com.apple.Finder AppleShowAllFiles FALSE
killall Finder
Browsing
cd
//to change a directory
ls
//lists out all the stuff in the directory
ls -l
//does the same thing as the previous but with more details (dates etc.)
pwd
//gives you the path of where you are
//Note - hit ctrl -X
//To exit or cancel
Reading files
//Find how much disk space is left
sudo df -h
sudo du -sh *
DNS records
whois markendley.co
//Will give you all the details of the domain name including details of registrar and name-servers
Editing files
less hello.txt
//open the txt file hello.txt so you can edit it!
q
//quit
nano hello.txt
//open the txt file hello.txt so you can edit it!
//Note - hit ctrl -X
Deleting files
rm -rf hannapak
//deletes the directory hannapak
mv hello.txt hi.txt
//rename the file
mv hello.txt documents/
//move the file to documents
mv hello.txt .
//move the file to the directory that I’m currently in
mkdir
//make directory
cp
//copy file
Users
whoami
//tells you what user your are logged in as
adduser
//add a new user (this command is specifically for ubuntu linux)
su mike
//switch user to “mike”
Permissions
Understanding how it works
//First we have the privileges are abbreviated as rwx
//Read - read the file
//Write - make changes
//Execute - programs can run
//Then we have the groups
//1. User
//2. Group
//3. Other
//And each group has their own set of priveages
u g o
rwx rwx rwx
//So....
rwxrwxrx
//Means everybody (users, groups and other) can read, write and execute
rwx------
//This means only the user can read, write and execute, groups and other can't do nothing
drwxrwxr
//d stands for directory
//Then we have octal numbers
0 - - -
1 - - x
2 - w -
3 - w x
4 r - -
5 r - x
6 r w -
7 r w x
//First column represents User, the second is group and the 3rd if other
//And the rwx is represented by a number r = 4, w = 2, x = 1
//and the numbers add up
//So if you do the math...
//777 means User, Groups and Everybody hence EVERYBODY can read write and execute
//755 means EVERYBODY can READ, but only the USER can change!
//644 means use can read and writre, everygody else can only read.
Change a file’s permissions
chmod u-r hello.txt
//turn off the READ permission for the user
chmod ug-r hello.txt
//turn off the READ permission for the user and group
chmod 777 hello.txt
//Change the permissions of a file to 777
Archiving files
//Compress a directory
tar -zcvf archive_name.tar.gz directory_to_compress
Last modified: November 12, 2018
Mark Endley