Вы находитесь на странице: 1из 19

http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.cmds%2Fdoc %2Faixcmds3%2Fmv.htm http://www.youtube.com/watch?v=CVUZYT3zcRo-------> youtube basic linux command http://www.cyberciti.biz/faq/copy-command/ --> basic Linux command http://www.thegeekstuff.

com/2009/07/linux-ls-command-examples/--> basic linux command http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.cmds%2Fdoc %2Faixcmds3%2Fls.htm--> basic Linux command Basic Linux Commands:

CAT
ex:

---> To create a New file

$cat>amulraj.txt apple Orange press (ctrl+d) You can display the content of the file using cat cammand. Ex: $cat amulraj its shows the content of the amulraj file

touchex:

-->To create a New Empty Files:

$touch filename

mkdirEx:

--> To create a New Directory

$mkdir amulraj

rmdir
Ex:

---> To remove a Directory

$rm amulraj

chdirEx:

--> To change the path from one into another.

$mkdir amulraj $cd amulraj $amjulraj> cd cd cd cd cd .. /home/tim/projects ~/projects ~tim/projects $HOME/projects

lsEx:

--> List the content of the Current directory

$amulraj>ls Its list out the content of the amulraj folder


1. Open Last Edited File Using ls -t Display One File Per Line Using ls -1 $ ls -1
bin boot cdrom dev etc home initrd initrd.img lib

3. Display All Information About Files/Directories Using ls -l $ ls -l -rw-r----- 1 ramesh team-dev 9275204 Jun 13 15:27 mthesaur.txt.gz

Just try: $ ls -l --> $ ls -lh --> $ ls -l /etc --> $ ls -ld /etc --> $ ls -lt--> $ ls -ltr--> $ ls -a--> $ ls -A--> ls -q--> $ ls --color=auto-->

copySyn:
cp cp cp cp cp

--> copy the content from source into destination

SOURCE DEST SOURCE DIRECTORY SOURCE1 SOURCE2 SOURCE3 SOURCEn DIRECTORY [OPTION] SOURCE DEST [OPTION] SOURCE DIRECTORY

To copy a file in your current directory into another directory, enter Ex: $ cp filename /tmp $ ls /tmp/filename $ cd /tmp

$ ls $ rm filename To copy all the files in a directory to a new directory, enter: $ cp * /home/tom/backup To copy a directory, including all its files and subdirectories, to another directory, enter (copy directories recursively): $ cp -R * /home/tom/backup

mvsyn: ex:

-> To move and rename a directories or files

mv oldname newname mv filename /dest/di

mv sourceDir destDir

Rename A File
Type the mv command to rename foo.txt to bar.txt:
mv foo.txt bar.txt ls

Rename A Directory
Type the following command to rename a directory in the current directory
mv oldDir newDir mv letters letters.old

Examples
1. To rename a file, enter:
mv appendix apndx.a

This command renames appendix to apndx.a. If a file named apndx.a already exists, its old contents are replaced with those of appendix. 2. To move a directory, enter:
mv book manual

This command moves all files and directories under book to the directory named manual, if manual exists. Otherwise, the directory book is renamed manual. 3. To move a file to another directory and give it a new name, enter:
mv intro manual/chap1

This command moves intro to manual/chap1. The name intro is removed from the current directory, and the same file appears as chap1 in the directory manual. 4. To move a file to another directory, keeping the same name, enter:
mv chap3 manual

This command moves chap3 to manual/chap3 Note: Examples 1 and 3 name two files, example 2 names two existing directories, and example 4 names a file and a directory. 5. To move several files into another directory, enter:
mv chap4 jim/chap5 /home/manual

This command moves the chap4 file to the /home/manual/chap4 file directory and the jim/chap5 file to the /home/manual/chap5 file. 6. To use the mv command with pattern-matching characters, enter:
mv manual/* .

This command moves all files in the manual directory into the current directory . (period), retaining the names they had in manual. This move also empties manual. You must type a space between the asterisk and the period. Note: Pattern-matching characters expand names of existing files only. For example, the command mv intro man*/chap1 does not work if the file manual/chap1 does not exist.

Head

