SlideShare a Scribd company logo
UNIX BASICS - Beginners guide for Unix commands
                           - by Meenakshi

For more software testing articles visit: http://www.softwaretestinghelp.com


Main features of unix :

Multi user - More than one user can use the machine

Multitasking- More than one program can be run at a time.

Portability – 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 explicitly.
Without options, ls displays files in a bare format. This bare format however makes it
difficult to establish the type, permissions, and size of the files. The most common
options to reveal this information or change the list of files are:
-l  long format, displaying Unix file type, permissions, number of hard links, owner,
group, size, date, and filename
-F    appends a character revealing the nature of a file, for example, * for an executable,
or / for a directory. Regular files have no suffix.

-a lists all files in the given directory, including those whose names start with "." By
default, these files are excluded from the list.
-R 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 Unix
and DOS operating systems. It is also available for use in Unix shell scripts or DOS batch
files. cd is frequently included built into certain shells such as the Bourne shell, tcsh, bash
(where it calls the chdir() POSIX C function) and in DOS's COMMAND.COM.

A directory is a logical section of a filesystem used to hold files. Directories 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 (/ in UNIX,  in
DOS) or move to any given directory.


pwd
command (print working directory) is used to print the name of current working directory
from a computer's 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 Unix family of operating systems and other flavors as well. The
DOS equivalent 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 POSIX C functions getcwd() and/or
getwd().

Example:
$ pwd
/home/foobar

mkdir

command in the Unix operating system is used to make a new Directory. Normal usage is
as straightforward as follows:
mkdir name_of_directory
Where name_of_directory is the name of the directory one wants to create. When typed
as above (ie. normal usage), the new directory would be created within the current
directory.
rm (short for remove)
is a Unix command used to delete files from a filesystem. Common options that rm
accepts include:
-r, which processes subdirectories recursively
-i, which asks for every deletion to be confirmed
-f, which ignores non-existent files and overrides any confirmation prompts ("force")
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 /", "rm -rf *", and others) is frequently used in jokes and
anecdotes about Unix disasters. The "rm -rf /" 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 Unix-system. It cannot be
capitalized. Normal usage is straightforward where one types:
rmdir name_of_directory
Where name_of_directory corresponds with the name of the directory one wishes to
delete. There are options to this command such as -p which removes parent directories if
they are also empty.
For example:
rmdir –p foo/bar/baz
Will first remove baz/, then bar/ and finally foo/ thus removing the entire directory tree
specified in the command argument.
Often 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 example:
rmdir -Rf for/bar/baz


