Please note that for LAB work book titled “Unix Concepts and Applications, 4th
Edition by Sumitabha Das” will be followed. And the below mentioned
assignments have been drafted from the different chapters of the above said book.
These commands can be referred from Chapters 1-6 and Chapter 11 of
the said book.
LAB Session 1 and 2
LINUX / UNIX based commands
Operating Systems
(UCS – 303)
1. Introduction to operating system
2 Introduction to Linux/Unix.
3. Architecture of Linux.
4. System Call execution.
5. Command structure.
1. Concept of Shell.
2. Types of Shell.
3. ls command and its options.
ls Command: ls [flags] [directory]
a. List of files in current directory: $ ls
b. Files with specific naming convention: $ ls filename*
c. Specific files with attributes: $ ls –l filename*
d. Save viewing output: $ ls > list
e. Assign values to variables: $ a=6
f. Evaluate the value: $ echo $a
4. > option for directing the output of a command.
To copy content from older to new file, or create a file.
5. Introduction and options for cat command
The 'cat' command can be used to display the content of a file.
a. To view file: cat fileName
b. To create a file: cat > fileName (You can exit with ctrl+D)
c. To copy content from older to new file: cat oldfile > newfile
d. To concatenate contents of multiple files into one: cat file1 file2 >
newfile
e. To display line numbers: cat -n/cat -b filename
f. To edit existing file: vi fileName
[This file is open in normal mode, to switch it to insert mode press 'ESC' key
followed by 'i' key. After that you can edit at whatever place in file you want.
To save the file and exit from the editor, press the 'ESC' key, followed by
:wq! Keys.]
6. Feeding output of one command to another by pipeline. Eg. $ ls > list
7. Ways for signing off from Linux: ctrl+d, logout, exit
8. Locating commands: $ locate filename
a. Search a file with specific name: $ locate [Link]
b. Limit Search Queries to a Specific Number: $ locate "*.html" -n 20
c. Display The Number of Matching Entries: $ locate -c [.txt]*
d. Ignore Case Sensitive Locate Outputs: $ locate -i *[Link]*
9. PATH and SHELL variable: Some commonly used environment variable:
$USER: Gives current user's name.
$PATH: Gives search path for commands.
$PWD: Gives the path of present working directory.
$HOME: Gives path of home directory.
$HOSTNAME: Gives name of the host.
$LANG: Gives the default system language.
$EDITOR: Gives default file editor.
$UID: Gives user ID of current user.
$SHELL: Gives location of current user's shell program.
10. Combining the commands.
11. echo and echo –e: echo [option] [string]
a. Displaying a Text: $ echo “string”
b. –e: -e here enables the interpretation of backslash escapes
Eg. \b: Removes all the spaces in between the text: echo -e "Welcome \bto
\bClass"
12. Cal and Date command with its different options.
Cal Command: cal [month] [year]
a. Current Month: $ cal
b. Complete Year: $ cal 2010
c. June 2010: $ cal 6 2010
Date Command: date [option]... [+format]
a. Today Info: $ date
b. Specific Date Info: $ date -d "2000-11-22 [Link]"
c. date --date="09/10/1960"
d. Format the Date: date +"Year: %Y, Month: %m, Day: %d"
e. date "+DATE: %D%nTIME: %T"
f. date +"Week number: %V Year: %y"
13. man and help command
a. man Command: man command in Linux is used to display the user
manual of any command that we can run on the terminal.
Syntax: $man [OPTION]... [COMMAND NAME]...
Eg. $ man printf, $ man 2 intro
b. help Command: help command displays information about shell built-
in commands.
Syntax: $help [-dms] [pattern ...]
Eg. $help help, $help fc
14. Using escape sequence: an escape sequence is two or more characters that
often begin with an escape character that tells the computer to perform a function
or command. Mostly used with echo.
Eg.
\n means newline
\r means return
\t means tab
\v means vertical tab
\b means backspace
\a means "alert" (beep or flash)
15. Printf in Linux: printf command in Linux is used to display the given string,
number or any other format specifier on the terminal window. It works the same
way as “printf” works in programming languages like C.
Syntax: $printf [-v var] format [arguments]
Eg. $printf "%s\n" "Hello, World!"
printf "%s\n" "Hello, World! \n" "From Patiala\n"
printf "%b\n" "Hello, World! \n" " Patiala \n"
1. Create Directory: mkdir mydir_name
2. Change Directory: cd mydir_name
3. Create Multiple Directories: mkdir dir1 dir2 dir3
4. To create a directory with a directory inside of it: mkdir -p
dir4/newdir
No. Command Name Explanation
1. info [command name] An alternative of man to obtaining comprehensive
user documentation for a given command.
2. mv oldname newname The mv command is used to move or rename files. (If
the last argument happens to be an existing directory,
mv will move the file to that directory instead of
renaming it)
3. mv first_file second_file third_file You can provide mv more than two arguments for
~/dir1 moving multiple files to a directory.
4. less myfile To just view the contents of a long file (or any text
file) you can use the less program.
5. who Displays all the users who have logged into the
system currently.
6. touch example This command creates a file(not directory). See the
difference among cat, vi, touch.
7. cp /home/sample/[Link] This ‘cp‘ command stands for ‘copy’ and it simply
/home/sample/new/ copy/paste the file wherever you want to. In the this
command, we are copying a file ‘[Link]’ from the
directory sample to a new directory new. See the
difference between cp and mv.
8. rm [Link] This command for remove the file.
9. chmod +w [Link] The ‘chmod’ command stands for change mode
chmod +r [Link] command. As there are many modes in Unix that can
chmod +x [Link] be used to manipulate files in the Unix environment.
Basically there are 3 modes that we can use with the
‘chmod’ command:
1. +w (stands for write)
2. +r (stands for read)
3. +x (generally it is used to make a file
executable)
10. sort filename Sorts the contents of the file according to the ASCII
rules.
11. grep picture newsfile The ‘grep’ command searches the specified input fully
(globally) for a match with the supplied pattern and
displays it. In this command, this would search for the
word ‘picture’ in the file newsfile and if found, the lines
containing it would be displayed on the screen.
12. lpr [Link] The ‘lpr’ command send a file to the printer for
printing.
13. passwd The ‘passwd’ command simply changes the password
of the user.
14. clear The ‘clear’ command is used to clean up the terminal
so that you can type with more accuracy.
15. head –N filename Used to print the first N lines of a file. It accepts N as
input and the default value of N is 10.
16. tail –N filename Used to print the last N-1 lines of a file. It accepts N as
input and the default value of N is 10.
17. wc filename Used to count the number of characters, words in a
file.
18. cut –c 2-4 filename Used to cut a specified part of a file.
19. du /home/sample/test du command, short for disk usage, is used to estimate
du -h /home/sample/test file space usage.
20. umask The bits which are set in the umask value, refer to the
permissions, which are not assigned by default, as
these values are subtracted from the maximum
permission for files/directories.
Here, the first digit, 0 is called the sticky bit, it is a
special security feature.
The next three digits represent the octal values of
the umask for a file or directory.
The three rwx permissions (Read-Write-Execute)
values are converted into three-bit binary values and
represented by a single octal value.
21. find ./OS1 -name [Link] It can be used to find files and directories and perform
subsequent operations on them. It supports searching
by file, folder, name, creation date, modification date,
owner and permissions. This command will search for
[Link] in OS1 directory.
22. find ./OS1 -name *.txt It will give all files which have ‘.txt’ at the end.
23. find ./GFG -empty This command find all empty folders and files in the
entered directory or sub-directories.