0% found this document useful (0 votes)
51 views11 pages

Linux Notes 1

Uploaded by

sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views11 pages

Linux Notes 1

Uploaded by

sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

==========================

Working with Linux Commands


==========================

whoami : To print logged in username

date : to print today's date

cal : to display calender

pwd : to display present working directory

ls : To list files and directories ( -ltr


options we can use)

$ ls -l (To display present


working directory content)

$ ls -l <dirname> (To
display given directory content)

mkdir : To create a new directory

$ mkdir <dirname>

rmdir : To remove empty directory

$ rmdir <dirname>
touch : To create empty file

$ touch linux.txt aws.txt


devops.txt

rm : To remove file

$ rm <filename> (it will


delete given file)

$ rm -r <dirname> (to
delete non-empty directories)

cat : Create file with data + Print file


data + Append data to existing file

$ cat > f1.txt


(create new file with data)

$ cat f1.txt (print


file data)

$ cat >> f1.txt


(append data to existing file)

$ cat f1.txt f2.txt >


f3.txt (To copy multiple files data into
single file)

cp : To copy one file data to another file

$ cp f1.txt f2.txt

cd : To change directory

$ cd <dirname>
(Going into that directory)

$ cd .. (come out
from directory)

wc : Word count

$ wc f1.txt

Note : It will give no.of lines, no.of words


and no.of characters of given file data.

tac : It is reverse of cat. (tac will print


file data from bottom to top)
$ tac f1.txt

head : To get file data from top

$ head <filename> (
It will print first 10 lines of data )

$ head -n 15
<filename> (it will print first 15 lines of
data)

tail : To get file data from bottom

$ tail <filename> (it


will print last 10 lines data)

$ tail -n 20 (it will


print last lines of data)

diff : To find differents between two files

$ diff f1.txt f2.txt

grep : Global Regular expression Print ( it


is used for file search )

$ grep 'devops' *
(It will search for devops keyword in all
files in the pwd)

$ grep -i 'devops' *
(It will search for devops keyword in all
files - case insensitive)

$ grep -i 'devops'
data.txt ( To search for data in given file )

============================
Working with text editors ( VI )
===========================

vi : Visual Editor

$ vi <filename> ==> It will


open the file

=> press 'i' to enter into insert mode

=> press 'Esc' to come out from insert mode

=> press :wq to save and quit the file


=> press :q! to close the file without saving
changes

===============
SED command
===============

=> SED standas for Stream Editor

=> This is command is used for substitution


(replacement)

=> Using SED command we can perform


operations on the file without opening it.

$ sed 's/Linux/Unix/' data.txt (It will


replace Linux with Unix and it will print on
console, it won't modify original file data)

$ sed -i 's/Linux/Unix/' (it will replace


Linux with Unix in original file)

$ sed -i '12d' data.txt (it will delete


12th line in original file)
=============
man command
=============

=> man command is used to get information


about given command (documentation)

$ man ls

$ man clear

$ man head

========================
User Management in Linux
=======================

=> Linux is multi user based Operating System

=> In one linux machine we can create


multiple user accounts

=> Mulitple users can connect with single


linux machine at a time and they can perform
Multi Tasking.
Note: In every linux machine by default one
'root' account will be avilable (super
account)

=> When we launch Linux VM using Amazon Linux


then we will get 'ec2-user' account by
default.

# To get user account infor we will use below


command

$ id <username>

Note: For every user one home directory will


be available in linux

ec2-user : /home/ec2-user

ashok : /home/ashok

john : /home/john

smith : /home/smith

root : /root
#Swtich to root user account

$ sudo su (it will switch to root account)

$ sudo su - (it will switch to root account


& will point to root user home directory)

$ exit (to exit from user account)

=========================
Create new users & Groups
=========================

# Switch to root user


$ sudo su -

# Add new user


$ sudo useradd <username>

# Set password for user


$ sudo passwd <username>

# Display users created


$ cat /etc/passwd
# Switch User account
$ su <username>

# delete user
$ sudo userdel <username>

# Delete user along with user home directory


$ sudo userdel <username> --remove

# Display all groups available


$ cat /etc/group

Note: When we create new user then user +


user group will be created.

# Create new Group


$ sudo groupadd <groupName>

# Adding user to group


$ sudo usermod -aG <group-name> <user-name>

# Remove user from the group


$ sudo gpasswd -d <username> <group-name>

# Display users belongs to group


$ sudo lid -g <group-name>
# display user belongs to how many groups
$ id <username>

# Delete Group
$ sudo groupdel <group-name>

# How to change username


$ usermod -l <login-name> <old-name>

You might also like