Drupal offers an excellent set of videos to walk you through cmd or command line basics for Unix/Mac. Below are some notes from the first 3 videos. For check here for Dos/Windows commands.

Moving Around the Command Line

From https://drupalize.me/series/command-line-basics-series

The cmd command line directory format:
machine: ~ directory username

pwd
Prints the current working directory (shows you where you are)
/Users/addi

ls
Displays a list of what is in the directory

ls -al
List all (provides more details) does not seem to work on Windows.
items beginning with a d are directories
items beginning with a are files
in linux, items beginning with a dot are hidden files
ls -al shows the hidden items

cd
Change directory
You can type first letter of directory and hit tab for auto compete, if not show, hit tab again it will show list of options – this is case sensitive. If you get lots of file results in ls, you can use piping, (|) this passes a command into another command.

pipe
ls | less
pipe less command
shows things as pagination
space bar moves to next page
q quicks out of less

cd ..
moves you back one to move back up directory
cd drupal/
ls
cd docs/
ls
cd ../..
takes you up two directories/

~
or cd
gets you back to home directory
cd /User/addi/drupal/docs
can go to specific directory
cd /Applications
Using / can get you above the root directory
by starting with /

man
manual help
man pwd tell you help about pwd (not always work)
q quit out of man page

clear
clears entire screen mac
cls is clear screen on windows

https://drupalize.me/videos/copy-move-delete-command-line?p=1149
Copy Move Delete

cp
copy
cp -r stuff/ more_stuff
Copies folder named stuff, and creates more_stuff folder (sibling of stuff)
the -r is necessary for copying folders (directories),
cd more_stuff/
ls

mkdir
make a directory
mkdir stats
makes a directory called stats in the current more_stuff directory
ls -al
gives details about items in more_stuff, see details about new stats directory
cp Drupal_January.ods stats/
Copies .ods file (in current directory) into stats folder
ls shows .ods file still in current more_stuff folder
cd stats/
ls
shows .ods file also in stats folder (copy)
cd .. (go up one)

rm
remove delete file from current directory
rm Drupal_January.ods
ls shows no longer there
rm -r garbage/
removes deletes directory from current directory (need -r for directories)

mv
move command
mv drupapal_commands.ods stats/
moves .ods file from current directory to stats folder. Can move to sibling directory w/ ../sibling

*
wildcard

mv 200* junk/
moves all files beginning with 200 to the (child) junk/ directory
mv *jpg junk/
moves all files ending w jpg

Renaming: use mv for renaming files
spaces in names not good
Design Eye for the Geek Guy.pdf
can rename using mv
mv Design\ Eye \ Eye\ for\ the\ Geek\ Guy.pdf design-eye.pdf
changes name to design-eye.pdf

Command Line Permissions
https://drupalize.me/videos/dealing-command-line-permissions?p=1149

sudo
on unix – allows temporary escelation of own priviledges (not Windows)
ls -al shows permissions info of files,
If starts with a d = directory
If starts with a w – it is a file
drwxr-xr-x
-rw-r–r–@ 1 addi staff 614 Apr 27 10:26 .DS_Store

Permissions
first set of characters is for user permissions, –rw-
(user is addi)
second set permissions for group r–
(group is staff)
third set, permissions for everyone else r–
@ symbol is not important for now
r = read
w = write
x = execute (for folders x means can go into folder, for files x means can run script)

chmod
Changing mode, to change permissions
u = user
g = group
o = other
a = all

example: can change group and other together
to remove use minus sign (-)
chmod go-rx stuff/
removes read and execute permissions for group and others in the stuff directory
ls -al
To see stuff folder premissions have changed
go+rx stuff/
adds back permissions
For directories, if you want to change permissions on all included files need to add -r directory/

Ownership
can change ownership
root is super user
typically not use root, but can temporarily be root user with sudo

chown
change ownership and group
chown root getdrupal.sh
may not have authority: Operation not permitted

sudo
sudo chown root getdrupal.sh
need password
will let you change ownership of file to root

can change owner and group name together
sudo chown addi:staff getdrupal.sh

ls -al shows owner and group names changed.

chgrp
allows change just the group

When you use sudo to copy a file, it creates the file with root as the owner
if want to change the owner from root to name (addi)
sudo chown addi settings.php

Do not want everybody to have write access, you can set all to read only with
chmod a=r settings.php