You are on page 1of 5

echo 'hello world' => prints hello world on screen

exit => close session/exit program


Up/Down arrows => review previous commands
ctrl + a => move cursor to start of line
ctrl + e => move cursor to end of line
tab => try to complete the command of filename
tab + tab => when tab doesn't complete, show list of sugestions

COMMAND STRUCTURE:
command + options + arguments
command => always 1 single word
options => options are optional
arguments => arguments
ex command without optiond
# echo 'hello world'
ex command with optiond
# echo -n 'hello world'

Options can be writen separatly or togheder:


# ls -l -a -h Desktop
# ls -lah Desktop

Options can have arguments:


# banner -w 50 'hello world'
# banner -w50 'hello world'

Write 2 or ore commands on a line, split them with semicolon ;


# echo 'hello'; echo 'world'

Kernel: - core of OS, alocates time & memory to programs


Shell : - what we see when we open a terminal
- shell sends requests to kernel
- macOs uses bash shell
- shells: sh, csh, tcsh, ksh, bash, zsh
- to enter/use one shell just type shell name: #sh, #bash
- to exit selected shell use: #exit

Environment variable:
- starts with $
- all capital letters
# echo $SHELL => prints login shell
# echo $0 => prints the shell we are using right now

Manual Pages => help about commands


command: man + what we want to find
ex: #man echo
: => tells us there is more, : is the new prompt, like vim
spacebar => pressing space will show next page
f, b => use f and b for FORWARD AND BACK in pages
q => exits man pages

UNIX FILE SYSTEM:


pwd => presend working directory
ls => list content of current working directory
ls -l => list content of current working directory but with more info
ls -la => list content of current working directory but with more info
un punct ( . ) inseamna directorul in care sunt acum
.. se refera la directorul parinte
fisierele care incept cu . se numesc DOT FILES pentru ca incep cu un punct.
DOT FILES sunt fisiere invizibile de configurare
cd => change directory
cd Desktop => change present directory and goes to desktop
cd .. => change present directory and go back to parent directory
cd Users/Marian/Desktop => change present working directory and go to
Users/Marian/Desktop
cd ../.. => move back 2 directoryes
cd ~ => moves to home folder
cd - => toggles between current directory and last directory

NAMING FILES:
- max 255 chars
- no simbols
- use: A-Z, a-z, 0-9, .(perios), _(underscore), -(hyphen)
- don't use - as first character
- use lowercase
- underscore are better then spaces
- add extension to files (.txt)

CREATE A FILE
3 WAYS:
1 - unix text: nano some_file.txt
2 - direct output to file
3 - touch files: touch some_file.txt

READING FILES
- cat -> concatename - shows the content of a file: cat test.txt or cat
test.txt test_again.txt
- more -> pagination - hit space for next pack, no back option (obsolete)
- less -> pagination - hit space for next pack, with back option
: # space = next page
# f/b = forward/back
# g = go to star
# G = go to end
# q = quit
- head - displays first 10 lines of the file
- tail - displays last 10 lines of the file
# head .var/log/system.log // system logs
var/log/apache2/acces_log
var/log/apache2/error

CREATING DIRECTORIES
mkdir testdir = make direcotory testdir
mkdir lynda_learn_unix/test1/test2

mkdir -p test1/test2 => create all parent directories

MOVE FILES
mv fileName path (absolute path or relative path)
FILES |
FOLDERS
mv testFile.txt testFolder OR | mv folder testFolder
mv testFile.txt ../parentFolder OR | mv folder
../parentFolder
mv testFile.txt .. | mv
testFile .. |

RENAME
- use mv to rename
FILES |
FOLDERS
mv myFile1.txt myFile2.txt | mv folder1
folder1_renamed
mv myFile1.txt testFolder/myFile2.txt | mv folder1
targetFolder/folder1_renamed

FLAGS:
-n no overwriting
-f force overwriting
-i interactive overwriting, "prompts confirmation"
-v verbose (some aditional info)

move has -f by default and it will overwrite files


tip: always use v for more info

COPY FILES JUST LIKE MOVE BUT WITH cp COMMAND


- copy folder: cp -R testFolder parentFolder

DELETE - DELETES FROM TRASH AS WELL


Delete file: rm test_file.txt
Delete folder: rmdir testFolder (works only for empty folders)
Delete folder: rm -R testFolder

