Aabid Unix
Aabid Unix
ON
UNIX Lab
BCA-506P
Affiliated To
UNIVERSITY OF LUCKNOW
Course
Bachelors in Computer Application
2024-2025
(ii) mkdir
The mkdir command in UNIX is a command-line utility that allows users to create new directories.
mkdir stands for “make directory”.
Syntax: mkdir[options][directories]
(iii) cd
cd stands for “change directory”. The cd command is used to change the current working directory.
Using ‘cd’ followed by a directory name or path changes your location within the file system.
Syntax: cd[directory]
1|Page
STUDY HALL COLLEGE UNIX Lab 2024
(ii) echo
Displays lines of text or strings that are passed as arguments on the command line. It is commonly
used in shell scripts and Bash files to display output status text.
Syntax: echo[options][string]
(iii) cat
Reads files sequentially, writing them to standard output. The name comes from its function to
concatenate files.
Syntax: cat file_name
2|Page
STUDY HALL COLLEGE UNIX Lab 2024
Options of rm command:-
a) -r, -R, --recursive: Recursively remove directories and their
contents.rm -r directory_name
(ii) mv
`mv` stands for “move”. But in this article, we will be talking about the “mv command in
Linux”.
This command is used to rename files or move files.
Syntax: mv file_name Directory
MV is used to move file one place to another place.
3|Page
STUDY HALL COLLEGE UNIX Lab 2024
(iii) wc
The wc command in UNIX is a command line utility or printing newline, word
and byte counts for files. It can return the number of lines in a file, the number
of characters in a file and the number of words in a file.
Syntax: wc file_name
Options of wc command : -
4|Page
STUDY HALL COLLEGE UNIX Lab 2024
5|Page
STUDY HALL COLLEGE UNIX Lab 2024
(iv) Cp
The cp command copies the contents of the source file or directory to the target
file or directory. If the target file exists, the copy will overwrite the original
contents.
Syntax: cp file_name Destination_name
6|Page
STUDY HALL COLLEGE UNIX Lab 2024
Options:
b) a: List all entries including hidden files (those starting with a dot).
ls –a
7|Page
STUDY HALL COLLEGE UNIX Lab 2024
ls –lt
(ii) Chmod
The chmod command is used to change the access mode of a file. The name is an abbreviation
of change mode. Which states that every file and directory has a set of permissions that control the
permissions like who can read, write or execute the file. In this the permissions have three
categories: read, write, and execute simultaneously represented by `r`, `w` and `x`. These letters
combine together to form a specific permission for a group of users.
The `chmod` command is used to modify this permission so that it can grant or restrict access to
directories and files.
8|Page
STUDY HALL COLLEGE UNIX Lab 2024
Each file is associated with a particular owner & have permission access for different users.
The userclasses may be:
Owner
Group member
Other ( everybody else )
1. Symbolic Mode:
The symbolic method in chmod allows you to change file permissions using a symbolic
representation,where you use letters and symbols to specify the changes you want to make to the
existing permissions.
9|Page
STUDY HALL COLLEGE UNIX Lab 2024
2. Absolute Mode:
The absolute mode in the chmod command allows you to set permissions explicitly using a
three-digitoctal (base-8) representation. Each digit corresponds to the permission settings for the
user, group, andothers, respectively. The digits are calculated by adding the values for read (4),
write (2), and execute (1).
The basic syntax for absolute mode is:
chmod xxx file
Here, each 'x' represents a digit (0-7) corresponding to the permission settings. The three digits
togetherrepresent the permissions for the user, group, and others.
The first digit: User/Owner permissions
The second digit: Group permissions
The third digit: Others
permissionsThe digits of the
permissions are:-
4: Read permission
2: Write permission
1: Execute permission
10 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
You add these values to get the desired combination. For example, read and execute would be 4 + 1 = 5.
Setting Read, Write, and Execute for User, Read and Execute for Group, and Read-only for Others:
Read and Write for User, Read-only for Group and Others:
11 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
12 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
14 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
14 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
7. Execute the following filters using regular expression with all possible options:
(i) grep
The grep filter searches a file for a particular pattern of characters, and displays all lines that contain
patterns. The pattern that is searched in the file is referred to as the regular expression. grep stands
for global search for regular expression and print out.
Syntax: grep [options] “string” file_name
Options:
-i (ignore case distinctions in both the pattern and the input files)
-r, -R (Recursively search subdirectories)
-n (Display line numbers along with the lines containing the pattern)
-c (Display only the count of lines that match the pattern)
-l (Displays only the names of file containing the pattern)
c) -n, --line-number: Display line numbers along with the lines containing the
pattern.wc -cfilename.
grep -n "pattern" file.txt
d) -c, --count: Display only the count of lines that match the pattern.
16 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
(ii) sed
sed is a text stream editor used to edit files quickly and efficiently. The tool searches through,
replaces, adds and deletes lines in a text file without opening the file in text editor. Using it complex
pattern matching can be performed.
Syntax: sed [options] ‘address action’ [file_name]
• SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution).
• SED command in unix supports regular expression which allows it perform complex pattern
matching.
17 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
18 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
interpreter. A shell script usually has the comments the describe the steps. The different operations
performed by shell scripts are program execution, file manipulation and text printing
15 | P a g e
STUDY HALL COLLEGE UNIX Lab 2024
19 | P a g e