0% found this document useful (0 votes)
2 views

Linux Print1

This document provides a comprehensive guide to basic Linux commands, including file and directory management, user and group management, disk usage commands, and file permissions. It also covers advanced topics such as symbolic and hard links, compression commands, and the use of the sed command for text manipulation. The information is structured in a clear manner, making it a useful reference for users looking to enhance their Linux command line skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Linux Print1

This document provides a comprehensive guide to basic Linux commands, including file and directory management, user and group management, disk usage commands, and file permissions. It also covers advanced topics such as symbolic and hard links, compression commands, and the use of the sed command for text manipulation. The information is structured in a clear manner, making it a useful reference for users looking to enhance their Linux command line skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1

***** Some basic command of LINUX ****


1. mkdir :- make new directory
2. mkdir -p :- create directory and subdirectory
3. touch :- crate new file (if want create a file which already exit in that directory then it will change time stamp of the file)
4. cd :- change directory
5. cd ~ :- change to home directory.
6. cd / :- change to root directory.
7. cd .. :- one directory back to parent directory.
8. cd ../.. :- two directory back to parent directory.
9. cd - :- change to previous directory.
10. rm :- it will remove file.
11. rm -r :- it will remove directory.
12. rm -rf :- it will remove recursively and enforce the file.
13. cat :- for opening a file.
14. cat file_1 > file_2 :- it will delete the content of “file_2” and paste the content of “file_1” .
into “file_2.”
15. cat file_1 >> file_2 :- paste the content of “file_1” into “file_2” without deleting the content
. of file_2.
 less key.txt : To scroll forward: Ctrl-f
 To scroll backward: Ctrl-b
 To end of file: G
 To quit less command: q
16. pwd :- print working directory.
17. cp :- used for copy.

eg.
(i).cp file_1 Download/ :- it will copy “file_1” into “Download” directory.

(ii).cp file_1 file_2 :- it will delete the content of “file_2” and paste the content of
“file_1” into “file_2”.
(iii).cp –a :- it will copy directory (cp –a d1/d2/ )
(iv).cp –v :- it will paste copied file into directory.

18. mv :- move and rename file.

(i) mv file_name directory/ :- move file into directory.

(ii) mv file_name new_name :- rename file.

19. tty :- revels the current terminal.


20. whoami :- shows logged user name.
21. history :- display command history. ( !262: It runs the 262 command)
22. head :- display opening lines of file.
23. tail :- display closining lines of file.
24. wc :- word count.
2

25. wc –l :- print the no of line in file.


26. nano and vi :- for editing files.
27. alias :- for creating shortcut for particular command.(alias s=‘sudo apt’)
28. unalias :- for undo alias(unalias s)
29. free :- for checking free ram and usage.
30. w,users,finger :- display user list.
31. ifconfig :- show physical ip address.
32. iftop :- show network related operation.
33. scp :- secured copy between two servers.
34. netstat :- for check port is listening or not in same server.
netstat -tupl : It lists all active listening ports
35. telnet :- for check port is listening or not in different server.
36. ch own :- change ownership.
37. ps :- check process id.
38. man <cmd> :- It shows the manual of command.
39. stat :- It reveals statistics of files(stat <filename>)
40. seq :- It echoes a sequence of numbers.
41. file :- It determines the file type.
42. whereis :- It display all paths
43. id : It display id info of current user
44. uptime :- It display for how long the system has been running
45. who :- It display users logged in the system with their respective terminals and time since logged in
46. top :- It displays all running processes
47. ip addr show :- It displays all network interfaces and ip address
48. wget :- It is used to download file

----------------------------------------------------------------------------------------------------------

 Ownership in linux

chmod : - change mode

777
owner group other/world
Read = 4
Write = 2
Execute = 1
eg. chmod 400 filename (read only permission to user/owner only)
NOTE: Use 777 sparingly!
---------------------------------------------------------------------------------------------------------------------------------------------------------------
3

 Compression in linux

 zip :- this zip command is used in linux for compress a file into zip file format

