linux commands (1)
linux commands (1)
4. What are the Differences between Linux and Windows Operating System?
11. What is Run Level? What are the Run Levels present in Linux Operating
System?
12. What is Shell? What are the Various Shells Present in Linux Operating
System?
=======================================================================
Linux Basics
Privileged User(root)#
Unprivileged User$
Basic Commands
1. uname : It is useful to know the Flavour of Operating System
uname -r : Display the Linux Kernel Version no
uname -a : Display the Complete Information about the Linux Machine
12. who : Display the Information about the Current Login Users and
Terminals
who -r : Display the Current Runlevel of the Linux OS
18. w : Detailed Information about all the Login Users and Terminals
19. last : Current Login User Login and Logout Details Information along
with system boot Information
last <username>: Login and Logout Details of the given user
25. alias : Display the List of alis command present in the Current Shell
and also useful to create the alias commands
alias today='date +%d-%B-%Y'
28. top : Display the Dynamic view of all the running services
information
q : quit
k : Close/kill the Application
31. jobs: Display the List of background Jobs in the current terminal
34. <processname> & : Start and Running the Process in the Background.
top &
Keys:
ctrl + c -> Useful to terminate the Process
ctrl + z -> Useful to send the Running Process to Background
ctrl + d -> End of the File
37. traceroute
38. nslookup
39. dig
40. netstat
41. route
43. ifconfig
Genral Commands
-------------------------------
44. hostname : Display the Linux Machine Name
52. lsof : Display List of open Files Information in the Linux System
54. whereis <commandname>: Display the Location of the Command and the
Command Manual Information.
By using printf and echo we can print the Environment Variable Values
and also command outputs. $variablename/$(command)
printf "$PATH"
echo "$HISTSIZE"
printf "My name is $(logname) and Today Date is $(date)\n"
Help Commands: Useful to know the Purpose and the Subcommands information
1. <commandname> --help
Ex: date --help
Note: View is not much good
2. info <commandname>
Ex: info date
Note: info is a Help Application with the Chain of Commands.
u: Up p->Prev n->next q->quit
Note: View is not much good and information is not Elabirated.
3. whatis <commandname> : Know the Purpose of the Command
Ex: whatis date
Whatis having it's own database to store the commands
information.Whatis command everyday run the job to get update from the
manuals present in the linux machine.
makewhatis: Update the whatis database manually(root only)
4. man <commandname>:
Ex: man cal/man date
man look for the given command from 1 to 8 and it will display
the information from the chapater where it intially exist.
q-> Quit
/expression: Highlight the Given Expression
======================================================================
Absolute PATH:PATH Start from /. Every Directory Has the Absoulte path to
access the directory from any where in the File System.
/root/Classes/aug2014/Test
Relitive PATH:PATH Start from Current Working Directory. This PATH
changes from location to location.
From Classes: aug2014/Test
From root: Classes/aug2014/Test
Note: relitive PATH is useful to access the Sub Directory
Structure.
5. ls -i : Inode Nos
Display the List of Files and Directories Start with D and end with
s
ls -l -d D*s
ls -l -d [p-t]*
4. Move or Rename
mv <src> <dest>
Case1 : Destination Does not Exist
Rename the Source file with Destination Name
5. Copy File
cp <src> <dest>
cp -p <src> <dest>: Preserve the Source file Properties to
the Destination File.
Case1: Destination Does not Exist
Create Another Copy of Source with Destination Name
Link Files
Linux has 2 Types of Link Files
1. Hard Links
Create an alias file to the existing file.Internally it
create a new file entry in the directory by copying the i-node no of the
exitsing file with out allocate any memory.
1071015
+------------------------------------------------------------------
---+
We are in the Class
and class is very boring but we are smiling
12
23
35
+------------------------------------------------------------------
----+
Test Directory
===================================================================
=====
1071006 .
1070881 ..
1071015 class
1071023 info
1071014 test1
1071015 boom
1071024
+------------------------------------------------------------------
---+
class
+------------------------------------------------------------------
---+
1071015
+------------------------------------------------------------------
---+
We are in the Class
and class is very boring but we are smiling
12
23
35
+------------------------------------------------------------------
----+
Test Directory
===================================================================
=====
1071006 .
1070881 ..
#1071015 class
1071023 info
1071014 test1
1071024 india
Index Node Table
===================================================================
======
1071006 drwxr-xr-x. 3 root root 4096 Sep 2 11:44
1070881 drwxr-xr-x. 4 root root 4096 Aug 30 09:47
#1071015 -rw-r--r--. 2 root root 64 Sep 2 11:44
1071023 drwxr-xr-x. 2 root root 4096 Sep 2 11:44
1071014 -rw-r--r--. 1 root root 25 Sep 2 11:44
1071024 lrwxrwxrwx. 1 root root 5 Sep 2 11:44->class
=======================================================================
Compress Files and Directories
1. gzip <filename>: Compress the Given file and replace with the
new file named filename.gz
2. zcat <filename.gz>: It will diaplay the content in the
Compressed file with out Uncompress the file and the file is a Text file
k(up)
j(down)
l(right)
h(left)
Note: Arrow key also working
Teamviewer: We can get the Desktop and Control of the Remote machine to
perform the Operation in the Remote Machine.
Note: root user of the remote machine telnet login is diabled because of
telnet is not secured.(Plain text Authauntication)
---------------------------
How to Connect the Linux Machine using SSH Protocol?
Secured Shell, Port NO: 22
Note: Root user of the remote machine can login using ssh protocol
because of it is Secured with the RSA Algorithm for password
authauntication.
------------------------------
Assignment:
What is the RSA Algorithm and how it is provide the security to the
SSH Protocol?
What is RDP?What are Port Nos using by the RDP?
======================================================================
Scheduling Commands
useful to run a job/task automatically at the given time.job can be
a command or an application.
2 Types of Applications
1. Foreground Applications: Application which is required running
user terminal.
Ex: cal
Note: Root user can scheduling a job to run very user login time
using the file /etc/bashrc
Running -> Jobs in /etc/bashrc then user Jobs present in
~/.bash_profile
2. Logout Scheduling: Every User in Linux has a file in the user home
directory with the name .bash_logout. add the job in the following file
with out distrubing the exitsing content.
vi ~/.bash_logout
wall " Have a Nice Day"
cal
sleep 3 #Suspend the Execution for given no of seconds
at noon/teatime(4PM)/midnight
======================================================================
Change the Date & Time
date mmddhhmmyyyy
date 091017152014
Control the Crontab Service
service crond restart
======================================================================
Redirection Commands/Characters
1. >(Overwrite) and >>(Append)
command>filename
command>>filename
Redirect the Left Side Command output to the Right side File.
2. | (PIPE)
command1|command2
Redirect the Left Side Command Output as Right side CommandInput.
cal|wc
Note: Some time command can not take the inputs Supplied by |
character, in this cased better to use xargs command.
xargs command will take the inputs getting from | and excute the
given command by supplying that inputs.
command1 | xargs command2
echo "9 1752" | xargs cal
======================================================================
Filter / Database Commands
wc : Display the No of Lines, Words and Characters in the given file.
wc file1 file2 ...filen
-l : Lines -w : Words -c : Character
Paste:Combine the Lines as Columns from the given files and Display and
by default delimiter is tab space.
paste file1 file2 file3 ... filen
paste -d "character" file1 file2 file3 ... filen
paste -d "$" file1 file2 file3 ... filen
head filename: Display the Top 10 Lines from the given file.
head filename
head -lineno filename: Display the top given no of Lines
head -n lineno filename: Display the top given no of Lines
tail filename: Display the Last 10 Lines from the given file.
tail filename
tail -lineno filename: Display the last given no of Lines
tail -n lineno filename: Display the last given no of lines
tail -n +lineno filename: Display from the given line no to end of
the file.
tr : Replace The Expression in the Given Input and Display the Output
Note: tr command required the data using |
input | tr
tr "exist chars set" "new chars set"
cat info | tr "aeiou" "PQRST"
cat info | tr "aeiou" "PQR"
Note: The extra characters replace with last character in the
charcater set
cat info | tr [a-z] [A-Z]
tr -d "characterset"->Remove all the Given characters.
tr -s "characterset"->Squeeze the Given Characters
cat empdata | tr -s ":"
sort: Display the Sorted data getting input from the file
sort filename (Asending) Character
sort -n filename Character and Numerical Sorting
-r : Desending
cmp: Compare 2 Files and Given the Location where files having the
Difference.
cmp file1 file2
diff: Compare 2 Files data line by line and Display all the differences
present in Both the files
diff file1 file2
comm: Display the data in the following way from the Sorted Files
uniqinfile1 uniqinfile2 commoninbothfiles
comm f1 f2
-1,-2,-3 : Suppress the given no column
comm f1 f2 --output-delimiter='$'
csplit: Csplit have more Extra Features than split. We can split the file
at the given expression also.
locate <filename>: Search for the Given file in All the locations in the
file system.
Note: chown command can change the file owner and group owner at a time
chown owner:groupowner file/dir1 file/dir2....
Note: -R option is required To change all the Files and Sub Directory
structure of the Directory for chown and chgrp
======================================================================
User Group:
1. Primary Group (User Must Have one Group as Primary Group and
it should be only one)
2. Secondary Groups (User May be using some groups as secondary
groups to perform some operations)
Linux Bydefault reserve the Userids and Group Ids from 0 to 499 for the
system Accounts.
User Management
======================================================================
useradd <username>
username:givename
userid:1 increment to previous id
groupid:create a group with the same username and add the user
comment:blank
homedir:/home/username
shell:/bin/bash
--------------------------------------------
Delete the User
userdel <username> : It delete the user but leave the user home
directory
userdel -r <username>: Delete the user along with homedir
Note: Linux copy the data present in /etc/skel directory to user home
directory after create the user.So if any files want to copy in the user
home directories at the time of create the user , copy in skel directory.
======================================================================
Group Management
Create the Group : groupadd <groupname>
groupadd aug2014
groupadd -g <groupid> <groupname>
groupadd -g 999 holiday
5. Allow Only Owner and Group Owner to Perfrom all the Operations
in the Directory and Block Others
chmod -R 770 /aainfo
Note: User can not edit or append the Information at grub menu if grub
has the password.
----------------------------
---------------------------
Remove the Grub Password if we lost both grub and root password
1. Boot from Liux DVD and Select the Rescue Installed System Mode
2. Select the Shell prompt and Enter to root mode using chroot
/mnt/sysimage
3. Open the Grub file(/boot/grub/grub.conf) and remove the Grub
password.
4. Go back to Menu using exit command and select reboot option to
restart the machine
Note: This operation is possible only if we can access the machine
directly(physically).
---------------------------
Mouting and Unmounting
Mounting: Create the Logical Directory structure of a storage
partition or shared directory to perfrom File Opeations.
Unmounting: Detach the Storage Patition with the Logical Directory
for not perfrom the File operations.
Linux Can mount the ISO file in a Directory to Access the data.
mount -o loop Desktop/rhel6.0.iso Desktop/test
Note: Linux provided an empty directory named /mnt for user mounts
-------------------------------
Linux has a tool named yum(Yellowdog Updater Modified) for packages
installation
Note: yum can not be directly install the packages,yum shpuld be
configured with the repository information. repository can be present in
Local System or In remote system(Share through nfs,ftp,http...)
2. create a file with anyname but should with .repo extension and
add the Repository Information in the Following way
[title]
baseurl=ftp://ipaddressorurl/path
baseurl=http://ipaddressorurl/path
baseurl=file://absolutepath
enabled=1
gpgcheck=0 (Gnu Privacy Gaurd)
[convergencelabs]
baseurl=file:///mnt/rhel6
enabled=1
gpgcheck=0
----------------------------------------------
How to Create the Repository?
1. Create the Directory
mkdir /mypack
Note: mkfs can not format parition with swap file system.
mkswap paritionid
mkswap -L label partitionid
3.We have to use Following Method to Mount the
ext2/etx3/ext4/vfat/ntfs file systems
[root@newserver ~]# mount /dev/sda3 Desktop/l1
[root@newserver ~]# mount /dev/sda5 Desktop/w1
To make this moutings permanant add in /etc/fstab file
/dev/sda3 /root/Desktop/l1 ext4 defaults 0 0
4. Using GUI
System -> Preferences -> Network Connections (Commandline: nm-
connection-editor)
After add/Change the IP Address we have to Reconnect the Inetrface
===================================
How to View/Change the DNS Server Information?
cat /etc/resolve.conf
Note: We can Edit this file and change the DNS Server Information
nameserver <dnsipaddress>
nameserver 192.168.1.1
nameserver 8.8.8.8
===================================
How to Create Psuedo Ethernet Cards and Assign the IP Addresses?
Q: Why Psuedo etherenet cards are required in the machine?
A: It is useful to Configure a Linux machine with Multiple IP
Addresses to run Several network applications on the same port no with
out having multiple ethernet inteface cards.
Network Application Socket Binds IPADDRESS:PORTNO -> This
combination should be unique
192.168.1.20:30
192.168.1.25:30
Note: Real Ethernet card can be Configure with DHCP and Static but
Psuedo Ethernet Card should have the static IP Address.
2. Create new copy for the Physical Ethernet Card with the
Following Filenames
ifcfg-eth<no> -> ifcfg-eth<no>:0 , ifcfg-eth<no>:1 ,.....
ifcfg-eth0 -> ifcfg-eth0:0, ifcfg-eth0:1, ifcfg-eth0:2,...
3. Edit the Psuedo Ethernet Card File and Change the Following
Information
DEVICE=eth0:1
IPADDR=192.168.1.17
NAME="System eth0:2"
4. Activate all the Interfaces
Reboot or use ifup <interfaceid>
-------------------------------------------------------------------------
------------------------------------
Services
View the List of Services running in the Linux System
1. setup->System Services
2. ntsysv
-------------------------------------------------------------------------
-------------------------------------
How to Connect to FTP server from Linux for Download and Upload the
files?
1. Every Internet browser can work as FTP Client.
2. Linux has a cli tool named ftp.
rpm -ivh ftp-versionno.rpm
yum install ftp*
2. Passive Mode:
1. FTP Client Send Request/Commands to FTP server on 21 Port
Number then Server Randomly Pick a Port number and send to client for
Data Transfer
2. FTP Client Send/Receive Data to server on the Port No send
by the server
How to Connect to FTP server from Windows for Download and Upload the
files?
1. Every Internet browser can work as FTP Client.
2. Lot of Third Party Tools are
available(Filezilla,DownloadAccelator)
2. Unanonymous/Private ftp
It is useful to connect the ftp server with the username
and password of the Linux system to upload/download the data from the
login user home directory.
1.Bydefault FTP enable the ftp login for the local users
with the following option.
local_enable=YES
2. Enable the user login in SELinux Boolean options
setsebool -P ftp_home_dir=on
--------------------------------------------------------
------------
User Management in FTP Server
FTP server has a file with the name user_list in
/etc/vsftpd directory.
The file can use to specify the user list as allwoing or
denying list with the following options
1. Open the Configuration file
/etc/vsftp[d/vsftpd.conf
2. Enable for User List file Authentication
userlist_enable=YES
3. Specify the purpose of userlist by adding the
following line
userlist_deny=NO, only allow users in this file
userlist_deny=YES, only deny users in this file