Sunteți pe pagina 1din 33

What is Linux hostid Command?

Explanation hostid COMMAND: hostid command prints the numeric identifier or id of the current host in hexadecimal. SYNTAX: The Syntax is hostid OPTIONS: --help Print help message and exit -Print version and exit version EXAMPLE: 1. To Print host id:
2. 3. hostid a3b50706

This command prints the hostid in hexadecimal. What is Linux hostname Command? Explanation hostname COMMAND: hostname specifies the name of the host. SYNTAX: The Syntax is hostname [-a | -d | -f | -h | -i | -s] OPTIONS: -a Displays the alias name of the host, if used. -d Displays DNS domain name -f Displays fully qualified domain name. -h Displays help message. -i Displays IP address of the host. -s Trim domain name from display. EXAMPLE: 1. hostname command

hostname

The above command will print as username.com 2. hostname -a The above command will remove space and print as username 3. To display DNS domain name
hostname -d

The above command will print as .com What is Linux id Command? Explanation id COMMAND: id command prints the effective(current) and real userid(UID)s and groupid(GID)s. SYNTAX: The Syntax is id [options] OPTIONS: -a Reports user name, use ID and all the groups to which the user belongs. -G Output all real and effective group IDs,using the format "%u\n". -g Output only the effective group IDs,using the format "%u\n". -u Output only the effective user Id,using the format "%u\n". EXAMPLE:
1. id -a

Output:
uid=501(username) gid=501(username) groups=48(apache), 501(username)

Prints real and current group IDs.


2. id -G

Output:
501 48

Prints in the format of "%u\n"


3. # id

Output:
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys), 4(adm),6(disk),10(wheel) context=user_u:system_r:unconfined_t

The above example display the rootuser uid, gid, groups and context. What is Linux info Command? Explanation info COMMAND: info command is used to display the readable online documentation for the specified command . SYNTAX: The Syntax is info commandname OPTIONS: -n Specify nodes in first visited info file. -f Specify info file to visit. EXAMPLE:
1. info man

Display the readable online documentation for the man command. What is Linux ifconfig Command? Explanation ifconfig COMMAND: ifconfig command displays information about the network interfaces attached to the system and also used to configure the network interface. SYNTAX: The Syntax is ifconfig [options] OPTIONS: -a dispalys information about both active and inactive Interface

[interface-name] [interface-name] up [interface-name] down [interface-name] [IP Address] up EXAMPLE:

dispalys information about interface Activates the interface Inactivates the interface Assigns IP address to the interface and activates it

1. To get information of active network-interfaces:


ifconfig

The sample output of above command:


eth0 Link encap:Ethernet HWaddr 00:14:85:9C:CC:55 inet addr:192.168.0.12 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::214:85ff:fe9c:cc55/64 Scope:Link UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:7856 errors:0 dropped:0 overruns:0 frame:0 TX packets:7856 errors:0 dropped:0 overruns:0 carrier:0 RX bytes:492016 (480.4 KiB) TX bytes:398 (398.0 b) Interrupt:201 Memory:e1000000-0 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0 inet6 addr: ::1/128 Scope:Host UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1455 errors:0 dropped:0 overruns:0 frame:0 TX packets:5 errors:0 dropped:0 overruns:0 carrier:0 RX bytes:1917382 (1.8 MiB) TX bytes:1917382 (1.8 MiB) In above output: Link encap:Ethernet -Specifies the type Interface HWaddr 00:14:85:9C:CC:55 -Specifies the Hardware or MAC address inet addr:192.168.0.12 -Specifies the IP address assigend to network-interface

2. To Assign IP address to Network Interface[Ethernet Card]:


ifconfig eth0 192.168.0.12 up

The above command will Assign IP address 192.168.0.12 to Ethernet card with name eth0. 3. To inactivate the Network Interface[Ethernet Card]:
ifconfig eth0 down

The above command inactivates the ethernet card. What is Linux jobs Command?

Explanation jobs COMMAND: jobs command is used to list the jobs that you are running in the background and in the foreground. If the prompt is returned with no information no jobs are present. SYNTAX: The Syntax is jobs [options] OPTIONS: Report the process group ID and working directory of the jobs. Display only jobs that have stopped or exited since last notified. Displays only the process IDs for the process group leaders of the selected -p jobs. EXAMPLE:
1. jobs -l

