Disclaimer: This content is created by Shankar Kumar Bhagat administrator of shankysportal com



Download 73.68 Kb.
Date09.01.2017
Size73.68 Kb.
#8154

Disclaimer: This content is created by Shankar Kumar Bhagat administrator of shankysportal.com

The content cannot be regenerated in any way.

For any further help and clarification please log on to my website shankysportal and ask a question at my forum

Let’s see some unique and important commands in Linux operating system



rcp

This command is used to copy files remotely from one machine to another.


DESCRIPTION
Rcp copies files between machines. Each file or directory argument is either a remote file name of the form ``rname@rhost:path'', or a local file name (containing no `:' characters, or a `/' before any `:'s).

SCP

scp is a program used to copy files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication.

Formate: scp [[username]@host1]:file1 [[username]@remote-host2]:[dir]

For eg. To copy a file from your system to any other system, use below command



user1@host1:~> scp abc1.txt host2:~/test
Enter Your Windows Password:
abc1.txt 100% 19 0.0KB/s 00:00

The above command will copy the file abc1.txt of home directory of host1 to the ~/test directory of host2



If you dont specify any directory on the destination host, the file will be copied to home directory of remote host. Lets say: See below command:

user1@host1
:~> scp abc1.txt host2:

Enter Your Windows Password:


abc1.txt 100% 19 0.0KB/s 00:00

Printer related commands



lp

This command is used to send jobs for printing. If no printer specified, it will use the default destination. DESCRIPTION


