Console basics
Permissions
Who?
u - user
g - group
o - others
r - read
w - write
x - execute
drwxr-xr-x
<!-- d - directory - user - group - others permissions -->
treehouse ~ $ chmod o+w hello.txt
drwxr-xrwx
<!-- now user have permission to write on hello.txt -->
treehouse ~ $ chmod +w hello.txt
drwxrwxrwx
<!-- everybody have permission to write on hello.txt -->
treehouse ~ $ chmod -w hello.txt
<!-- -w remove permission -->
treehouse ~ $ chmod 777 hello.txt
<!-- Also it can be done with numbers -->
-----------
File ownership
Each file and directory has a user owner, and a group owner. The ownership properties are important for determining how permissions are applied for each user.
chown - changes the owner of a file or directory
$ ls - l
$ sudo chown mike hello.txt (change user)
sudo - overrite any permission
$ nano hello.txt (read the file)
$ sudo chown mike:mike hello.txt (change user and group)
$ su mike (edit mike user)
$ nano hello.txt (read or edit the file)
----
Sudo
Sometimes you need to take on special privileges to perform an action. The sudo command allows you to override all permissions temporarily to get things done.
sudo - Run a command as the super user.
sudo !! - Run the previous command as the super user.
<!-- Console
The console is a text-based interface to your computer. It allows you to interact with files, folders and programs using text commands instead of windows, buttons and menus -->
command line
<!-- this is call prompt - treehouse = user name -->
treehouse ~ $
<!-- List files on directory -->
treeuse ~ $ ls
documents hello.txt
<!-- List files on directory long form -->
drwxr-xr-x 2 priscillarodriguez staff 68 May 14 21:39 Applications
Permission
r - read
w - write
x - execute
<!-- The ~ (tilde character) shorthand command refers to that particular user's home directory. -->
---------------
<!-- Home directory - $pwd -/Users/priscillarodriguez -->
treehouse ~ $ pwd
/home/treehouse
treehouse ~ $ cd documents <!-- Change directory -->
treehouse ~/documents $
<!-- See hello.txt content -->
treehouse ~ $ cat hello.txt
<!-- See hello.txt content -->
treehouse ~ $ less hello.txt
----------------
Editing Files
<!-- the program nano to edit the contents of a file inside the console.
^ (means control) -- >
treehouse ~ $ nano hello.txt
--------------
Rename a file
treehouse ~ $ ls
documents hello.txt
treehouse ~ $ mv hello.txt hi.txt
treehouse ~ $ ls
documents hi.txt
------------
Rename directory
treehouse ~ $ mv documents docs
treehouse ~ $ ls
docs
treehouse ~ $ mv docs documents
treehouse ~ $ ls
documents
-------------
Move a file to another directory
treehouse ~ $ mv hi.txt documents/
treehouse ~ $ ls
documents
treehouse ~ $ ls documents
hi.txt how_to_go_home.txt
treehouse ~ $ mv documents/hi.txt . <!-- move back and also I can rename it -->
treehouse ~ $ ls
documents hi.txt
------------
Copy files
treehouse ~ $ cp hello.txt hi.txt
treehouse ~ $ ls
documents hello.txt hi.txt
treehouse ~ $ less hello.txt
---------
Make a directory
treehouse ~ $ mkdir pictures
treehouse ~ $ ls
documents hello.txt pictures