0% found this document useful (0 votes)
84 views7 pages

UNIX BASICS - Beginners Guide For Unix Commands - by Meenakshi

The document provides an overview of common Unix commands like ls, cd, rm, mkdir, cp, and find. It describes what each command is used for and provides examples of basic syntax and usage.

Uploaded by

pravin216
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views7 pages

UNIX BASICS - Beginners Guide For Unix Commands - by Meenakshi

The document provides an overview of common Unix commands like ls, cd, rm, mkdir, cp, and find. It describes what each command is used for and provides examples of basic syntax and usage.

Uploaded by

pravin216
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 7

UNIX BASICS - Beginners guide for Unix commands - by Meenakshi

For more software testing articles visit !tt" ##www$softwaretesting!el"$com

%ain features of unix


%ulti user - More than one user can use the machine %ultitas&ing- More than one program can be run at a time. 'ortability ( This means the operating system can be easily converted to run on different browsers.

Commands
ls when invoked without any arguments, lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. Files whose names start with . are not listed, unless the -a flag is specified or the files are specified e!plicitly. "ithout options, ls displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and si#e of the files. The most common options to reveal this information or change the list of files are$ long format, displaying %ni! file type, permissions, number of hard links, owner, si#e, date, and filename
-l -F -a -R

group,

appends a character revealing the nature of a file, for e!ample, * for an e!ecutable, or / for a directory. &egular files have no suffi!. lists all files in the given directory, including those whose names start with . 'y default, these files are e!cluded from the list. recursively lists subdirectories. The command ls -R / would therefore list all files.

cd Is a command line command used to change the current working directory in the %ni! and ()* operating systems. It is also available for use in %ni! shell scripts or ()* batch files. cd is

fre+uently included built into certain shells such as the 'ourne shell, tcsh, bash ,where it calls the chdir() -)*I. / function0 and in ()*1s /)MMA2(./)M. A directory is a logical section of a filesystem used to hold files. (irectories may also contain other directories. The cd command can be used to change into a subdirectory, move back into the parent directory, move all the way back to the root ,3 in %2I., 4 in ()*0 or move to any given directory. "wd command ,"rint working directory0 is used to print the name of current working directory from a computer1s command-line interface. If the shell prompt does not already show this, the user can use this command to find their place in the directory tree. This command is found in the %ni! family of operating systems and other flavors as well. The ()* e+uivalent is CD with no arguments. It is a command which is sometimes included built into certain shells such as sh, and bash. It can be implemented easily with the -)*I. / functions getcwd() and3or getwd(). 5!ample$ 6 pwd 3home3foobar mkdir command in the %ni! operating system is used to make a new (irectory. 2ormal usage is as straightforward as follows$ mkdir name7of7directory "here name_of_directory is the name of the directory one wants to create. "hen typed as above ,ie. normal usage0, the new directory would be created within the current directory. rm ,short for remove0 is a %ni! command used to delete files from a filesystem. /ommon options that rm accepts include$ -r, which processes subdirectories recursively -i, which asks for every deletion to be confirmed -f, which ignores non-e!istent files and overrides any confirmation prompts , force 0 rm is often aliased to rm -i so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option. rm -rf ,variously, rm -rf 3 , rm -rf 8 , and others0 is fre+uently used in 9okes and anecdotes about %ni! disasters. The rm -rf 3 variant of the command, if run by an administrator, would cause the contents of every mounted disk on the computer to be deleted.
rmdir

is a command which will remove an empty directory on a %ni!-system. It cannot be capitali#ed. 2ormal usage is straightforward where one types$ rmdir name7of7directory "here name7of7directory corresponds with the name of the directory one wishes to delete. There are options to this command such as -" which removes parent directories if they are also empty. For e!ample$ rmdir :p foo3bar3ba# "ill first remove ba#3, then bar3 and finally foo3 thus removing the entire directory tree specified in the command argument. )ften rmdir will not remove a directory if there is still files present in the directory. To force the removal of the directory even if files are present usually the -rf flag can be used. For e!ample$ rmdir -&f for3bar3ba#