zip filename.zip *
zip –p filename.zip * (with password)
zip –e filename.zip *

 unzip :- this command is used for unzip the zip file

o unzip filename.zip
o unzip --ql key.zip *.txt : It quietly unzips the file

 Gunzip :- (for gz to a file)

c - for creation of zip


x - for unzip
f - forcefully
v - verbosely
z - zip

gzip –c filename > filename.gz

 tar :-
o tar -cf filename.tar *.txt : It will create a tar file.
o tar -xf filename.tar *.txt : It is used to extract the compressed file
o tar -cvfz um.tar.gz um.img
o tar -czf filename.tar.gz directory name : It create a tar with gzip
compression

o tar –cvfz filename filename.tar.gz

 untar :-

tar –xvfz filename.tar.gz


----------------------------------------------------------------------------------------------------------

 ls command

1. ls :- list the content.


2. ls –a :- list hidden files.
3. ls –l :- list in long listing format.
4. ls –al :- list sub content in long listing format.
5. ls –ld :- list long listing format the directory.
6. ll :- list in long listing format.
7. ls –ltr :- sort from old to new(sort by time)
4

8. ls –R :- list Recursively
9. ls –F :- list the content and classify them.
10. ls –r :- in reverse order.
11. ls –lS :- sort by size.
12. ls –i :- show inode number.
13. ls –version :- show the ls version.
14. lscpu :- show information about cpu.

 top command

1. q :- for exit from top command


2. c :- show absolute path of running process.
3. k :- kill the process.
4. r :- change priority of the process.
5. 1(one) :- check cpu cores.
6. i :- list ideal process.
7. shift + p :- short process by cpu usage.
8. shift + m :- short process by memory usage.
9. z :- display running process in colour.
10. d :- change interval time.(default is 3 sec)
11. top –n | -b > to –otput.txt :- to save running command result output to a file /root/toprc

----------------------------------------------------------------------------------------------------------

 Linux Groups

 Linux groups are organization units that are used to organize and administer user
accounts in Linux.

 The primary purpose of groups is to define a set of privileges such as reading, writing,
or executing permission for a given resource that can be shared among the users
within the group.

 There are two types of groups in Linux operating systems:

1. The Primary group :–

 When a user creates a file, the file’s group is set to the user’s primary group.

 Usually, the name of the group is the same as the name of the user.

The information about the user’s primary group is stored in the /etc/passwd

2. Secondary or supplementary group :–


5

 Useful when you want to grant certain file permissions to a set of users who are
members of the group.

 For example, if you add a specific user to the docker group, the user will inherit the
group’s access rights and be able to run docker commands.

 Each user can belong to exactly one primary group and zero or more secondary
groups.
Note :- Only root or users with sudo access can add a user to a group.

 How to add an existing user to group


To add an existing user to a secondary group, use the usermod -a –G

sudo usermod -a -G groupname username

For example, to add the user linuxize to the sudo group, you would run the following command:

sudo usermod -a -G sudo linuxize

Always use the -a (append) option when adding a user to a new group. If you omit the -a option,
the user will be removed from any groups not listed after the -G option.
On success, the usermod command does not display any output. It warns you only if the user
or group doesn’t exist.

 How to Add an Existing User to Multiple Groups in One Command


If you want to add an existing user to multiple secondary groups in one command, use the
usermod command followed by the -G option name of the group separated by , (commas):

sudo usermod -a -G group1,group2 username

 How to Remove a User From a Group


To remove a user from a group, use the gpasswd command wit the -d option.
In the following example, we are removing the user username from the group groupname:

sudo gpasswd -d username groupname

 How To Create A New Grop


To create a new group, use the groupadd command followed by the group name

Sudo groupadd groupname

for delete group


sudo groupdel groupname

 How to Change a User’s Primary Group


To change a user primary group, use the usermod command followed by the -g option:

sudo usermod -g groupname username


6

In the following example, we are changing the primary group of the user linuxize to
developers:

