day-7-a-GCP Linux Basics
day-7-a-GCP Linux Basics
------------------------
Agenda:
step 1:
The linux is free to use and everyone have freedom to contributed to its
development. The code used to create linux is free and available to the
public to view, edit and for users with the appropriate skill to
contribute to
Wildcard chars
Package management
file permission
networking
archives (tar files)
search
file transfer
date
cal
free # allows you to check for memory RAM on your system or to check the memory
statics of the Linux operating system.
histroy # lists and annotates the last 1000 commands issued in the terminal
snap where the files and folders from installed snap packages appear on your
system
srv The /srv directory points to the location of data files for a specific
service.
For example, if you are running a web server,
your HTML files would go into /srv/http or /srv/www.
If you were running an FTP server, your files would go into /srv/ftp.
sys /sys is another virtual directory like /proc and /dev and
also contains information from devices connected to your computer
tmp used to store the data used by the system and user applications to
store the data that are needed for a short period of time
usr directory that contain files and utilities share bw the users
mkdir foo/bar
mkdir -p dir1/dir2/dir3
ls -R dir
cd
ls
various options
-l
-a
-t
-u
-r
-R
cd .
cd ..
cd ../../..
cd ~ : go to home dir
cd - : go to previous working dir
cat
more
less
head/tail
Ex:
head facts.txt
head -n 3 facts.txt
tail -n 2 facts.txt
Ex:
cp foo /foo2
cp cats.txt /tmp/cat2.txt
cp f1 f2 f3 /tmp
Ex:
mkdir d1 d2 d3
cp -r d1 d2 d3 /tmp
move dir
----------
mv d3 d2 put d3 inside d2
mv d1 d2 big
removing files
----------------
rm file1 file2
Ex:
cat demo.txt blabla 2> error.txt
cat demo.txt blabla 1> output.txt
du -u dir
wc -l f1.txt lines
wc -w f1.txt words
wc -c f1.txt char
wc f1.txt
sort facts.txt
sort -r facts.txt
grep :searches a file for a particular pattern of characters and displays all
lines that contain that pattern
ls | grep txt
https://www.geeksforgeeks.org/grep-command-in-unixlinux/
sed :SED command in UNIX stands for stream editor and it can perform lots of
functions on file like searching, find and replace, insertion or deletion
-d : delimiter
' ': seperator
f 1: first field
3 :third field
Wildcard chars
---------------
* ====> Match any char
? ==> Match single char
[char]====> Match char that are members of the set
ex [abc]
[!char]====> Not Match char that are members of the set
ex [!abc]
Ex:
ls -l *.txt
ls -l f*
ls -l ???
ls -l ???.txt
ls -l [af]*
ls -l [!af]*.txt
Package management
------------------
Package is compressed archive file that contains all the nessary file for a
particular s/w
to run
ex:
Configure apache2
cat /etc/os-release
systemctl list-unit-files # list all the servies that run in the background
like ssh cron
systemctl list-unit-files | grep ssh
Process Management
-------------------
A process in linux is a program in execution
it is a running instance of a program
any command that you execute start a process
Commands
---------
ps
kill
top
nice
umstat
df
pstree
free
ps -aux | more very useful commands display cpu memory usages very similar to
taks manager
ps -u username process related to some user
kill command:
-----------
Kill command send signal to a process to terminate, start stop etc
This can terminalte a process, intrept/ suspend/crash
you must own that process
or login as root user
example:
top command
--------------
top command display resouces cpu, ram occupied by processes
dynamically
used to monitor load on machine
TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through
hundredths of a second.
NI: Represents a Nice Value of task. A Negative nice value implies higher
priority,
and positive Nice value means lower priority.
RES: How much physical RAM the process is using, measured in kilobytes.
nice command
-----------------
nice and renine only super user cand run
renice: used to alter priority for running processes
nice: we can launch a process with user defined scheduling priorities
Ex
sleep 400 &
ps -eo pid,euser,stat,pcpu,pmem,ni,command
ps -eo pid,euser,stat,pcpu,pmem,ni,command | grep -i sleep
renice -15 5332
cat /etc/passwd
username: passwrd: user id: group id: comments: home dir: bash
gun
kesh
tester
ekta
vicky
adding users:
----------------
useradd -m -s /bin/bash gun
useradd -m -s /bin/bash kesh
cat /etc/passwd
------------------
gun:x:1002:1003::/home/gun:/bin/bash
kesh:x:1003:1004::/home/kesh:/bin/bash
ekta:x:1004:1005::/home/ekta:/bin/bash
vicky:x:1005:1006::/home/vicky:/bin/bash
cat /etc/group
group name: group pw: group id: hash value
gun:x:1003:
kesh:x:1004:
ekta:x:1005:
vicky:x:1006:
adding user to the group
-------------------------------
Primary group: login group
default same name as that of usre
only one
steps :
groupadd dev # creating dev group
usermod -aG dev gun # add gun to the dev group
usermod -aG dev kesh
id ekta
uid=1004(ekta) gid=1005(ekta) groups=1005(ekta),1007(dev),1008(tester)
su ekta
su - gun
ls -l demo.txt
ls -l demo.txt
-rw-rw-r-- 1 gun gun 23 Jan 6 05:54 demo.txt
File permission:
-------------
Every file is assigned permission to
3 different entities
R W X
4 2 1
owner
group
everyone else
ls -l demo.txt
-rw-rw-r--