cp
is the command entered in a Unix 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 Copy a File to another File
cp [ -f ] [ -h ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
To Copy a File to a Directory
cp [ -f ] [ -h ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
To Copy a Directory to a Directory
cp [ -f ] [ -h ] [ -i ] [ -p ] [ -- ] { -r | -R } SourceDirectory ... TargetDirectory
-f (force) – specifies removal of the target file if it cannot be opened for write operations.
The removal precedes any copying performed by the cp command.
-h – 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 (interactive) – prompts you with the name of a file to be overwritten. This occurs if the
TargetDirectory or TargetFile parameter contains a file with the same name as a file
specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's
equivalent of y, the cp command continues. Any other answer prevents the cp command
from overwriting the file.
-p (preserve) – duplicates the following characteristics of each
SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
Examples
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 exist, the cp
command creates it. If it does exist, 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 jones /home/nick/clients
This copies the jones file to /home/nick/clients/jones.
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.jr
This copies the smith file to the smith.jr file. Instead of creating the file with the current
date and time stamp, the system gives the smith.jr file the same date and time as the smith
file. The smith.jr file also inherits the smith file's access control protection.
To copy all the files in a directory to a new directory, enter:
  cp /home/janet/clients/* /home/nick/customers
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 -R /home/nick/clients /home/nick/customers
This copies the clients directory, including all its files, subdirectories, and the files in
those subdirectories, to the customers/clients directory.
To copy a specific set of files to another directory, enter:
  cp jones lewis smith /home/nick/clients
This copies the jones, lewis, and smith files in your current working directory to the
/home/nick/clients directory.
To use pattern-matching characters to copy files, enter:
  cp programs/*.c .
This copies the files in the programs directory that end with .c to the current directory,
signified by the single . (dot). You must type a space between the c and the final dot.




find

program is a search utility, mostly found on Unix-like platforms. It searches through a
directory tree of a filesystem, locating files based on some user-specified criteria. By
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 extremely
powerful program for applying actions to many files. It also supports regexp matching.

Examples

From current directory
find . -name my*
This searches in the current directory (represented by a period) and below it, for files and
directories with names starting with my. The backslash before the star is needed to avoid
the shell expansion. Without 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 quotes: find . -name "my*"

Files only
find . -name "my*" -type f
This limits the results of the above search to only regular files, therefore excluding
directories, special files, pipes, symbolic links, etc. my* is enclosed in quotes as
otherwise the shell would replace it with the list of files in the current directory starting
with my

Commands
The previous examples created listings of results because, by default, find executes the '-
print' action. (Note that early versions of the find command had no default action at all;
therefore the resulting list of files would be discarded, to the bewilderment of naïve
users.)
find . -name "my*" -type f -ls
This prints an extended file information.
Search all directories
find / -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.

Specify a directory
find /home/brian -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. You should always specify the directory to the deepest level
you can remember.

Find any one of differently named files
find . ( -name "*jsp" -or -name "*java" ) -type f -ls
This prints extended information on any file whose name ends with either 'jsp' or 'java'.
Note that the parentheses are required. 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, "(" and ")", to prevent them from being
interpreted as special shell characters.


touch
is a program on Unix and Unix-like systems used to change a file's date- and time-stamp.
It can also be used to create an empty file. The command-syntax is:
touch [options] <file_name>
If the file exists, its access and modification time-stamps are set to the system's 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 exist, an empty file of that name is created with its access and
modification time-stamps set to the system's current date and time. If no file path is
specified, the current directory is assumed.
touch can be invoked with options to change its behaviour, which may vary from one
Unix to another. One option makes it possible to set the file's 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 system's superuser.


echo
is a command in Unix (and by extension, its descendants, such as Linux) and MS-DOS
that places a string on the terminal. It is typically used in shell scripts and batch programs
to output status text to the screen or a file.
$ echo This is a test.
This is a test.
$ echo "This is a test." > ./test.txt
$ cat ./test.txt
This is a test.

cat

program concatenates the contents of files, reading from a list of files and/or standard
input in sequence 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.
Example:          cat filename


who
The Unix 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.
Example output
user19 pts/35        Apr 18 08:40       (localhost)
user28 pts/27        Apr 18 09:50       (localhost)


du (abbreviated from disk usage)
is a Unix computer program to display the amount of disk space used under a particular
directory or files on a file system.
du 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.
In Linux, it is a part of the GNU Coreutils package.
The du utility first appeared in version 1 of AT&T UNIX.

Example
The -k flag will show the sizes in 1K blocks, rather than the default of 512 byte blocks.
$du -k /seclog
4    /seclog/lost+found
132 /seclog/backup/aix7
136 /seclog/backup
44044 /seclog/temp
439264 /seclog

We will discuss more advanced commands in the next article.



For more software testing resources visit following pages:
Software Testing articles: http://www.softwaretestinghelp.com/sitemap/
QA/Testing Job openings: http://www.softwaretestinghelp.com/jobs/
Software Testing Help: http://www.softwaretestinghelp.com/


Copyright 2008: http://www.softwaretestinghelp.com

More Related Content

PDF
Basic linux commands
PPTX
SQL for ETL Testing
PPTX
Filepermissions in linux
PDF
Partitioning tables and indexing them
PPT
Db2
PPT
Install and configure linux
PDF
Enhanced Entity-Relationship (EER) Modeling
PDF
Intro to Linux Shell Scripting
Basic linux commands
SQL for ETL Testing
Filepermissions in linux
Partitioning tables and indexing them
Db2
Install and configure linux
Enhanced Entity-Relationship (EER) Modeling
Intro to Linux Shell Scripting

What's hot (20)

PDF
Shell scripting
PPTX
Dos%20commands(1)
PPTX
Structured Query Language (SQL)
PPTX
Linux commands
PPTX
Linux Basic commands and VI Editor
PPT
11. Storage and File Structure in DBMS
PPTX
Linux commands
PPT
Lossless decomposition
PPTX
PPT
Ch 7 Physical D B Design
PPTX
Modelo entidad relacion
PDF
SQL Monitoring in Oracle Database 12c
PPTX
Enhanced ER(database)
PPTX
Os unit 3 , process management
PPTX
Database constraints
PPTX
Booting process by Amar singh
PPTX
Know the UNIX Commands
PPTX
Introduction to File System
PPTX
4.1 Individual Y 4.3.pptx
PPTX
Introduction to Vim
Shell scripting
Dos%20commands(1)
Structured Query Language (SQL)
Linux commands
Linux Basic commands and VI Editor
11. Storage and File Structure in DBMS
Linux commands
Lossless decomposition
Ch 7 Physical D B Design
Modelo entidad relacion
SQL Monitoring in Oracle Database 12c
Enhanced ER(database)
Os unit 3 , process management
Database constraints
Booting process by Amar singh
Know the UNIX Commands
Introduction to File System
4.1 Individual Y 4.3.pptx
Introduction to Vim
Ad

Viewers also liked (20)

PPTX
PowerPoint Presentation (shared using http://VisualBee.com). (shared using Vi...
PPT
Spsl II unit
PDF
Scripting Recipes for Testers
PDF
Vsam interview questions and answers.
PPTX
Unix shell scripting basics
PDF
Manual software-testing-interview-questions-with-answers
DOCX
Quality center interview questions and answers
PPTX
3, regular expression
PDF
Cobol questions and answers
PDF
Project manager interview questions and answers
DOCX
Linux or unix interview questions
DOCX
Manual testing interview questions and answers
PDF
QA interview questions and answers
PDF
Ibm db2 interview questions and answers
KEY
Advanced Shell Scripting
PPTX
Practical unix utilities for text processing
PDF
"make" system
PDF
Siebel 8.1 Certifications Question Answers
PDF
Linux User Space Debugging & Profiling
PDF
Cts informatica interview question answers
PowerPoint Presentation (shared using http://VisualBee.com). (shared using Vi...
Spsl II unit
Scripting Recipes for Testers
Vsam interview questions and answers.
Unix shell scripting basics
Manual software-testing-interview-questions-with-answers
Quality center interview questions and answers
3, regular expression
Cobol questions and answers
Project manager interview questions and answers
Linux or unix interview questions
Manual testing interview questions and answers
QA interview questions and answers
Ibm db2 interview questions and answers
Advanced Shell Scripting
Practical unix utilities for text processing
"make" system
Siebel 8.1 Certifications Question Answers
Linux User Space Debugging & Profiling
Cts informatica interview question answers
Ad

Similar to Unix Basics For Testers (20)

PDF
UNIX Command Cheat Sheets
DOCX
Chapter 4 Linux Basic Commands
PDF
Basic unix commands_1
PPT
intro unix/linux 07
PPTX
Linux Command.pptx
DOC
Treebeard's Unix Cheat Sheet
PPTX
various shell commands in unix operating system.pptx
PPT
03 browsing the filesystem
PPT
Linux ppt
PDF
Command Line Tools
PDF
Basic linux commands
PDF
Linux_Commands.pdf
PDF
Course 102: Lecture 3: Basic Concepts And Commands
RTF
Unix lab manual
PDF
Lecture1 2 intro-unix
PDF
Os lab manual
PDF
LinuxCommands (1).pdf
DOCX
Directories description
UNIX Command Cheat Sheets
Chapter 4 Linux Basic Commands
Basic unix commands_1
intro unix/linux 07
Linux Command.pptx
Treebeard's Unix Cheat Sheet
various shell commands in unix operating system.pptx
03 browsing the filesystem
Linux ppt
Command Line Tools
Basic linux commands
Linux_Commands.pdf
Course 102: Lecture 3: Basic Concepts And Commands
Unix lab manual
Lecture1 2 intro-unix
Os lab manual
LinuxCommands (1).pdf
Directories description

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Insiders guide to clinical Medicine.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Business Ethics Teaching Materials for college
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
Insiders guide to clinical Medicine.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Business Ethics Teaching Materials for college
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
TR - Agricultural Crops Production NC III.pdf
Microbial disease of the cardiovascular and lymphatic systems
Renaissance Architecture: A Journey from Faith to Humanism
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study

Unix Basics For Testers

  • 1. UNIX BASICS - Beginners guide for Unix commands - by Meenakshi For more software testing articles visit: http://www.softwaretestinghelp.com Main features of unix : Multi user - More than one user can use the machine Multitasking- More than one program can be run at a time. Portability – 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 explicitly. Without options, ls displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are: -l long format, displaying Unix file type, permissions, number of hard links, owner, group, size, date, and filename -F appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix. -a lists all files in the given directory, including those whose names start with "." By default, these files are excluded from the list. -R recursively lists subdirectories. The command ls -R / would therefore list all files. cd
  • 2. Is a command line command used to change the current working directory in the Unix and DOS operating systems. It is also available for use in Unix shell scripts or DOS batch files. cd is frequently included built into certain shells such as the Bourne shell, tcsh, bash (where it calls the chdir() POSIX C function) and in DOS's COMMAND.COM. A directory is a logical section of a filesystem used to hold files. Directories 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 (/ in UNIX, in DOS) or move to any given directory. pwd command (print working directory) is used to print the name of current working directory from a computer's 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 Unix family of operating systems and other flavors as well. The DOS equivalent 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 POSIX C functions getcwd() and/or getwd(). Example: $ pwd /home/foobar mkdir command in the Unix operating system is used to make a new Directory. Normal usage is as straightforward as follows: mkdir name_of_directory Where name_of_directory is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. rm (short for remove) is a Unix command used to delete files from a filesystem. Common options that rm accepts include: -r, which processes subdirectories recursively -i, which asks for every deletion to be confirmed -f, which ignores non-existent files and overrides any confirmation prompts ("force")
  • 3. 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 /", "rm -rf *", and others) is frequently used in jokes and anecdotes about Unix disasters. The "rm -rf /" 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 Unix-system. It cannot be capitalized. Normal usage is straightforward where one types: rmdir name_of_directory Where name_of_directory corresponds with the name of the directory one wishes to delete. There are options to this command such as -p which removes parent directories if they are also empty. For example: rmdir –p foo/bar/baz Will first remove baz/, then bar/ and finally foo/ thus removing the entire directory tree specified in the command argument. Often 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 example: rmdir -Rf for/bar/baz cp is the command entered in a Unix 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 Copy a File to another File cp [ -f ] [ -h ] [ -i ] [ -p ][ -- ] SourceFile TargetFile To Copy a File to a Directory cp [ -f ] [ -h ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory To Copy a Directory to a Directory cp [ -f ] [ -h ] [ -i ] [ -p ] [ -- ] { -r | -R } SourceDirectory ... TargetDirectory -f (force) – specifies removal of the target file if it cannot be opened for write operations.
  • 4. The removal precedes any copying performed by the cp command. -h – 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 (interactive) – prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file. -p (preserve) – duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory: Examples 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 exist, the cp command creates it. If it does exist, 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 jones /home/nick/clients This copies the jones file to /home/nick/clients/jones. 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.jr This copies the smith file to the smith.jr file. Instead of creating the file with the current date and time stamp, the system gives the smith.jr file the same date and time as the smith file. The smith.jr file also inherits the smith file's access control protection. To copy all the files in a directory to a new directory, enter: cp /home/janet/clients/* /home/nick/customers 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 -R /home/nick/clients /home/nick/customers This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory. To copy a specific set of files to another directory, enter: cp jones lewis smith /home/nick/clients This copies the jones, lewis, and smith files in your current working directory to the
  • 5. /home/nick/clients directory. To use pattern-matching characters to copy files, enter: cp programs/*.c . This copies the files in the programs directory that end with .c to the current directory, signified by the single . (dot). You must type a space between the c and the final dot. find program is a search utility, mostly found on Unix-like platforms. It searches through a directory tree of a filesystem, locating files based on some user-specified criteria. By 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 extremely powerful program for applying actions to many files. It also supports regexp matching. Examples From current directory find . -name my* This searches in the current directory (represented by a period) and below it, for files and directories with names starting with my. The backslash before the star is needed to avoid the shell expansion. Without 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 quotes: find . -name "my*" Files only find . -name "my*" -type f This limits the results of the above search to only regular files, therefore excluding directories, special files, pipes, symbolic links, etc. my* is enclosed in quotes as otherwise the shell would replace it with the list of files in the current directory starting with my Commands The previous examples created listings of results because, by default, find executes the '- print' action. (Note that early versions of the find command had no default action at all; therefore the resulting list of files would be discarded, to the bewilderment of naïve users.) find . -name "my*" -type f -ls This prints an extended file information.
  • 6. Search all directories find / -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. Specify a directory find /home/brian -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. You should always specify the directory to the deepest level you can remember. Find any one of differently named files find . ( -name "*jsp" -or -name "*java" ) -type f -ls This prints extended information on any file whose name ends with either 'jsp' or 'java'. Note that the parentheses are required. 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, "(" and ")", to prevent them from being interpreted as special shell characters. touch is a program on Unix and Unix-like systems used to change a file's date- and time-stamp. It can also be used to create an empty file. The command-syntax is: touch [options] <file_name> If the file exists, its access and modification time-stamps are set to the system's 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 exist, an empty file of that name is created with its access and modification time-stamps set to the system's current date and time. If no file path is specified, the current directory is assumed. touch can be invoked with options to change its behaviour, which may vary from one Unix to another. One option makes it possible to set the file's 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 system's superuser. echo is a command in Unix (and by extension, its descendants, such as Linux) and MS-DOS that places a string on the terminal. It is typically used in shell scripts and batch programs to output status text to the screen or a file.
  • 7. $ echo This is a test. This is a test. $ echo "This is a test." > ./test.txt $ cat ./test.txt This is a test. cat program concatenates the contents of files, reading from a list of files and/or standard input in sequence 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. Example: cat filename who The Unix 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. Example output user19 pts/35 Apr 18 08:40 (localhost) user28 pts/27 Apr 18 09:50 (localhost) du (abbreviated from disk usage) is a Unix computer program to display the amount of disk space used under a particular directory or files on a file system. du 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. In Linux, it is a part of the GNU Coreutils package. The du utility first appeared in version 1 of AT&T UNIX. Example The -k flag will show the sizes in 1K blocks, rather than the default of 512 byte blocks. $du -k /seclog 4 /seclog/lost+found
  • 8. 132 /seclog/backup/aix7 136 /seclog/backup 44044 /seclog/temp 439264 /seclog We will discuss more advanced commands in the next article. For more software testing resources visit following pages: Software Testing articles: http://www.softwaretestinghelp.com/sitemap/ QA/Testing Job openings: http://www.softwaretestinghelp.com/jobs/ Software Testing Help: http://www.softwaretestinghelp.com/ Copyright 2008: http://www.softwaretestinghelp.com