LINKS / ALIASES / SHORTCUTS


# HARD LINKS: ln targetFile/source (or path to file) nameOfTheShortcut
- ln yt_acc.txt ytacc_shortcut
- ln ~/Downloads/yt_acc.txt ytacc_shortcut
- does not break if the file is removed or deleted
- keep track of the file on the HDD and points to them
- it's almost like a copy of the original file but editing the 'copy' will
edit the original

# SYMBOLIK LINK: ln -s targetFile/source (or path to file) nameOfTheShortcut


- ln -s yt_acc.txt ytacc_shortcut
- ln -s ~/Downloads/yt_acc.txt ytacc_shortcut
- keep track of the path / in ce director se afla fisierul (ca o scurtatura
normala)
- it's a link to the file
- break if file is moved or deleted

SEARCH:
# find whereToSearch whatToSearch
# find ~/Documents -name 'branza.jpg' => go in Documents find files img with
the name of branza.jpg
# WILDCARD CHARACTERS:
- * = 0 or more characters
- ? = any 1 character (1 singur caracter de orice tip)
- []= orice caracter dintre paranteze
# find -name "yt_acc.txt" / cauta yt_acc.txt
# find -name "yt_acc.???" / cauta yt_acc. urmat de orice 3 alte caractere
# find -name "yt_acc.*" / cauta yt_acc. urmat de orice alt caracter
# find -name "*.txt" / cauta orice fisier care se termina cu .txt
# find -name "index[123].html" / index1.html sau index2.html sau
index3.html
# find -name *.plist -and -not -path *QuickTime*
cauta tot ce se termina cu .plist si orice care nu are quick time in path
ROLES / GROUPS / WHO AM I ???
$whoami = returneaza userul logat
- Grups = a set of users
- A user belongs to AT LEAST ONE GROUP, A PRIMARY GROUP
- Grupurile se folosesc pentru a asocia un set de useri cu un fisier sau cu o
anumita permisiune sau cu anumite comenzi
- permisiunile se dau grupului iar automat toti userii din acel grup primesc
permisiune pentru ca sunt membrii grupului
$groups = arata toate grupurile din care faci parte

FILE AND DIRECOTORY OWNERSIP


$ls -la
> pe coloana 2 avem OWNERUL
> pe coloana 3 avem GRUPUL din care OWNERUL face parte

- putem da permisiuni in functie de user sau de grup


- orice fisier creat de userul curent va avea:
> OWNERUL CURENT (cel carea creat fisierul (userul curent))
> GRUPUL va fi grupul default al userului curent, cel care a creat fisierul

CHANGE OWNERSHIP
- schimbarea OWNERSHIP-ului se face prin comanda: chown care inseamna change
ownership
syntax: $chown + numeUserului + fisierul sau folderul care dorim sa ii schimbam
ownershipul
$chown + numeUserului:dinGrupul(numeGrup)
ex: current user = marian
FILES:
> $chown sandra acc.txt -> schimba ownerul fisierului acc.txt in sandra
> $chown sandra:staff acc.txt -> schimba ownerul fisierului acc.txt in sandra
din grupul STAFF
> $chown :staff acc.txt -> schimba grupul fisierului acc.txt la grupul
staff
Change files ownership:
> $sudo chown sandra:staff acc.txt -> schimba ownerul fisierului acc.txt la sandra
din grupul staff

FOLDERS:
> $chown sandra testFolder -> schimba ownerul folderului testFolder in
sandra
NOTE: comanda de mai sus schimba doar ownerul folderului, NU SI OWNERUL
CONTINUTULUI FOLDERULUI
- pentru a realiza asta folosim flagul de recursivitate: -R

> $chown -R sandra:staff testFolder -> schimba ownerul folderului testFolder


in sandra din grupul staff
- se poate si fara a preciza grupul din care face parte
$chown -R sandra testFolder -> schimba ownerul folderului testFolder in
sandra

> $chown :staff testFolder -> schimba grupul folderului testFolder la grupul
staff
> $chown -R :staff testFolder -> schimba grupul folderului testFolder la
grupul staff
Change folder ownership
> $sudo chown sandra:staff acc.txt -> schimba ownerul fisierului acc.txt la sandra

You might also like