lp submits files for printing or alters a pending job. Use a filename of "-" to force printing from the standard input. The format is:
SYNOPSIS
lp [ -E ] [ -c ] [ -d destination ] [ -h server ] [ -m ] [ -n num-copies [ -o option ] [ -q priority ] [ -s ] [ -t title ] [ -H handling ] [ -P page-list ] [ file(s) ] Eg. Prompt:> lp abc.txt {ENTER} The file abc.txt will be sent for printing to the default printer
You can use -d destination to specify the destination printer -h hostname
Specifies the print server hostname. The default is "localhost" or the value of the CUPS_SERVER environment variable.

lpr

Same as lp, It also sends jobs for printing, if no destination specified, it used the default destinations.

Format:
lpr [ -E ] [ -P destination ] [ -U username ] [ -# num-copies [ -l ] [ -o option ] [ -p] [ -r ] [ -C/J/T title ] [file(s) ]

DESCRIPTION


lpr submits files for printing. Files named on the command line are sent to the named printer (or the system default destination if no destination is specified). If no files are listed on the command-line lpr reads the print file from the standard input.

lpadmin

This command configure cups printers and classes


Format:
lpadmin [ -E ] [-U username ] [ -h server[:port] ] -d destination
lpadmin [ -E ] [-U username ] [ -h server[:port] ] -p printer option(s)
lpadmin [ -E ] [-U username ] [ -h server[:port] ] -x destination


DESCRIPTION
lpadmin configures printer and class queues provided by CUPS. It can also be used to set the server default printer or
class.
Example:

lpadmin -U user1 -h cups-server:portno -p printer1 -v lpd://remoteserver/printer1 -o printer-is-shared=false -o printer-error-policy=retry-job -E


lpadmin -U user1 -h cups-server:port -p printer2 -v lpd://remote-server/printer2 -o printer-is-shared=false -o printer-error-policy=retry-job -E

lpstat

This command shows the status of a CUPS printer.


DESCRIPTION
lpstat displays status information about the current classes, jobs, and printers. When run with no arguments, lpstat will list jobs queued by the current user. -a [printer(s)] Shows the accepting state of printer queues. If no printers are specified then all printers are listed. Eg.
lpstat -a
printer1 accepting requests since Tue 18 Feb 2014 11:15:04 AM CET
printer2 accepting requests since Tue 18 Feb 2014 11:15:01 AM CET
-c [class(es)]
Shows the printer classes and the printers that belong to them. If no classes are specified then all classes are listed.

-d
Shows the current default destination.

-h server[:port]
Specifies an alternate server.

-l
Shows a long listing of printers, classes, or jobs.

-o [destination(s)]
Shows the jobs queue on the specified destinations. If no destinations are specified all jobs are shown.
-r
Shows whether the CUPS server is running.

-s
Shows a status summary, including the default destination, a list of classes and their member printers, and a list of printers and their associated devices.


Eg.
Prompt:>lpstat -s
no system default destination
device for printer1: lpd://server-name/printer1
device for printer2: lpd://server-name/printer2

lpinfo

Thiscommand show available devices or drivers


Format:
lpinfo [ -E ] [ -U username ] [ -h server[:port] ] [ -l ] -m
lpinfo [ -E ] [ -U username ] [ -h server[:port] ] [ -l ] -v
DESCRIPTION
lpinfo lists the available devices or drivers known to the CUPS server. The first form (-m) lists the available drivers, while the second form (-v) lists the available devices.

lppasswd

lppasswd - add, change, or delete digest passwords.

Format:
lppasswd [ username ] lppasswd -a [ -g groupname ] username lppasswd -x username
DESCRIPTION

lppasswd adds, changes, or deletes passwords in the CUPS digest password file, passwd.md5. When run by a normal user, lppasswd will prompt for the old and new passwords. When run by the super-user, lppasswd can add new accounts (-a user- name), change existing accounts (username), or delete accounts (-x username) in the digest password file. Digest usernames do not have to match local UNIX usernames.


ps

This command shows all the currently running processes

DESCRIPTION:
ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top(1) instead.

It shows information in below format:

UID PID PPID C STIME TTY TIME CMD

UID -> User Id of the starter of the process

PID -> Process id of the process

PPID -> Process id of the parent process

C ->

STIME -> start time



TTY

TIME ->Duration by which the process is running

CMD -> The command to start the process

Example:


Prompt:>ps -fu userName

This command will list all the process started by "userName"

Prompt:>ps -aef

This command will list all the process started by any user on the Linux machine.


To see the every process on the system using BSD syntax, we can use folowwing command:

ps -aux
ps -ax



man

This command shows a help manual of any other command. It accepts a command-name as argument and shows a detailed help manual on that command.

Example:
Prompt:>man top

Prompt:>man man



top

Like ps, top command also shows currently running processes but it also updates their status repeatedly.


Prompt:>top {}
top - 12:59:25 up 82 days, 2:31, 6 users, load average: 0.31, 0.38, 0.36
Tasks: 257 total, 1 running, 255 sleeping, 0 stopped, 1 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 32782M total, 31096M used, 1685M free, 185M buffers
Swap: 1027M total, 87M used, 940M free, 26222M cached

It displays following details:


PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

The command starts a display where all active processes are shown. It keeps on updating the values like % of CPU usage, % of memory usage, time the process is up by etc.



whoami

This command tells you who you are. It will tell the username who is logged on currently. For Eg.


DESCRIPTION
Print the user name associated with the current effective user ID. Same as id -un. Prompt:>whoami{Enter}
user1

xev

This command is ued to log the keyboard events. It starts an event tester and generates a log for evry keys pressed on the keyboard.

DESCRIPTION
Xev creates a window and then asks the X server to send it events whenever anything happens to the window (such as it being moved, resized, typed in, clicked in, etc.). You can also attach it to an existing window. It is useful for seeing what causes events to occur and to display the information that they contain; it is essentially a debugging

and development tool, and should not be needed in normal usage.


For eg. Below is the log of Shift key and Enter key. Notice the 3rd line which gives the keycode , the key pressed and the screen where pressed.

KeyPress event, serial 23, synthetic NO, window 0x400001,


root 0x54, subw 0x0, time 759929, (601,628), root:(605,654),
state 0x0, keycode 61 (keysym 0xffe2, Shift_R), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 25, synthetic NO, window 0x400001,


root 0x54, subw 0x0, time 760088, (601,628), root:(605,654),
state 0x1, keycode 61 (keysym 0xffe2, Shift_R), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 25, synthetic NO, window 0x400001,


root 0x54, subw 0x0, time 761329, (601,628), root:(605,654),
state 0x0, keycode 35 (keysym 0xff0d, Return), same_screen YES,
" XLookupString gives 1 bytes: (0d) "
" XmbLookupString gives 1 bytes: (0d) "
XFilterEvent returns: False

KeyRelease event, serial 25, synthetic NO, window 0x400001,


root 0x54, subw 0x0, time 761469, (601,628), root:(605,654),
state 0x0, keycode 35 (keysym 0xff0d, Return), same_screen YES,
" XLookupString gives 1 bytes: (0d) "

XFilterEvent returns: FalseThis command is ued to log the keyboard events. It starts an event tester and generates a log for evry keys pressed on the keyboard.


DESCRIPTION
Xev creates a window and then asks the X server to send it events whenever anything happens to the window (such as it being moved, resized, typed in, clicked in, etc.). You can also attach it to an existing window. It is useful for seeing what causes events to occur and to display the information that they contain; it is essentially a debugging
and development tool, and should not be needed in normal usage.
For eg. Below is the log of Shift key and Enter key. Notice the 3rd line which gives the keycode , the key pressed and the screen where pressed.
KeyPress event, serial 23, synthetic NO, window 0x400001,
root 0x54, subw 0x0, time 759929, (601,628), root:(605,654),
state 0x0, keycode 61 (keysym 0xffe2, Shift_R), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 25, synthetic NO, window 0x400001,
root 0x54, subw 0x0, time 760088, (601,628), root:(605,654),
state 0x1, keycode 61 (keysym 0xffe2, Shift_R), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 25, synthetic NO, window 0x400001,


root 0x54, subw 0x0, time 761329, (601,628), root:(605,654),
state 0x0, keycode 35 (keysym 0xff0d, Return), same_screen YES,
" XLookupString gives 1 bytes: (0d) "
" XmbLookupString gives 1 bytes: (0d) "
XFilterEvent returns: False
KeyRelease event, serial 25, synthetic NO, window 0x400001,
root 0x54, subw 0x0, time 761469, (601,628), root:(605,654),
state 0x0, keycode 35 (keysym 0xff0d, Return), same_screen YES,
" XLookupString gives 1 bytes: (0d) "
XFilterEvent returns: False

xmodmap

This command is used to remap the keyboard keys from one to another or as per user's choice. Suppose your Enter key is not working, you can use your right shift key by mapping Enter key to the it.

DESCRIPTION
The xmodmap program is used to edit and display the keyboard modifier
map and keymap table that are used by client applications to convert
event keycodes into keysyms. It is usually run from the user's session
startup script to configure the keyboard according to personal tastes.

So to map the right shift key to your enter key, use below command:


xmodmap -e "keycode 61=Return"
xmodmap -e "keycode 35=Shift_R"

The format is: xmodmap -e EXPRESSION. The expression can be:


keycode NUMBER=KEYSYMNAME

This mapping will persist only in the logged session, if you want it make it permanent, you have to execute below command.

xmodmap -pke >~/.Xmodmap


It will create a file Xmodmap in your home directory.
Then create one more file called .xinitrc in your home directory where you have to enter this line:

xmodmap .Xmodmap



ping

This command is used to ping an ip-address or server to find if the host is in the n/w or reachable. It takes ip address or ip-name as argument.


DESCRIPTION:

ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.

On success:

Linux-Prompt:> ping serverOrIP


PING serverOrIP (1.2.3.4) 56(84) bytes of data.
64 bytes from serverOrIP (1.2.3.4): icmp_seq=1 ttl=58 time=0.365 ms
64 bytes from serverOrIP (1.2.3.4): icmp_seq=2 ttl=58 time=0.435 ms
64 bytes from serverOrIP (1.2.3.4): icmp_seq=3 ttl=58 time=0.345 ms

--- serverOrIP ping statistics ---


3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 0.345/0.381/0.435/0.044 ms

On failure:

It says: Unknown host or ping failure.

netstat

The command shows all the active internet connection.


DESCRIPTION:
Netstat prints information about the Linux networking subsystem. The type of information printed is controlled by the first argument, as follows:
(none)
By default, netstat displays a list of open sockets. If you don't specify any address families, then the active sockets of all configured address families will be printed.
It shows following information:

Proto Recv-Q Send-Q Local Address Foreign Address State



nmap

The command accepts ip-address or Ip-name as argument. It is used to show the status of all open ports on that IP-address.

DESCRIPTION
Nmap ("Network Mapper") is an open source tool for network exploration and security auditing. It was designed to rapidly scan large networks, although it works fine against single hosts. Nmap uses raw IP packets in novel ways to determine what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems (and OS versions) they are running, what type of packet filters/firewalls are in use, and dozens of other characteristics. While Nmap is commonly used for security audits, many systems and network administrators find it useful for routine tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime.
Eg.
Prompt:>nmap ServerOrIP
Starting Nmap 4.75 ( http://nmap.org ) at 2014-02-20 11:41 CET
Interesting ports on ServerOrIP (10.252.103.22):
Not shown: 991 closed ports

PORT STATE SERVICE


25/tcp open smtp
80/tcp open http
139/tcp open netbios-ssn
443/tcp open https
515/tcp open printer
631/tcp open ipp
843/tcp open unknown
9100/tcp open jetdirect
50003/tcp open unknown

Nmap done: 1 IP address (1 host up) scanned in 6.61 seconds



**************SSH Login Setup******************

SSH login without password can help you directly login into a unix session without password.
It also helps you to switch from one unix session to other remote sessions directly
command is : ssh

To get this working, please follow below steps.


1. generate pub/private keys using RSA algorithms
ssh-keygen <-t rsa>
<-t rsa> is optional. If this field not given, ssh-keygen will generate keys using RSA algorithm by default.
This command will prompt to enter directory where the key will be generated.

Generating public/private rsa key pair.

Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Press Enter to accept default
Enter passphrase (empty for no passphrase):
Press Enter to accept default
Enter same passphrase again:
Press Enter to accept default

Your identification has been saved in /home/user1/.ssh/id_rsa.

Your public key has been saved in /home/user1/.ssh/id_rsa.pub.

The key fingerprint is:


some hexadecimal fingerprint user1@server1
The key's randomart image is:
+--[ RSA 2048]----+
| .*o=oo ... |
| . =.. o ..E |
| = o. |
| +.*.. |
| So .o+ |
| . o. |
| o |
| |
| |
+-----------------+
now, the keys are generated and saved in the path mentioned as default.

Accept default responses.


Just press Enter at every question.
2. copy the public key to the remote serever where you want to login

ssh-copy-id -i ~/.ssh/id_rsa.pub


Enter the password of remote server:
This is the first time the password will be asked.

3. ssh 'ssh login without password


Here the session wont prompt for any password.

4. Now you are on remote server.


Next time, when you do ssh , it wont ask for password and you will be redirected to remote server(unix session).

5. To come back to previous server, press ctrl+d.





history

This command displays a list of recently executed commands on your session with the timestamp.

Eg.

Prompt:>history



1 2014-02-20 15:25:18 netstat

2 2014-02-20 15:29:51 man history

3 2014-02-20 15:30:28 history
In your home directory, there is a file .bash_history which contains all the recently executed commands.

chmod

The commands is used to change access permission to a file. I can add access permission, remove access permissions.

Refer below example:

Prompt:>ls -l abc.txt

-rw-rw-r-- 1 someUser someGroup 27 2014-02-20 15:37 abc.txt

Prompt:>chmod 777 abc.txt

Prompt:>ll abc.txt

-rwxrwxrwx 1 someUser someGroup 27 2014-02-20 15:37 abc.txt

User someUser had permission -rw-rw-r--(664) on the file abc.txt by default.
Chmod changes the file permission to 777 i.e. -rwxrwxrwx

chown

This command changes the group and owneship of a file

Description:

chown changes the user and/or group ownership of each given file. If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the files' group is not changed. If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well.

Examples:
chown root /mydir Change the owner of /mirdir to "root".
chown root:shan /mydir It will also do the same, but also change its group to "staff".
chown -hR root /mydir Change the owner of /mydir and subfiles to "root".

xeyes

This command starts a funny animation. It will start a small window containing animation of eyes. And, the eyes will look where your cursor goes. To quit press ctrl+c .

emacs

info

This command is used to read a documentation in info format.


Example
Prompt:>info emacs {ENTER}
Prompt:>info show top-level dir menu

At the info page, press


p -> to go to previous node(data)
n -> to the nest node or entry
spacebar -> to go below. The last two lines of the content will be at the top of the page and more lines will be displayed.
Del/backspace -> to come back (undo of spacebar)

portmap


file

A command to determine the type of file. It takes a file as argument and tells its type


DESCRIPTION
file tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed.
Eg.

Prompt:>file abc.txt


abc.txt: ASCII text
Prompt:> file abc.xml
abc.xml: XML
Prompt:>ll LinkFile
lrwxrwxrwx 1 username group 44 2013-08-01 09:39 LinkFile -> ~/a/b/c/somescript.sh
Prompt:>file LinkFile

LinkFile: symbolic link to `~/a/b/c/somescript.sh'



type

This command accepts the command-name as argument and tells the type of command. It writes about the command like it is a shell builtin command or an alias or a bin command.


Eg.
Prompt:> type alias
alias is a shell builtin

Prompt:> type whoami


whoami is /usr/bin/whoami

Prompt:> type ll

ll is aliased to `ls -la'

alias

A shell builtin command that shows aliases being used currently in your system.

You can set aliases as per need to shorten the long commands and customize the commands. For Eg.

alias ll='ls -l'

It will set "ls -l" command to "ll" and "ll " will work as "ls -l"

To set an alias, use below format:

alias customCommand='complex set of comands'

nslookup

It takes server-name or ip-address as argument. This command is used to query the DNS and find the alias names of a server. It gives all the canonical and logical names and ip-address for a server or ip-adress.

Description:Nslookup is a program to query Internet domain name servers. Nslookup
has two modes: interactive and non-interactive. Interactive mode allows
the user to query name servers for information about various hosts and
domains or to print a list of hosts in a domain. Non-interactive mode
is used to print just the name and requested information for a host or
domain.

Eg. nslookup ip-address/server



host

Takes server/ip-name as argument.This command will tell you the alias name and ip- address of the server-name


DESCRIPTION:
host is a simple utility for performing DNS lookups. It is normally

used to convert names to IP addresses and vice versa.



uname

It displays system information.


"uname -a" will give a long system description.
Eg. Prompt:>uname -a

Linux hostname 2.6.32.59-0.3-xen #1 SMP 2012-04-27 11:14:44 +0200 x86_64 x86_64 x86_64 GNU/Linux



finger

DESCRIPTION


The finger utility displays information about local and remote system users. By default, the following information is displayed about each user currently logged-in to the local host:
· login name
· user's full name
· associated terminal name
· idle time
· login time
· from where

id

This command is used to find the user id and group id of a user. It also shows the groups the user belongs to.


Eg. Prompt :> id
uid=12345(someid) gid=12345(groupname) groups=gid(gname), gid(gname)...

uptime command in Linux

If you want to find the duration of time a linux server is up or active, you can use uptime command


uptime - tell how long the system has been running

Format


uptime [OPTION]... [ FILE ]

DESCRIPTION

Print the current time, the length of time the system has been up, the number of users on the system, and the average number of jobs in the run queue over the last 1, 5 and 15 minutes. If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common.

Prompt> hostname


DemoServer

Prompt:> uptime


12:24pm up 346 days 1:14, 3 users, load average: 0.06, 0.07, 0.08

So the above command will tell that the server DemoServer is UP by 346 days 1:14 hrs having the average load of jobs as

0.06, 0.07, 0.08 in last 1, 5 and 15 minutes.




RSYNC: A command in linux to copy files remotely. Faster and more flexible than rcp

The command is same like rcp but can be used for large and faster file transfer from one machine to another.
DESCRIPTION
rsync is a program that behaves in much the same way that rcp does, but has many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.
The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection, using an efficient checksum-search algorithm described in the technical report that accompanies this package.

Some of the additional features of rsync are:

o support for copying links, devices, owners, groups, and permissions
o exclude and exclude-from options similar to GNU tar
o a CVS exclude mode for ignoring the same files that CVS would ignore
o can use any transparent remote shell, including ssh or rsh
o does not require super-user privileges
o pipelining of file transfers to minimize latency costs
o support for anonymous or authenticated rsync daemons (ideal for mirroring)




AWK command for scanning and analysing a large file in Linux

awk - A command for pattern scanning and processing of a large file

The awk utility shall execute programs written in the awk programming language, which is specialized for textual data manipulation. An awk program is a sequence of patterns and corresponding actions. When input is read that matches a pattern, the action associated with that pattern is carried out.

The awk utility shall interpret each input record as a sequence of fields where, by default, a field is a string of non- s. This default white-space field delimiter can be changed by using the FS built-in variable or -F ERE.
The awk utility shall denote the first field in a record $1, the second $2, and so on. The symbol $0 shall refer to the entire record; setting any other field causes the re-evaluation of $0. Assigning to $0 shall reset the values of
all other fields and the NF built-in variable.

Syntax:
awk '/search pattern1/ {Actions} /search pattern2/ {Actions}' file


Examples:

Pompt:>cat employee.txt


Name EmpId City sex age
Shankar 624532 Hyderabad Male 24
Priyanka 624534 Bangalore Female 24
Anirudh 62543 Chennai Male 24
Sagar 363533 Pune Male 23
Bhavani 624531 Lahore Female 22

1. To print the entire file.


awk '{print;}' employee.txt

Pompt:>awk '{print;}' employee.txt


Name EmpId City sex age
Shankar 624532 Hyderabad Male 24
Priyanka 624534 Bangalore Female 24
Anirudh 62543 Chennai Male 24
Sagar 363533 Pune Male 23
Bhavani 624531 Lahore Female 22

2. To print the line containing 23 or print employees of age 23.


Pompt:>awk '/23/' employee.txt
Sagar 363533 Pune Male 23

3.To print the line containing 23 or 22 ; or print all employees of age 23 or 22


Note:- All the search patterns are given in new line starting with '>'
Pompt:>awk '/23/
> /22/' employee.txt
Sagar 363533 Pune Male 23
Bhavani 624531 Lahore Female 22

4. Print only 2nd column of the file or print only the employee Ids


Pompt:>awk '{print $2}' employee.txt
EmpId
624532
624534
62543
363533
624531

5. Print only 2nd and 4th column of the file or print only the employee Ids and Sex


Pompt:>awk '{print $2, $4}' employee.txt
EmpId sex
624532 Male
624534 Female
62543 Male
363533 Male
624531 Female

6. Print all the male employees. ie. 4th column is matching with 'Male'


Pompt:>awk '$4~/Male/{print;}' employee.txt
Shankar 624532 Hyderabad Male 24
Anirudh 62543 Chennai Male 24
Sagar 363533 Pune Male 23

7. Print all the employee whose age is above or equal to 23.


Pompt:>awk '$5>=23{print;}' employee.txt
Name EmpId City sex age
Shankar 624532 Hyderabad Male 24
Priyanka 624534 Bangalore Female 24
Anirudh 62543 Chennai Male 24
Sagar 363533 Pune Male 23

8. Print the no. of employees who are in Hyderabad.


Pompt:>awk 'BEGIN {count=0;}
> $3~/Hyderabad/ {count++;}
> END {print "No of employees in Hyderabad=", count;}' employee.txt
No of employees in Hyderabad= 2



Create a new user in Linux system: useradd

useradd - This command is used to create a new user account.

FORMAT:
useradd [-D binddn] [-P path] [-c comment] [-d homedir] [-e expire] [-f inactive] [-G group,...] [-g gid] [-m [-k skeldir]] [-o] [-p password] [-u uid] [-r] [-s shell] [--service service] [--help] [--usage] [-v] account

DESCRIPTION
useradd creates a new user account using the default values from /etc/default/useradd and the specified on the command line. Depending on the command line options the new account will be added to the system files or LDAP database, the home directory will be created and the initial default files and directories will be copied.

You must have admin rights to add a user. You must have rw acces to passwd file or else it will say " Cannot lock password file: already locked."

ll /etc/passwd
-rw-r--r-- 1 root root 21178 2014-03-25 13:04 /etc/passwd

The account name must begin with an alphabetic character and the rest of the string should be from the POSIX portable character class ([A-Za-z_][A-Za-z0-9_-.]*[A-Za-z0-9_-.$]).

This command will take account-name as argument. Rest all are optional and can be added later.

-c some-comment


This will give a short description about the user and purpose of account.
-p password
We can specify password here for the account.

-e expire


With this option the date when the account will be expired can be changed. expiredate has to be specified as number of days since January 1st, 1970. The date may also be expressed in the format YYYY-MM-DD. If not specified, the default from /etc/default/useradd is used.
-G group1,group2..

If You want the user to be member of a group or more, you can user this option. All the groups that the new user has to be member of can be given seperated by comma.

Example:

1. Add a new user "shanky"


useradd shanky [-c "A demo user"] -p mypswd

If you dont give -p some-passwd, it will ask you to give a password


2. Give a password:
******

Once this is done , you can check if the account is added or not. Use below command: grep shanky /etc/passwd



user-name

Place-holder for encrypted password

uId

gId

Comment

Home dir

Default shell

shanky

x

1234

2345

A demo user

/home/shanky

/bin/bash

The 2nd field in this file 'x' is a place holder of the encrypted password for the user and the encrypted password is stored in /etc/shadow file.

Related Files:


/etc/passwd - user account information
/etc/shadow - shadow user account information
/etc/group - group information
/etc/default/useradd - default values for account creation
/etc/skel - directory containing default files

SEE ALSO
passwd, login.defs, userdel, usermod





crontab: A command in linux to automatically start/repeat a process at certian time and interval

crontab - A command to manage crontab files for each users
Format:
crontab [-u user] file
crontab [-u user] [-l | -r | -e]

DESCRIPTION


Crontab is the program used to creat, remove or show the tables used to drive the cron(8) daemon in ISC Cron. Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly.

Related files: /etc/cron.allow, /etc/cron.deny

Note:-
Cron.allow: If the cron.allow file exists, then you must be listed therein in order to be allowed to use this command.

Cron.deny: If the cron.allow file does not exist but the cron.deny file does exist, then you must not be listed in the cron.deny file in order to use this command.

If neither of these files exists, only the super user will be allowed to use this command.

Example:


Prompt:>crontab -l

The -l option causes the current crontab to be displayed on standard output.


Prompt:>crontab -r
The -r option causes the current crontab to be removed.

The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-file-


name ``-'' is given.

The format to create a new cron:

+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed

Example:


Prompt:> crontab -e
The crontab editor will open. Add your jobs here line by line.

20 16 13 3 4 ls -l

The above will execute ls -l at the time 16:20 on 13th of March on day 4 of the week at your home directory.

yourId@ServerName:/home/yourId:> crontab -l


# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXFIDLBr installed on Thu Mar 13 16:19:00 2014)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
20 16 13 3 4 ls -l

You will get a mail about cron at here /var/mail/yourId

If you are a root user, you can see and edit the cron job of other users.

crontab -u someUser -e


The above command will view/edit the corn jobs of someUser.

Example 2:

Suppose you want to delete some log files from your home directory at every friday of the month at 23:59. How will you do this? Simply type below line in your crontab:

59 23 * * 5 rm *.log

Example 3:

Suppose you want to start a script at 06:10 pm at the end of each month, you can use below cron:

10 18 * * * /path-of-script/script.sh




strings : a command in linux to read the non-text files

Suppose you opened a file (eg. a binary file) in linux which is completely un-readable. There might be some useful words that you want to see. You can go for strings command.

strings : Mainly useful for determining the contents of non-text files.

DESCRIPTION
For each file given, GNU strings prints the printable character sequences that are at least 4 characters long (or the number given with the options below) and are followed by an unprintable character. By default, it only prints the strings from the initialized and loaded sections of object files; for other types of files, it prints the strings from the whole file.

Example:


1. strings non-text-file

The above command will show all the words of the file having at least character.

We can manually specify the no. of words i.e. minimum length of characters of words to be shown from the non-text file. See below example:

2. strings -n 2 non-text-file

Above command will find all the words from non-readable file with minimum two characters.

Format:


strings -n min-len filename

Print sequences of characters that are at least min-len characters long, instead of the default 4.





lwp-download: A command in linux to downlaod large files from internet

lwp-download command is used to fetch large files from the web

Format:
lwp-download [-a] []

DESCRIPTION


The lwp-download program will save the file at url to a local file.If local path is not specified, then the current directory is assumed.
If local path is a directory, then the basename of the file to save is picked up from the Content-Disposition header or the URL of the response. If the file already exists, then lwp-download will prompt before it overwrites and will fail if its standard input is not a terminal. This form of invocation will also fail is no acceptable filename can be derived from the sources mentioned above.
Example:
lwp-download http://www.shankysportal.com/favicon.ico
The above command will download the file "http://www.shankysportal.com/favicon.ico" to the folder where you executed this command.
lwp-download http://www.shankysportal.com/_ph/3/1/805900426.jpg /home/mint/rpc/
The above command will download the mentioned file in the path /home/mint/rpc/



SCP : a secure copy program in Linux

scp is a program used to copy files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication.

Formate: scp [[username]@host1]:file1 [[username]@remote-host2]:[dir]


For eg. To copy a file from your system to any other system, use below command

user1@host1:~> scp abc1.txt host2:~/test
Enter Your Windows Password:
abc1.txt 100% 19 0.0KB/s 00:00

The above command will copy the file abc1.txt of home directory of host1 to the ~/test directory of host2

If you dont specify any directory on the destination host, the file will be copied to home directory of remote host. Lets say: See below command:

user1@host1:~> scp abc1.txt host2:



Enter Your Windows Password:
abc1.txt 100% 19 0.0KB/s 00:00


Download 73.68 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page