sudo usermod -g developers linuxize

 How to Create a New User and Assign Groups in One Command

The following useradd command

sudo useradd -g users -G wheel,developers Nathan

 Display User Groups


To display complete user information, including all the groups of which a user is a member of,
use the id command followed by the username:

id username
----------------------------------------------------------------------------------------------------------------
 du (Disk Utilization)
a. Specify maximum depth

We can make this more useful by specifying how deep we should check with
--max-depth, which can be shortened to the -d option.
By setting this to 1, we will look 1 directory deep and display the size in use of all directories
within the current location.
Du -d 1

b. Human readable output


du -h -d 1 /

c. Show disk usage for files


Now we can see the space used within the directories as well as the specific files within.
du -h -d 2 -a
d. Report total disk space
With the -c option we can have the total space reported at the bottom of the output
du -h -d 2 –c

e) Sort output by disk usage size


While not built into the du command, we can pipe it to the sort command in order to list files
in order of file size, such as smallest to largest. This is extremely useful as we can search the
whole disk and order the output based on file size, allowing us to quickly locate large files.
du -h -a / | sort -h | tail -n 15

f) Show last modification time


While searching for files using disk space to potentially be removed it can be beneficial to view
the last modified time stamp. For example if used disk space is increasing over time then the
most recently modified files are a good place to investigate, for instance we may have a large
log file that is constantly being modified and written to.
du -h -d 1 --time –a
7

g) Only show larger than specified size


This may be helpful if we want to search for files larger than a specified size which would be
useful in finding large single files that may be using the majority of your disk space.
du -h -t 100M -a /

h) Exclude pattern from search


With the --exclude option we can optionally not show anything that matches a specified
pattern in the search results
du -h -d 1 -a --exclude="*.txt"

i) Piping du
This will search your entire file system sort the results by size and then show only the top ten
results. It’s essentially a shortcut for the top ten largest files on your machine
du -a / | sort -n -r | head -n 1
----------------------------------------------------------------------------------------------------------------
 df
1. Running df
If we run the df command with no options, it will print out disk usage information
for all mounted file systems Df.

2. Print Totals
So far with df we can print out the usage of each individual file system. With the
--total option we can get an overall result
df --total –h
----------------------------------------------------------------------------------------------------------------

 sed command
 sed command is stand for stream editor
 it can perform searching,finding,replacement and deletion

sed ‘s/Unix/Linux/g’ textile


o ‘g’ = global
o ‘p’ = print falg :- it duplicate replaced line.
o ‘^’ = for starting of line.
o ‘$’ = for ending of line.
o ‘-i’ = for permanent change.
o ‘d’ = for deletion.
o ‘b’ = eaxact same word.
o ‘n’ = print only replaced line
1. Change Every Occurrence Of Word :

sed ‘s/1st/2nd/g’ textfile


2.Chnage The Word Which Present At Starting :

sed ‘s/^1st/2nd/g’ textfile


8

3.Chnage Only Last Word :

sed ‘s/1st $/2nd/g’ textfile

4.Change Exact Same Word :

sed ‘s/\b1st \b/2nd/g’ textfile


5.Replacing Particular Position Of Same Word :

sed ‘s/1st /2nd/2’ textfile


6.Replacing From A Particular Position Of Word To All Next Word :

sed ‘S/1st /2nd/3g’ Textfile


7.Replacing With Specific Line No:

sed ‘3s/1st /2nd/g’ textfile


8.Duplicate Replaced Line:

sed ‘s/1st /2nd/p’ textfile


9.Print Only Replaced Line:

sed -n ‘s/1st /2nd/p’ textfile


10.Replacing Range Of Line With Specify :

sed ‘1,3 s/1st /2nd/p’ textfile

##Deletiton##
1. for particular line delete :
sed ‘nd’ filename

2. Delete last line :


sed ‘$d’ filename

3. To delete range from x to y:


Sed ‘x,yd’ filename

4. Delete nth to last line:

sed ‘12,$d’ filename


9