--> Displays the first few lines of a file.

Examples

To display the first five lines of the Test file, enter:


head -5 test

OR
head -n 5 test

tail

--> Displays the last few lines of a file

syn: To Display Lines in Reverse Order tail [ -r ] [ -n Number ] [ File ]

Examples
1. To display the last 10 lines of the notes file, enter:
tail notes

2. To specify the number of lines to start reading from the end of the notes file, enter: tail -n 20 notes 3. To display the notes file a page at a time, beginning with the 200th byte, enter: tail -c +200 notes | pg 4. To follow the growth of a file, enter: tail -f accounts This displays the last 10 lines of the accounts file. The tail command continues to display lines as they are added to the accounts file. The display continues until you press the Ctrl-C key sequence to stop it.

More
Syn:

Displays file contents one screen at a time.

more [ -c ] [ -d ] [ -e ] [ -H ] [ -i ] [ -l ] [ -N ] [ -s ] [ -u ] [ -v ] [ -z ] [ -n Number ] [ -p Subcommand ] [ -t Tagstring ] [ -W Option ] [ -x Tabs ] [ File ... ]

Examples
1. To view a file named myfile, enter:
more myfile

2. To view output from the nroff command, enter:


ls -l | more

3. To view each file starting at its last screen, enter:


more -p G file1 file2

4. To view each file with the 100th line at the current position, enter:
more -p 100 file1 file2

Typically, the current position in a more command display is the third line on the screen. In this example, the first line on the screen is the 98th line in the file. 5. To view each file starting with the first line that contains the foo string, enter:
more -p /foo file1 file2

The more command displays the line in the current position, the third line on the screen.

hostname
Syntax

--> Sets or displays the name of the current host system.

/usr/bin/hostname [ HostName ] [ -s ] The /usr/bin/hostname command displays the name of the current host system. Only users with root user authority can set the host name. The mkdev command and the chdev commands also set the host name permanently. Use the mkdev command when you are defining the TCP/IP instance for the first time. You can use the System application in Web-based System Manager (wsm) to change system characteristics. You could also use the System Management Interface Tool (SMIT) smit mkhostname fast path to run this command.

Flags
-s Trims any domain information from the printed name.

Parameters
HostName Sets the primary name of the host. Note: You must have root user authority to use the HostName parameter.

date-

-> Tells you the date and time in Unix.

date--->List the date and time of the server. Below is an example of the output. Thu Feb 8 16:47:32 MST 2001 date -s "11/20/2003 12:48:00" Set the date to the date and time shown. date '+DATE: %m/%d/%y%nTIME:%H:%M:%S' Would list the time and date in the below format. DATE: 02/08/01 TIME:16:44:55

time--->
$time

Used to time a simple command.

Its display current time

dc--> clear--->

desktop calculator Clearscreen

Enters the desk calculator, below is a short example of what can be done: 1234 - Enter base value of 1234 1234 2 * p - Takes the value of 1234 times 2 and prints value 2468 468 - p - Takes the value of 2468 and subtracts 468 2000 2 / p - Takes the value of 2000 and divides by 2. 1000 v p - Takes the value of 1000 and square roots it. 31 q - Quits the desk calucator pr---> Print the files

bc-->

to do a basic calculation

$bc 3*4 its shows 12

echo-->

display the information

$echo 4 * 5 | bc its shows 20 directly $echo hi this is amulraj

its shows hi this is amulraj

cal

---> display the calender details

$cal Its shows current date calender

free-$free

> its shows the free space of the current system

gzip$ls

-> to compress the file into zip format

$gzip test 1 test1 test.gz

gunzip$ls 1 test1 test

--> Unzip the file

$gunzip test.gz

kill-

-> to stop the current process like end process in task mananger

$kill 1899 1899 means process number

man wc
ex:

---> we can learn more details about one particular command we can use man

$man cat we can learn more about cat --> to display the no of char and line and word in a file

$cat test | wc

if test file contain hi this is amulr

its shows 1 1->line 4-> words 17-> char with null value 4 17

whichex: $which ls its shows /bin/ls

-> this is used to view the location of command

ls located in /bin in computer $which cat /bin/cat

who

