Wednesday, 11 June 2014

Some handy UNIX Commands for Software Testing

1. Reads 1 or more files & print them to standard output:

cat [files]

Examples:
cat file1
cat file1 file2>all
cat file1>>file2

2. Command that changes directory:

cd [dir]

Examples:
cd tech
cd /tech

3. Command to change access mode of 1 or multiple files:

chmod [options] mode files

Examples:
chmod 755 file1
chmod u=rwx,g=rx,o=rx file1                            -- read, write & execute access                       
chmod -w file1                                                     -- removes write access

4. How to ftp:

ftp [options] [hostname]

Examples:
ftp -v hostname1                                                  -- display all server responses
Username: rnath
Password: passme1
ftp> pwd                                                                -- find path of the current remote directory
ftp> cd /pub/HPSC                                               -- Remote machine change directory
ftp> ls                                                                     -- List files in remote machine
ftp> lcd /pub/HPSC                                              -- Local machine change directory
ftp> get file1 file2                                                -- copy remote file1 into local as file2
ftp> mget*                                                            -- Copies multiple files (everything from the current directory)
ftp> put file3 file 4                                               -- copy local file into remote
ftp> mput*                                                            -- Copies multiple files (everything from the current directory)
ftp> bye                                                                 -- Exit FTP
ftp> quit                                                                 -- Same as buy. Exit FTP

5. Search File Contents based on patterns

grep [options] pattern [files]

Examples:
grep -i abc file1                                                    -- Ignore case sensitivity
grep -c abc file1                                                   -- Display number of matched lines
grep -W abc file1                                                 -- Match the whole word

6. Finding files

find search_path -name filename

Examples:
find / -name file1.txt                           -- find file1.txt anywhere in the system
find . -name file1.txt                            -- find file1.txt anywhere in the current directory or sub directories

7. Killing a process

kill [options] ID

Examples:
kill -9 12345                                                          -- kill signal number 9 of process id 12345

8. List all the files in a directory that matches the name. If name of directory is not mentioned, list out all files in current directory.

ls [options] [dir_name]

Examples:
ls -a                                                                         -- display all files
ls -c                                                                         -- display files with timestamp
ls -l                                                                          -- display log format listing
ls -r                                                                         -- displays files in reverse order
ls -t                                                                          -- displays newest files first (based on timestamp)

9. Create directories

mkdir [options] directories

Examples:
mkdir -m 755 dir1                                                -- creates dir1 with access 755
mkdir -p tech/abc/dir1                                       -- if parent directories do not exist, this command creates them

10. For moving and renaming files.

mv [options] sources target

Examples:
mv -f abc/xyz                                                        -- forces the change
mv -i abc/xyz                                                         -- ask for permission before changing

11. Changing password

passwd [user]

Examples:
passwd rnath       

12. Displaying the active processes

ps [options]

Examples:
ps -e                                                                       -- display all processes
ps -f                                                                        -- display a full listing
ps -l                                                                         -- display a long listing
ps -ulist                                                                  -- display data for the list of usernames
ps -plist                                                                  -- display data for the list of process IDs
ps -ef

13. Finding full path of the current directory

pwd

14. Displaying the last few lines of a file

tail [options] [files]

Examples:
tail -f file1                                                              -- displays last 10 lines of the file
tail -r file1                                                              -- displays the lines in reverse order
tail -20 file1                                                           -- displays last 20 lines of the file

  
15. Displaying first few lines of a file

head [options] [files]

Examples:
head -f file1                                                          -- displays first 10 lines of the file
head -r file1                                                          -- displays the lines in reverse order
head -20 file1                                                       -- displays first 20 lines of the file

16. Progressively dump a file to the screen:

more filename

Examples:
more file1             -- Progressively dump a file to the screen: ENTER = one line down, SPACEBAR = page, down  q=quit

17. Launch the text editor:

vi [options] [files]

Examples:
vi + file1                                                                 -- position the cursor at the last line of the file in vi
vi +5 file1                                                              -- position the cursor at the 5th line of the file in vi
vi -R file1                                                               -- Read Only mode

18. To enter vi command mode:

[esc]

19. Cursor Movement in vi

h                     -- move left (backspace)
j                     -- move down
k                     -- move up
l                     -- move right (spacebar)


r                      -- replace character under cursor with next character typed
R                          -- keep replacing character until [esc] is hit
i                      -- insert before cursor
a                      -- append after cursor
A                         -- append at end of line
O                     -- open line above cursor and enter append mode

21. Deleting in vi

x                                                                             -- delete character under cursor
dd                                                                           -- delete line under cursor
dw                                                                          -- delete word under cursor
db                                                                          -- delete word before cursor

22. Copying Code in vi

yy      -- (yank)'copies' line which may then be put by the p(put) command. Precede with a count for multiple lines.

brings back previous deletion or yank of lines, words, or characters
P                     -- bring back before cursor
p                      -- bring back after cursor

24. Find Commands in vi

?                     -- finds a word going backwards
/                     -- finds a word going forwards

25. Repeat last command in vi

.                    -- repeat last command

26. Getting out of vi editor:

:q!                                                                           -- quit vi without saving
:w                                                                            -- save changes
:wq                                                                         -- save & quit

27. Display the current user name

whoami

28. Search a person’s details, organization, login etc.

whois name



No comments:

Post a Comment