-l -n

Lists the jobs that you are running in the foreground (or) background.
2. jobs -p

Display only the process Id for the listed jobs. What is Linux kill Command? Explanation kill COMMAND: kill command is used to kill the background process. SYNTAX: The Syntax is kill [-s] [-l] %pid OPTIONS: Specify the signal to send. The signal may be given as a signal name or number. Write all values of signal supported by the implementation, if no operand is -l given. -pid Process id or job id. -9 Force to kill a process. EXAMPLE: -s Step by Step process:

Open a process music player. xmms


press ctrl+z to stop the process.

To know group id or job id of the background task. jobs -l


It will list the background jobs with its job id as, xmms 3956 kmail 3467

To kill a job or process. kill 3956


kill command kills or terminates the background process xmms.

What is Linux last Command? Explanation last COMMAND: last command is used to display the last logged in users list. Last logged in users informations are read from the file /var/log/wtmp. SYNTAX: The Syntax is last [options] OPTIONS: -n Specify how many lines to show. -R Suppresses the display of the hostname field. -x Display the system shutdown entries and run level changes. -a Display the hostname in the last column. Useful in combination with the next flag. EXAMPLE:
1. last

Displays the last logged in users list.


2. last -x

Displays the logged in users list with shutdown entries and run level changes. What is Linux lastlog Command? Explanation lastlog COMMAND: lastlog command is used to print the last login times for system accounts. Login information is read from the file /var/log/lastlog.

SYNTAX: The Syntax is lastlog [options] OPTIONS: -t n Print only logins more recent than 'n' days ago.. -u username Print only login information for username. EXAMPLE:
1. lastlog -t 5

Displays the login information, 5 days ago.


2. last -u username

Displays the login information for the specified user. What is Linux less Command? Explanation less COMMAND: less command is used to display text in the terminal screen. It just prints the text in the given file, you cannot edit or manipulate the text here. To display the file from the specified line, enter the line number followed by colon(:). It allows Forward and backward movement in the file. SYNTAX: The Syntax is less [options] filename OPTIONS: -c Clear screen before displaying. +n Starts up the file from the given number. :p Examine the pervious file in the command line list. :d Remove the current file from the list of files. EXAMPLE:
1. less +3 index.php

Start printing from 3rd line of the file. What is Linux link Command?

Explanation link COMMAND: link command is used to create a link to a file. It is also called as hard link. Inode will be same for source and destination. SYNTAX: The Syntax is link existingfilename newfilename (or) link source destination OPTIONS: --help Print help message and exit -Print version and exit version EXAMPLE:
1. link test.php test1.php

Create a link to 'test1.php' file. Here inode for 'test.php' and 'test1.php' will be same. What is Linux ln Command? Explanation ln COMMAND: ln command is used to create link to a file (or) directory. It helps to provide soft link for desired files. Inode will be different for source and destination. SYNTAX: The Syntax is ln [options] existingfile(or directory)name newfile(or directory)name OPTIONS: Link files without questioning the user, even if the mode of target forbids writing. This is the default if the standard input is not a terminal. -n Does not overwrite existing files. -s Used to create soft links. EXAMPLE: -f
1. ln -s file1.txt file2.txt

Creates a symbolic link to 'file1.txt' with the name of 'file2.txt'. Here inode for 'file1.txt' and 'file2.txt' will be different.
2. ln -s nimi nimi1

Creates a symbolic link to 'nimi' with the name of 'nimi1'. What is Linux ls Command? Explanation ls COMMAND: ls command lists the files and directories under current working directory. SYNTAX: The Syntax is ls [OPTIONS]... [FILE] OPTIONS: Lists all the files, directories and their mode, Number of links, owner of the file, file size, Modified date and time and filename. -t Lists in order of last modification time. -a Lists all entries including hidden files. -d Lists directory files instead of contents. -p Puts slash at the end of each directories. -u List in order of last access time. -i Display inode information. -ltr List files order by date. -lSr List files order by file size. EXAMPLE: -l 1. Display root directory contents:
ls /