Who logged in currently

who [OPTION]... [ FILE | ARG1 ARG2 ]

DESCRIPTION
-a, --all same as -b -d --login -p -r -t -T -u -b, --boot time of last system boot -d, --dead print dead processes -H, --heading print line of column headings -i, --idle add idle time as HOURS:MINUTES, . or old (deprecated, use -u) --login print system login processes (equivalent to SUS -l) -l, --lookup attempt to canonicalize hostnames via DNS (-l is deprecated, use --lookup)

-m only hostname and user associated with stdin -p, --process print active processes spawned by init -q, --count all login names and number of users logged on -r, --runlevel print current runlevel -s, --short print only name, line, and time (default) -t, --time print last system clock change -T, -w, --mesg add user's message status as +, - or ? -u, --users list users logged in

eject dos2unix
dos2unix

--->eject the current device --> dos2unix - DOS/MAC to UNIX text file format converter

Get input from stdin and write output to stdout.

Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt

Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt

EXAMPLES
Eject the default device: eject Eject a device or mount point named cdrom: eject cdrom Eject using device name: eject /dev/cdrom Eject using mount point: eject /mnt/cdrom/ Eject 4th IDE device: eject hdd Eject first SCSI device: eject sda Eject using SCSI partition name (e.g. a ZIP drive): eject sda4 Select 5th disc on mult-disc changer: eject -v -c5 /dev/cdrom Turn on auto-eject on a SoundBlaster CD-ROM drive: eject -a on /dev/sbpcd

whoami-

-> to display user name of the user

$whoami its shows current user name

password
Current Password: New Password: Confirm New Password:

--> change your password

passwd - entering just passwd would allow you to change the password. After entering passwd you will receive the following three prompts:

Each of these prompts must be entered and entered correctly for the password to be successfully changed.

IP Display Current Config for all NIC's: ifconfig Display Current Config for eth0: ifconfig eth0 Assign IP: ifconfig eth0 192.168.1.2 Ping: ping -c 3 192.168.1.1 Assign multiple IP's: ifconfig eth0:0 192.168.1.2 Assign second IP: ifconfig eth0:1 192.168.1.3 Disable network card: ifconfig eth0 down Enable network card: ifconfig eth0 up View current routing table: route "or" route -n View arp cache: arp "or" arp -n Assign IP/Subnet: ifconfig eth0 192.168.1.2 netmask 255.255.255.0 Assign Default Gateway: route add default gw 192.168.1.1 Trace Route: traceroute www.whatismyip.com Trace Path: tracepath www.whatismyip.com

DNS Test: host www.whatismyip.com Advanced DNS Test: dig www.whatismyip.com Reverse Lookup: host 66.11.119.69 Advanced Reverse Lookup: dig -x 66.11.119.69 *You MUST be at the ROOT user to make/save any changes. Linux users, your distribution will determine the location of your network config file which will need to be updated and saved in order for the changes to remain in effect after rebooting. Network cards are referred to as eth0, eth1, eth2, etc based on their position on the PCI bus. *Special thanks to Gergely for the Linux commands!

Vi
What is vi?
The default editor that comes with the UNIX operating system is called vi (visual editor). [Alternate editors for UNIX environments include pico and emacs, a product of GNU.] The UNIX vi editor is a full screen editor and has two modes of operation: 1. Command mode commands which cause action to be taken on the file, and 2. Insert mode in which entered text is inserted into the file. In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the <Esc> (Escape) key turns off the Insert mode. While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, this Web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become automatic. NOTE: Both UNIX and vi are case-sensitive. Be sure not to use a capital letter in place of a lowercase letter; the results will not be what you expect.

To Get Into and Out Of vi


To Start vi To use vi on a file, type in vi filename. If the file named filename exists, then the first

page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text. * vi filename edit filename starting at line 1

vi -r filename recover filename that was being edited when system crashed To Exit vi Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file. Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the <Return> (or <Enter>) key. * :x<Return> :q<Return> quit vi, writing out modified file to file named in original invocation quit (or exit) vi

:wq<Return> quit vi, writing out modified file to file named in original invocation * :q!<Return> quit vi even though latest changes have not been saved for this vi call

