1-linux basics
1-linux basics
----------------------------------------
Agenda:
Linux Operating system
Ubuntu commands with AWS vm instance
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
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
cd
ls
various options
-l long and details listing
-a hidden files
-t sort by modification time
-u access time
-r reverse listing
-R list sub directories
mkdir -p dir1/dir2/dir3
ls -R dir
cd .
cd ..
cd ../../..
cd ~ : go to home dir
cd - : go to previous working dir
cat
more
more /etc/services
less
head/tail
Ex:
head facts.txt
head -n 3 facts.txt
tail -n 2 facts.txt
Ex:
cp hi.txt raj/
cp cats.txt /tmp/cat2.txt
cp f1 f2 f3 /tmp
Ex:
mkdir d1 d2 d3
cp -r d1 d2 d3 /tmp
mv cats.txt /tmp
mv f1 f2 f3 /d2
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
reading both std op and std error to the same file:
cat demo.txt blabla > all.txt 2>1
discarting errors
cat blabla 2> /dev/null : /dev/null is just like gc
du 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
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
https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/
-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: process state
------------------
ps : process of current terminal
ps -e : all process informations
ps -ef : full formate
ps -ef | more
ps -ef | grep -i ssh
ps -ef | grep -i apache
ps -aux | more very useful commands display cpu memory usages very similar to
taks manager
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:
PR: The process’s priority. The lower the number, the higher the priority.
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
dev:
gun
kesh
tester:
ekta
vicky
----------------
switch back to root user:
su
and provide the password
--------------------------
cat /etc/group
group name: group pw: group id: hash value
gun:x:1003:
kesh:x:1004:
ekta:x:1005:
vicky:x:1006:
steps :
groupadd dev # creating dev group
usermod -aG dev gun # add gun to the dev group
usermod -aG dev kesh
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--