5. To delete pattern matching line:

sed ‘/pattern/d’ filename

6. Delete hole line which have word in command:

sed ‘/unix/d’ textfile

------------------------------------------------------------------------------------------------

 Symbolic Link
Softlink 1

1. Soft-Link: Original file

Also known as symlink or symbolic link. Softlink 2

ln –s ‘filename’ ‘soft-link name’


(i) It has different inode number.
(ii) It consume space.
(iii) If we delete main file then soft-link become empty.
(iv) Not bounded on file system.
(v) Dependent on original file.
(vi) If change in original file no change in soft-link.
(vii) We create file and directory also.

2. Hard-Link: Original file Hard-link

ln ‘filename’ ‘hard-link name’


(i) It has same inode number.
(ii) Exact copy of original file.
(iii) It consume less space.
(iv) If we change in main file then hard-link also get change.
(v) It cannot be used in directories
(vi) If we delete main file then hard-link remain.
(vii)
10

 LINUX BOOT PROCESS

1. BIOS
2. MBR
3. GRUB
4. KERNAL
5. INIT
6. RUNLEVEL PROGRAM

1. BIOS
 BIOS stands for Basic Input/Output System
 Performs some system integrity checks
 Searches, loads, and executes the boot loader program.
 It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on
your system) during the BIOS startup to change the boot sequence.
 Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
 So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR
 MBR stands for Master Boot Record.
 It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
 MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition
table info in next 64 bytes 3) mbr validation check in last 2 bytes.
 It contains information about GRUB (or LILO in old systems).
 So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB
 GRUB stands for Grand Unified Bootloader.
 If you have multiple kernel images installed on your system, you can choose which one to be executed.
 GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as
specified in the grub configuration file.
 GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
 Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of
CentOS.

4. Kernel
 Mounts the root file system as specified in the “root=” in grub.conf
 Kernel executes the /sbin/init program
 Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’
and check the pid.
 initrd stands for Initial RAM Disk.
 initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It
also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init
 Looks at the /etc/inittab file to decide the Linux run level.
 Following are the available run levels
 0 – halt
 1 – Single user mode
 2 – Multiuser, without NFS
 3 – Full multiuser mode
 4 – unused
 5 – X11
11

 6 – reboot
 Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
 Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
 If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means,
probably you might not do that.
 Typically you would set the default run level to either 3 or 5.

6. Runlevel programs
 When the Linux system is booting up, you might see various services getting started. For example, it might say
“starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your
run level.
 Depending on your default init level setting, the system will execute the programs from one of the following
directories.
 Run level 0 – /etc/rc.d/rc0.d/
 Run level 1 – /etc/rc.d/rc1.d/
 Run level 2 – /etc/rc.d/rc2.d/
 Run level 3 – /etc/rc.d/rc3.d/
 Run level 4 – /etc/rc.d/rc4.d/
 Run level 5 – /etc/rc.d/rc5.d/
 Run level 6 – /etc/rc.d/rc6.d/
 Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to
/etc/rc.d/rc0.d.
 Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
 Programs starts with S are used during startup. S for startup.
 Programs starts with K are used during shutdown. K for kill.
 There are numbers right next to S and K in the program names. Those are the sequence number in which the programs
should be started or killed.
 For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the
sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.

There you have it. That is what happens during the Linux boot process

N/W HDFS SERVICES


PROTOCALL
Process Port no
SERVICE DEFAULT PORT PROTOCALL

FTP 21 & 22 NAME NODE WEB UI 50070 HTTP


NAME NODE WEB UI 50070 HTTPS
SSH 22 (secure)
NAME NODE 8020/9000 IPC
TELNET 23
DATA NODE 50075 HTTP

SMTP 25 DATA NODE 50475 HTTPS


(secure)
DNS 53
DATA NODE 50010 IPC
DATA NODE 50020 IPC
HTTP 80
DATA NODE 0.0.0.0:8010 IPC
HTTPS 443 SECONDARY 50090 HTTP
NAMENODE
NTP 123
12

You might also like