Moving the Cursor


Unlike many of the PC and MacIntosh editors, the mouse does not move the cursor within the vi editor screen (or window). You must use the the key commands listed below. On some UNIX platforms, the arrow keys may be used as well; however, since vi was designed with the Qwerty keyboard (containing no arrow keys) in mind, the arrow keys sometimes produce strange effects in vi and should be avoided. If you go back and forth between a PC environment and a UNIX environment, you may find that this dissimilarity in methods for cursor movement is the most frustrating difference between the two. In the table below, the symbol ^ before a letter means that the <Ctrl> key should be held down while the letter key is pressed. * j or <Return> [or down-arrow] h or <Backspace> [or left-arrow] l or <Space> [or right-arrow] move cursor down one line move cursor up one line move cursor left one character move cursor right one character move cursor to start of current line (the one with the cursor)

* k [or up-arrow] * *

* 0 (zero)

* $ w b

move cursor to end of current line move cursor to beginning of next word move cursor back to beginning of preceding word

:0<Return> or 1G move cursor to first line in file :n<Return> or nG move cursor to line n :$<Return> or G move cursor to last line in file

Screen Manipulation
The following commands allow the vi editor screen (or window) to move up or down several lines and to be refreshed. ^f move forward one screen ^b move backward one screen ^d move down (forward) one half screen ^u move up (back) one half screen ^l redraws the screen ^r redraws the screen, removing deleted lines

Adding, Changing, and Deleting Text


Unlike PC editors, you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables. Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step. * u UNDO WHATEVER YOU JUST DID; a simple toggle The main purpose of an editor is to create, add, or modify text for a file. Inserting or Adding Text The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode. * i insert text before cursor, until <Esc> hit

I insert text at beginning of current line, until <Esc> hit * a append text after cursor, until <Esc> hit A append text to end of current line, until <Esc> hit * o open and put text in a new line below current line, until <Esc> hit * O open and put text in a new line above current line, until <Esc> hit Changing Text The following commands allow you to modify text. * r R cw cNw C cc Ncc or cNc replace single character under cursor (no <Esc> needed) replace characters, starting with current cursor position, until <Esc> hit change the current word with new text, starting with the character under cursor, until <Esc> hit change N words beginning with character under cursor, until <Esc> hit; e.g., c5w changes 5 words change (replace) the characters in the current line, until <Esc> hit change (replace) the entire current line, stopping when <Esc> is hit change (replace) the next N lines, starting with the current line, stopping when <Esc> is hit

Deleting Text The following commands allow you to delete text. * x Nx dw dNw D * dd Ndd or dNd delete single character under cursor delete N characters, starting with character under cursor delete the single word beginning with character under cursor delete N words beginning with character under cursor; e.g., d5w deletes 5 words delete the remainder of the line, starting with current cursor position delete entire current line delete N lines, beginning with the current line; e.g., 5dd deletes 5 lines

Cutting and Pasting Text The following commands allow you to copy and paste text. yy copy (yank, cut) the current line into the buffer

Nyy or yNy copy (yank, cut) the next N lines, including the current line, into the buffer p put (paste) the line(s) in the buffer into the text after the current line

Other Commands
Searching Text A common occurrence in text editing is to replace one word or phase by another. To locate instances of particular sets of characters (or strings), use the following commands. /string search forward for occurrence of string in text ?string search backward for occurrence of string in text n N move to next occurrence of search string move to next occurrence of search string in opposite direction

Determining Line Numbers Being able to determine the line number of the current line or the total number of lines in the file being edited is sometimes useful. :.= returns line number of current line at bottom of screen := ^g returns the total number of lines at bottom of screen provides the current line number, along with the total number of lines, in the file at the bottom of the screen

Saving and Reading Files


These commands permit you to input and output files other than the named file with which you are currently working. :r filename<Return> :w<Return> :w newfile<Return> :12,35w smallfile<Return> :w! prevfile<Return> read file named filename and insert after current line (the line with cursor) write current contents to file named in original vi call write current contents to a new file named newfile write the contents of the lines numbered 12 through 35 to a new file named smallfile write current contents over a pre-existing file named prevfile