lists the contents of root directory. 2. Display hidden files and directories:
ls -a

lists all entries including hidden files and directories. 3. Display inode information:
ls -i 7373073 book.gif 7373074 clock.gif 7373082 globe.gif 7373078 pencil.gif 7373080 child.gif 7373081 email.gif

7373076 indigo.gif

The above command displays filename with inode value. What is Linux lsattr Command? Explanation lsattr COMMAND: lsattr command is used to list the attributes of the specified file or directory. SYNTAX: The Syntax is lsattr [options] OPTIONS: -R Recursively list attributes of directories and their contents. -a List all files in directories, including files that start with `.'. -d List directories like other files, rather than listing their contents. EXAMPLE: 1. List attributes:
lsattr

Lists the attributes of the current directory. 2. Set the attribute:


chattr +i test.txt

Set the attribute for 'test.txt' file.


3. lsattr test.txt

Lists the attributes of the 'test.txt' file.


----i-------- ./test.txt

What is Linux mail Command? Explanation mail COMMAND: mail command is used to send and receive mails locally and globally. SYNTAX: The Syntax is

mail OPTIONS: Specify subject on command line. Send carbon copies to list of users. Send blind carbon copies to list. List should be a comma-separated list of -b names. Read in the contents of your mbox for processing; when you quit, mail writes -f undeleted messages back to this file. Ignore tty interrupt signals. This is particularly useful when using mail on -i noisy phone lines. EXAMPLE: 1. Receive mails
mail The above command display the messages. Press Enter to view the next message after '&' symbol.

-s -c

2. Sent mails
mail abc@localhost.com (or) mail abc@hiox.com Starts a new mail and sent to abc@localhost.com. To terminate the message, type a period(.) and press Enter (or) press ctrl+d and press Enter.

What is Linux man Command? Explanation man COMMAND: man command which is short for manual, provides in depth information about the requested command (or) allows users to search for commands related to a particular keyword. SYNTAX: The Syntax is man commandname [options] OPTIONS: -a Print a one-line help message and exit. -k Searches for keywords in all of the manuals available.. EXAMPLE:
1. man mkdir

Display the information about mkdir command. What is Linux mkdir Command?

Explanation mkdir COMMAND: mkdir command is used to create one or more directories. SYNTAX: The Syntax is mkdir [options] directories

OPTIONS: -m Set the access mode for the new directories. -p Create intervening parent directories if they don't exist. -v Print help message for each directory created. EXAMPLE: 1. Create directory:
mkdir test

The above command is used to create the directory 'test'. 2. Create directory and set permissions:
mkdir -m 666 test

The above command is used to create the directory 'test' and set the read and write permission. What is Linux more Command? Explanation more COMMAND: more command is used to display text in the terminal screen. It allows only backward movement. SYNTAX: The Syntax is more [options] filename OPTIONS: -c -e -n +n Clear screen before displaying. Exit immediately after writing the last line of the last file in the argument list. Specify how many lines are printed in the screen for a given file. Starts up the file from the given number.

EXAMPLE:
1. more -c index.php

Clears the screen before printing the file .


2. more -3 index.php

Prints first three lines of the given file. Press Enter to display the file line by line. What is Linux mv Command? Explanation mv COMMAND: mv command which is short for move. It is used to move/rename file from one directory to another. mv command is different from cp command as it completely removes the file from the source and moves to the directory specified, where cp command just copies the content from one file to another. SYNTAX: The Syntax is mv [-f] [-i] oldname newname OPTIONS: This will not prompt before overwriting (equivalent to --reply=yes). mv -f will move the file(s) without prompting even if it is writing over an existing target. -i Prompts before overwriting another file. EXAMPLE: -f 1. To Rename / Move a file:
mv file1.txt file2.txt

This command renames file1.txt as file2.txt 2. To move a directory


mv hscripts tmp

In the above line mv command moves all the files, directories and sub-directories from hscripts folder/directory to tmp directory if the tmp directory already exists. If there is no tmp directory it rename's the hscripts directory as tmp directory. 3. To Move multiple files/More files into another directory
mv file1.txt tmp/file2.txt newdir

This command moves the files file1.txt from the current directory and file2.txt from the tmp folder/directory to newdir. What is Linux netstat Command? Explanation netstat COMMAND: nestat command displays statistics information and current state of network connections, protocol, ports/ sockets and devices. SYNTAX: The Syntax is netstat [options] OPTIONS: dispalys statics information about protocols. dispalys statistics information about the network interface. diplays routing table. displays statistics information and updates every second. displays information about all sockets that are in listening state. displays information about all sockets that are in listening and non-listening -a state. -p displays information about sockets with ProcessName and PID. EXAMPLE: 1. To get statistics of network connections:
netstat

-s -i -r -c -l

The sample output of above command:


Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 vhost:32803 LocalHost:smtp TIME_WAIT tcp 0 0 vhost:32803 google.com:http ESTABLISHED

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

-Specifies the Protocol used for connection. -Specifies the Number of Bytes which are not recevied. -Specifies the Number of Bytes not send to destination. -Specifies the local or source address and port. -Specifies the destination address and port. -Specifies the current state of conection to the socket.

o o o

ESTABLISHED - Connection is Established. TIME_WAIT - Waiting to receive packets. LISTEN - Listening to establish connection.

2. To Get Statistics of Protocols:


netstat -s

The Sample output of above command:


IP: 5193 incoming packets delivered 4813 requests sent out Tcp: 4033 segments received 4813 segments send out Icmp: 41 ICMP messages received 178 ICMP messages sent

3. To Get statistics of Network Interface:


netstat -i

The sample output of above command:


Kernel Interface table Iface MTU Met RX-OK RX-ERR TX-OK TX-ERR Flg eth0 1500 0 1308 0 1345 0 BMRU

This is the statistics information of Ethernet Card[eth0]. What is Linux passwd Command? Explanation passwd COMMAND: passwd command is used to change your password. SYNTAX: The Syntax is passwd [options] OPTIONS: -a -l -d Show password attributes for all entries. Locks password entry for name. Deletes password for name. The login name will not be prompted for password.

Force the user to change password at the next login by expiring the password for name. EXAMPLE: -f
1. passwd

Entering just passwd would allow you to change the password. After entering passwd you will receive the following three prompts:
Current Password: New Password: Confirm New Password:

Each of these prompts must be entered correctly for the password to be successfully changed. What is Linux paste Command? Explanation paste COMMAND: paste command is used to paste the content from one file to another file. It is also used to set column format for each line. SYNTAX: The Syntax is paste [options] OPTIONS: -s Paste one file at a time instead of in parallel. -d Reuse characters from LIST instead of TABs . EXAMPLE:
1. paste test.txt>test1.txt

Paste the content from 'test.txt' file to 'test1.txt' file.


2. ls | paste - - - -

List all files and directories in four columns for each line. What is Linux pidof Command? Explanation pidof COMMAND: pidof linux command is used to find the process ID of a running program.

SYNTAX: The Syntax is pidof [options..] program OPTIONS: Single shot - this instructs the program to only return one pid. Scripts too - this causes the program to also return process id's of shells -x running the named scripts. Tells pidof to omit processes with that process id. The special pid %PPID can -o be used to name the parent process of the pidof program, in other words the calling shell or shell script. EXAMPLE: 1. To find a process id of a particular console:
pidof -s console

-s

This command prints the process id of the console.


3189

What is Linux ping Command? Explanation ping COMMAND: System administration command. Confirm that a remote host is online and responding. Ping is used for verifying connectivity between two hosts on a network. It sends Internet Control Message Protocol (ICMP) echo request packets to a remote IP address and watches for ICMP responses. SYNTAX: The Syntax is ping [options] host OPTIONS: Make ping audible. Beep each time response is received. Ping a broadcast address. Stop after sending count ECHO_REQUEST packets. With deadline option, -c count ping waits for count ECHO_REPLY packets, until the timeout expires. Show network addresses as numbers. ping normally displays addresses as -n host names. Quiet outputnothing is displayed except the summary lines at startup time -q and when finished. -i Specify the interval between successive transmissions. The default is one -a -b

-t -w
1.

second. Set the IP Time to Live to n seconds. Exit ping after n seconds.

ping google.com -c 3

Display ECHO_REQUEST 3 times only because we set count for three.


2. ping -n google.com

Here the network addresses displays as numbers,normally it displays as hostnames. What is Linux printf Command? Explanation printf COMMAND: printf command is used to write formatted output. SYNTAX: The Syntax is printf format [argument].... OPTIONS: The format characters and their meanings are: \b Backspace. \n Newline. \t Horizontal tab \v Vertical tab. EXAMPLE:
1. printf "hello\n"

Use '\n' returns 'hello' to the new line.


2. printf "hel\blo"

Output:
helo

Here '\b' is used for backspace. What is Linux ps Command? Explanation ps COMMAND:

ps command is used to report the process status. ps is the short name for Process Status. SYNTAX: The Syntax is ps [options] OPTIONS: List information about all processes most frequently requested: all those except process group leaders and processes not associated with a terminal.. -A or e List information for all processes. -d List information about all processes except session leaders. -e List information about every process now running. -f Generates a full listing. -j Print session ID and process group ID. -l Generate a long listing. EXAMPLE: -a
1. ps

Output:
PID TTY 2540 pts/1 2621 pts/1 TIME CMD 00:00:00 bash 00:00:00 ps

In the above example, typing ps alone would list the current running processes.
2. ps -f

Output:
UID PID PPID C STIME TTY TIME CMD nirmala 2540 2536 0 15:31 pts/1 00:00:00 bash nirmala 2639 2540 0 15:51 pts/1 00:00:00 ps -f

Displays full information about currently running processes. What is Linux pwd Command? Explanation pwd COMMAND: pwd - Print Working Directory. pwd command prints the full filename of the current working directory. SYNTAX: The Syntax is

pwd [options] OPTIONS: -P The pathname printed will not contain symbolic links. -L The pathname printed may contain symbolic links. EXAMPLE: 1. Displays the current working directory.
pwd

If you are working in home directory then, pwd command displays the current working directory as /home. What is Linux restore Command? Explanation restore COMMAND: restore - command restores the data from the dump-file or backup-file created using dump command. SYNTAX: The Syntax is restore [options] OPTIONS: -f -C -i -v -e Used to specify the backup or dump file Used to compare dump-file with original file Restore in Interactive mode Displays Verbose Information Exclude inode while making backup

Commands used in interactive mode: ls List the files and directories in backup file add Add files in dump-file to current working directory cd Changes the directory pwd Displays the current working directory extract Extract the files from the dump quit Quit from the interactive mode EXAMPLE: 1. To restore file and directories from backup-file :

restore -if databack Where, i -To make restore with interactive mode f -To restore from the backup-file specifed databack -Is a name of backup-file or dump-file

This command gets you to interactive mode as follows:


restore > Now the following commands are entered to restore: restore > ls -Lists files and directories in dump file restore > add -add files to the current directory restore > ls -Lists the file added from the backup file to current directory restore > extract -Extracts the file from the backup file to current directory restore > quit -Quits from the interactive mode

2. To compare and display any dump-file with the original file:


restore -Cf databack

This command will compare,


-1 databackup /home/user1/data -Is the dump-level [1 specifies incremental backup] -Is a dump-file [or backup-file] -Is a directory for which a backup is created

What is Linux rm Command? Explanation rm COMMAND: rm linux command is used to remove/delete the file from the directory. SYNTAX: The Syntax is rm [options..] [file | directory] OPTIONS: Remove all files in a directory without prompting the user. Interactive. With this option, rm prompts for confirmation before removing -i any files. Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally -r (or) -R prompted for removal of any write-protected files which the directory contains. EXAMPLE: -f

1. To Remove / Delete a file:


rm file1.txt

Here rm command will remove/delete the file file1.txt. 2. To delete a directory tree:
rm -ir tmp

This rm command recursively removes the contents of all subdirectories of the tmp directory, prompting you regarding the removal of each file, and then removes the tmp directory itself. 3. To remove more files at once
rm file1.txt file2.txt

rm command removes file1.txt and file2.txt files at the same time. What is Linux rmdir Command? Explanation rmdir COMMAND: rmdir command is used to delete/remove a directory and its subdirectories. SYNTAX: The Syntax is rmdir [options..] Directory OPTIONS: Allow users to remove the directory dirname and its parent directories which become empty. EXAMPLE: -p 1. To delete/remove a directory
rmdir tmp

rmdir command will remove/delete the directory tmp if the directory is empty. 2. To delete a directory tree:
rm -ir tmp

This command recursively removes the contents of all subdirectories of the tmp directory, prompting you regarding the removal of each file, and then removes the tmp directory itself. What is Linux route Command? Explanation route COMMAND: route command displays routing table resides in kernel and also used to modify the routing table.The tables which specifies how packets are routed to a host is called routing table. SYNTAX: The Syntax is route [options] OPTIONS: -n -e add del dispalys routing table in numerical[IP Address] format dispalys routing table in Hostname format Adds a new route to the routing table Deletes a route from the routing table

Options used with add and del : -net Indicate the target is network -host Indicate the target is host gw Specifies the gateway of target host/network Used to specifiy the subnet-mask of destination netmask network/host Specify the device or interface where the packets will be dev sent reject rejects the packets sent to particular route/host EXAMPLE: 1. To dispaly the routing table:
route -n

The above command will print:


Destination Gateway Genmask Flags Metric Ref 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 Use 0 0 0 Iface eth0 eth0 eth0

In above table: Destination -Indicates the IP address of desination host/network Gateway -Indicates gateway from which desination host/network could be reached Genmask -Indicates the subnetmask destination Flags -Indicates the current status of route o U - Route is up o H - Target is a host Iface o G - Use gateway -Indicates the interface

2. To add static route to a network in the routing table: route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
In above command: add -Indicates that the route is added to routing table. -net -Indicates that desination is a network. 192.168.0.1 -Indicates IP address of destination network. netmask -Indicates the subnetmask of destination network. gw 192.168.1.1 -Indicates the gateway of destination network. dev eth0 -Indicates that the packets are routed via the interface eth0.

3. To delete a route from the routing table: route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0 The above command will delete the route to 192.168.1.0 from the routing table. What is Linux sort Command? Explanation sort COMMAND: sort command is used to sort the lines in a text file. SYNTAX: The Syntax is sort [options] filename OPTIONS: -r Sorts in reverse order. -u If line is duplicated display only once. -o filename Sends sorted output to a file. EXAMPLE:
1. sort test.txt

Sorts the 'test.txt'file and prints result in the screen.

2.

sort -r test.txt

Sorts the 'test.txt' file in reverse order and prints result in the screen. What is Linux sed Command? Explanation sed COMMAND: sed is a stream editor. sed command helps to edit or delete all occurrences of one string to another within a file. It takes a file as input and prints the result on screen or redirects the output to a specified file. SYNTAX: The Syntax is sed [options] '{command}' [filename] OPTIONS: Command and its function -n do not output the trailing newline -e enable interpretation of the backslash-escaped characters listed below -E disable interpretation of those sequences in STRINGs Without -E, the following sequences are recognized and interpolated: \NNN the character whose ASCII code is NNN (octal) \a alert (BEL) \b Backspace \c suppress trailing newline \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab EXAMPLE: Lets assume that we have a file file1.txt and it has the following data. hscripts has many valuable free scripts It is the parent site of www.forums.hscripts.com hscripts include free tutorials and free gif images free DNS lookup tool Purchase scripts from us A webmaster/web master resource website
1. sed G file1.txt>file2.txt

2. In the above example, using the sed command with G would double space the file file1.txt and output the results to the file2.txt.
3. sed = file1.txt | sed 'N;s/\n/\. /'

In the above example, sed command is used to output each of the lines in file1.txt with the line number followed by a period and a space before each line.
4. sed 's/scripts/javascript/g' file1.txt

Opens the file file1.txt and searches for the word 'scripts' and replaces every occurrence with the word 'javascript'.
5. sed -n '$=' file1.txt

The above command count the number of lines in the file1.txt and output the results. What is Linux Shutdown Command? Explanation Shutdown COMMAND: Shutdown - Turn off the computer immediately or at a specified time. Shutdown / Turn off brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified delay. All processes are first notified that the system is going down by the signal SIGTERM. This gives programs like vi(1) the time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc. Shutdown does its job by signalling the init process, asking it to change the runlevel. Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a state where administrative tasks can be performed; this is the default if neither the -h or -r flag is given to shutdown. To see which actions are taken on halt or reboot see the appropriate entries for these runlevels in the file /etc/inittab. SYNTAX: The Syntax is /sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message] OPTIONS: -a -t sec -k -r -h -H -P Use /etc/shutdown.allow. Tell init(8) to wait sec seconds between sending processes the warning and the kill signal, before changing to another runlevel. Dont really shutdown; only send the warning messages to everybody. Reboot after shutdown. Halt or poweroff after shutdown. Halt action is to halt or drop into boot monitor on systems that support it. Halt action is to turn off the power.

-f Skip fsck on reboot. -F Force fsck on reboot. -c Cancel an already running shutdown. EXAMPLE: shutdown 10:00 Shutdown the computer at 10-oclock What is Linux tail Command? Explanation tail COMMAND: tail command is used to display the last or bottom part of the file. By default it displays last 10 lines of a file. SYNTAX: The Syntax is tail [options] filename OPTIONS: To specify the units of lines. To specify the units of blocks. To specify how many lines you want to display. The number option-argument must be a decimal integer whose sign affects the -c number location in the file, measured in bytes. The number option-argument must be a decimal integer whose sign affects the -n number location in the file, measured in lines. EXAMPLE:
1. tail index.php

-l -b -n

It displays the last 10 lines of 'index.php'.


2. tail -2 index.php

It displays the last 2 lines of 'index.php'.


3. tail -n 5 index.php

It displays the last 5 lines of 'index.php'.


4. tail -c 5 index.php

It displays the last 5 characters of 'index.php'.

What is Linux tar Command? Explanation tar COMMAND: tar command is used to create archive and extract the archive files. SYNTAX: The Syntax is tar [options] [archive-file] [File or directory to be archived] OPTIONS: -c Creates Archive -x Extract the archive -f creates archive with give filename -t displays or lists files in archived file -u archives and adds to an existing archive file -v Displays Verbose Information -A Concatenates the archive files EXAMPLE: 1. To archive a directory or file :
tar -cvf backup.tar /etc

This command creates a tarfile called backup.tar which is the archive of /etc directory.
Where, backup.tar - Is a tar file created /etc - Is a directory archived

2. To archive a directory or file and store it in a storage device:


tar -cvf /dev/fd0 /home/user1/HGB

This command will archive /etc directory and store it in floppy-disk.


Where, /dev/fd0 - Is a floppy-disk name where the archive is stored /home/user1/HGB - Is a directory archived

3. To Extract the archive:


tar -xvf backup.tar

This command will extract the backup.tar file 4. To List The File In An Archive:

tar -tvf backup.tar

The above command will display the files and directories that archived in backup.tar. What is Linux useradd Command? Explanation useradd COMMAND: useradd - Adds new user to the linux system, with specified user-name. When a new user is added then a corresponding entry is made in files /etc/passwd, /etc/group and /etc/shadow SYNTAX: The Syntax is useradd [options] [username] OPTIONS: -d Specifies the users home directory -s Specifies the users shell -g Specifies the users primary group -G Specifies the users secondary groups -M Specifies not to create home directory for the user -e Specifies the expire date of the user -uid Specifies the user-id of the user EXAMPLE: 1. To add new user:
useradd hiox

This command will add a new user with name hiox. 2. To add user but not allow to login in the system:
useradd -s /bin/nologin hiox

This command will add user hiox but not allow to login.
In above command: hiox -Is the user-name /bin/nologin -Is Shell assigned to the user

3. To set expire date of the user:


useradd -e 2008-06-30 hiox

This command will add user hiox and set the expire date to 2008-06-30.

In above command: hiox -Is the user-name 2008-06-30 -Is date on which the user-account will be expired

4. To create user without creating home directory:


useradd -M hiox

The above command will create user hiox but home directory will not be created. What is Linux who Command? Explanation who COMMAND: who command can list the names of users currently logged in, their terminal, the time they have been logged in, and the name of the host from which they have logged in. SYNTAX: The Syntax is who [options] [file] OPTIONS: Print the username of the invoking user, The 'am' and 'i' must be space separated. -b Prints time of last system boot. -d print dead processes. -H Print column headings above the output. Include idle time as HOURS:MINUTES. An idle time of . indicates activity -i within the last minute. -m Same as who am i. -q Prints only the usernames and the user count/total no of users logged in. -T,-w Include user's message status in the output. EXAMPLE: am i
1. who -uH

Output:
NAME LINE TIME IDLE PID COMMENT hiox ttyp3 Jul 10 11:08 . 4578

This sample output was produced at 11 a.m. The "." indiacates activity within the last minute. 2. who am i

who am i command prints the user name. What is Linux whois Command? Explanation whois COMMAND: whois command lists the information about the domain owner of the given domain. SYNTAX: The Syntax is whois [option] query OPTIONS: -h Host which holds the identification information in its database. -p connect to the specified port. EXAMPLE:
1. whois hscripts.com

Output: The above command will produce the following output.


[Querying whois.internic.net] [Redirected to whois.PublicDomainRegistry.com] [Querying whois.PublicDomainRegistry.com] [whois.PublicDomainRegistry.com] Registration Service Provided By: HIOX INDIA Contact: +91.4226547769 Domain Name: HSCRIPTS.COM Registrant: HIOX INDIA Rajesh Kumar (support@hioxindia.com) 32, North Street, Krishnapuram, Singanallur Coimbatore tamil nadu,641005 IN Tel. +91.04225547769 Creation Date: 06-Oct-2004 Expiration Date: 06-Oct-2008 Domain servers in listed order: ns1.hscripts.com ns2.hscripts.com Administrative Contact: HIOX INDIA

Rajesh Kumar (support@hioxindia.com) 32, North Street, Krishnapuram, Singanallur Coimbatore tamil nadu,641005 IN Tel. +91.04225547769 Technical Contact: HIOX INDIA Rajesh Kumar (support@hioxindia.com) 32, North Street, Krishnapuram, Singanallur Coimbatore tamil nadu,641005 IN Tel. +91.04225547769 Billing Contact: HIOX INDIA Rajesh Kumar (support@hioxindia.com) 32, North Street, Krishnapuram, Singanallur Coimbatore tamil nadu,641005 IN Tel. +91.04225547769 Status:ACTIVE The data in this whois database is provided to you for information purposes only, that is, to assist you in obtaining information about or related to a domain name registration record. We make this information available "as is", and do not guarantee its accuracy. By submitting a whois query, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: (1) enable high volume, automated, electronic processes that stress or load this whois database system providing you this information; or (2) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via fascimile, electronic mail, or by telephone. The compilation, repackaging, dissemination or other use of this data is expressly prohibited without prior written consent from us. The registrar of record is PublicDomainRegistry. We reserve the right to modify these terms at any time. By submitting this query, you agree to abide by these terms.

What is Linux yes Command? Explanation yes COMMAND:

yes command repeatedly prints the given string separated by a space and followed by a newline until it is killed. If no string is given, it just prints 'y' repeatedly until it is killed. It is normally used in scripts, its output is piped to a command or program that prompts you to do this or that (do you want to delete this file press 'y' or 'n') SYNTAX: The Syntax is yes [string..] yes [options..] OPTIONS: --help Print help message and exit -Print version and exit version EXAMPLE: 1. Print the given string repeatedly:
yes "hscripts"

The above command will print hscripts repeatedly until it is killed(CTRL+C). 2. To delete a file without pressing any key when it prompts:
yes | rm -i *.txt

In the above example, the yes command is piped with rm command. Normally rm -i will prompt you to remove the file, to remove the file you have to type either y(yes) or n(no). When it is piped with yes by default, the yes will print y and all the txt files will be removed automatically, so that you dont need to type y for every txt files.
yes n | rm -i *.txt

The above example says not to remove a file when rm -i prompts to remove the file.

S-ar putea să vă placă și