cp is the command entered in a %ni! shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name. To /opy a File to another File cp ; -f < ; -h < ; -i < ; -p <; -- < *ourceFile TargetFile To /opy a File to a (irectory cp ; -f < ; -h < ; -i < ; -p < ; -r = -& < ; -- < *ourceFile ... Target(irectory To /opy a (irectory to a (irectory cp ; -f < ; -h < ; -i < ; -p < ; -- < > -r = -& ? *ource(irectory ... Target(irectory -f ,force0 : specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command. -! : makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point. -i ,interactive0 : prompts you with the name of a file to be overwritten. This occurs if the Target(irectory or TargetFile parameter contains a file with the same name as a file specified in the *ourceFile or *ource(irectory parameter. If you enter y or the locale1s e+uivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file. -" ,preserve0 : duplicates the following characteristics of each *ourceFile3*ource(irectory in the corresponding TargetFile and3or Target(irectory$ )xam"les To make a copy of a file in the current directory, enter$ cp prog.c prog.bak

This copies prog.c to prog.bak. If the prog.bak file does not already e!ist, the cp command creates it. If it does e!ist, the cp command replaces it with a copy of the prog.c file. To copy a file in your current directory into another directory, enter$ cp 9ones 3home3nick3clients This copies the 9ones file to 3home3nick3clients39ones. To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter$ cp -p smith smith.9r This copies the smith file to the smith.9r file. Instead of creating the file with the current date and time stamp, the system gives the smith.9r file the same date and time as the smith file. The smith.9r file also inherits the smith file1s access control protection. To copy all the files in a directory to a new directory, enter$ cp 3home39anet3clients38 3home3nick3customers This copies only the files in the clients directory to the customers directory. To copy a directory, including all its files and subdirectories, to another directory, enter$ cp -& 3home3nick3clients 3home3nick3customers This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers3clients directory. To copy a specific set of files to another directory, enter$ cp 9ones lewis smith 3home3nick3clients This copies the 9ones, lewis, and smith files in your current working directory to the 3home3nick3clients directory. To use pattern-matching characters to copy files, enter$ cp programs38.c . This copies the files in the programs directory that end with .c to the current directory, signified by the single . ,dot0. @ou must type a space between the c and the final dot.

find program is a search utility, mostly found on %ni!-like platforms. It searches through a directory tree of a filesystem, locating files based on some user-specified criteria. 'y default, find returns all files below the current working directory. Further, find allows the user to specify an action to be taken on each matched file. Thus, it is an e!tremely powerful program for applying actions to many files. It also supports rege!p matching.

)xam"les From current directory find . -name my48 This searches in the current directory ,represented by a period0 and below it, for files and directories with names starting with my. The backslash before the star is needed to avoid the shell e!pansion. "ithout the backslash, the shell would replace my* with the list of files whose names begin with my in the current directory. An alternative is to enclose the the arguments in +uotes$
find . -name "my*"

Files only find . -name my8 -type f This limits the results of the above search to only regular files, therefore e!cluding directories, special files, pipes, symbolic links, etc. my* is enclosed in +uotes as otherwise the shell would replace it with the list of files in the current directory starting with my Commands The previous e!amples created listings of results because, by default, find e!ecutes the 1-print1 action. ,2ote that early versions of the find command had no default action at allA therefore the resulting list of files would be discarded, to the bewilderment of naBve users.0 find . -name my8 -type f -ls This prints an e!tended file information. Searc! all directories find 3 -name myfile -type f -print This searches every file on the computer for a file with the name myfile. It is generally not a good idea to look for data files this way. This can take a considerable amount of time, so it is best to specify the directory more precisely. S"ecify a directory find 3home3brian -name myfile -type f -print This searches for files named myfile in the /home/brian directory, which is the home directory for the user brian. @ou should always specify the directory to the deepest level you can remember. Find any one of differently named files find . , -name 89sp -or -name 89ava 0 -type f -ls This prints e!tended information on any file whose name ends with either 19sp1 or 19ava1. 2ote that the parentheses are re+uired. Also note that the operator or can be abbreviated as o . The and operator is assumed where no operator is given. In many shells the parentheses must be escaped with a backslash, 4, and 40 , to prevent them from being interpreted as special shell characters. touc!

is a program on %ni! and %ni!-like systems used to change a file1s date- and time-stamp. It can also be used to create an empty file. The command-synta! is$ touch ;options< Cfile7nameD If the file e!ists, its access and modification time-stamps are set to the system1s current date and time, as if the file had been changed. To touch a file simulates a change to the file. If the file does not e!ist, an empty file of that name is created with its access and modification time-stamps set to the system1s current date and time. If no file path is specified, the current directory is assumed. can be invoked with options to change its behaviour, which may vary from one %ni! to another. )ne option makes it possible to set the file1s time-stamp to something other than the current system date and time, but this action is normally restricted to the owner of the file or the system1s superuser.
touch

ec!o is a command in %ni! ,and by e!tension, its descendants, such as Einu!0 and M*-()* that places a string on the terminal. It is typically used in shell scripts and batch programs to output status te!t to the screen or a file. 6 echo This is a test. This is a test. 6 echo This is a test. D .3test.t!t 6 cat .3test.t!t This is a test. cat program concatenates the contents of files, reading from a list of files and3or standard input in se+uence and writing their contents in order to standard output. cat takes the list of files as arguments but also interprets the argument - as standard input. 5!ample$ w!o The %ni! command who displays a list of users who are currently logged into a computer. The command accepts various options that vary by system to further specify the information that is returned, such as the length of time a particular user has been connected or what pseudo-teletype a user is connected to. The who command is related to the command w, which provides the same information but also displays additional data and statistics. )xam"le out"ut userFG userMJ pts3HI pts3MN Apr FJ KJ$LK Apr FJ KG$IK ,localhost0 ,localhost0 cat filename

du ,abbreviated from disk usage0


is a %ni! computer program to display the amount of disk space used under a particular directory or files on a file system. counts the disk space by walking the directory tree. As such, the amount of space on a file system shown by du may vary from that shown by df if files have been deleted but their blocks not yet freed.
du

In Einu!, it is a part of the O2% /oreutils package. The du utility first appeared in version F of ATPT %2I.. )xam"le The -& flag will show the si#es in FQ blocks, rather than the default of IFM byte blocks. 6du -k 3seclog L 3seclog3lostRfound FHM 3seclog3backup3ai!N FHS 3seclog3backup LLKLL 3seclog3temp LHGMSL 3seclog *e will discuss more advanced commands in t!e next article$

For more software testing resources visit following "ages


Software +esting articles http$33www.softwaretestinghelp.com3sitemap3 ,A#+esting -ob o"enings$ http$33www.softwaretestinghelp.com39obs3 Software +esting .el" http$33www.softwaretestinghelp.com3 Copyright 2008: http$33www.softwaretestinghelp.com

You might also like