Unix Notes 2
Unix Notes 2
The pwd command displays the full pathname of the current directory.
Syntax
pwd
Example:
$pwd
/home/pc10
$
The 'cat' command is used to display text files. It can also be used for copying, combining and
creating new text files.
cat filename
cat >>filename
Options
Option Description
1|Page
3] Deleting Files
The 'rm' command removes files from the system without confirmation.
Example:
1] rm sample.f - deletes sample.f
2] rm chap?.txt - deletes all files with chap as the first four characters of their name including with
any one more character and having extension.txt.
3] rm -i * - deletes all files in current directory but asks first for each file
4] rm -r /olddir - recursively removes all files in the directory olddir, including the directory itself.
Options
Option Description
It is used to remove non-empty directory, together with all the files and
-r(recursive)
subdirectories contains.
mv filename new_file_location
Suppose we want to move the file "sample2" to location /home/zsp/Document. Executing the
command
mv sample2 /home/zsp/Document
mv filename newfilename
mv sample.f sample2.f - moves sample.f to sample2.f
mv dir1 newdir/dir2 - moves contents of directory
dir1 to newdir/dir2
2|Page
mv -i file.1 file.new - prompts if file.new will be
overwritten
mv *.txt chapt1 - moves all files with .txt
suffix to directory chapt1
Options
Option Description
cp - copies files. Will overwrite unless otherwise specified. Must also have write permission in the
destination directory.
Options
Option Description
3|Page
Option Description
5] Creating Directories
Directories can be created on a Linux operating system using the following command
mkdir directoryname
This command will create a subdirectory in your present working directory, which is usually your
"Home Directory".
For example,
mkdir mydirectory
The mkdir command creates a single directories or multiple directories.
Syntax
The syntax for the mkdir command is:
Options
Option Description
Example
6] Removing Directories
rmdir directoryname
Example
rmdir zsp
Options
Option Description
This option remove directories and any intervening parent directories that become empty
-p
as a result useful for removing subdirectory trees.
Man stands for manual which is a reference book of a Linux operating system. It is similar to HELP file
found in popular software.
To get help on any command that you do not understand, you can type
man
The terminal would open the manual page for that command
History command shows all the commands that you have used in the past for the current terminal
session. This can help you refer to the old commands you have entered and re-used them in your
operations again.
This command helps in formatting the file for printing on the terminal. There are many options
available with this command which help in making desired format changes on file. The most used
'pr' options are listed below.
Option Function
Once you are done with the formatting, and it is time for you to get a hard copy of the file, you need
to use the following command:
lp Filename
or
lpr Filename
In case you want to print multiple copies of the file, you can use the number modifier.
'ls -al' gives detailed information of the files. The command provides information in a columnar
format. The columns contain the following information:
6|Page
2nd Column # of Hard Links to the File
ls -a
Hidden items in UNIX/Linux begin with .(period) symbol at the start, of the file or directory.
Any Directory/file starting with a '.' will not be seen unless you request for it. To view hidden files,
use the command.
The ls command lists all files in the directory that match the name. If name is left blank, it will list all
of the files in the directory.
Syntax
The syntax for the ls command is:
ls [options] [names]
The Unix command to return the files that ends with single digit and has .txt extension
ls -l *[0-9].txt
Options
7|Page
Option Description
-F Flags filenames.
-g Displays the long format listing, but exclude the owner name.
-n Displays the long format listing, with GID and UID numbers.
8|Page
Option Description
13] cd
The change directory (cd) command is used to move one directory to another directory.
Syntax
Examples of CD commands
Syntax
9|Page
The syntax for the chmod command is:
Example
Options
Option Description
10 | P a g e
Option Description
15] passwd
Syntax
Option Description
16] more
The more command displays the file called name in the screen. The RETURN key displays the next
line of the file. The spacebar displays the next screen of the file.
Syntax
The syntax for the more command is:
Options
Option Description
11 | P a g e
Option Description
+/pattern Displays the file starting at two lines before the pattern.
Example
more -d tech
filter utilitie
head
syn
Options
12 | P a g e
Option Description
-q (quit ) It never print name of files as header , more than one file is given.
Tail
Option Description
+n( n is number) It display lines from nth to last line of input file.
13 | P a g e