0% found this document useful (0 votes)
80 views5 pages

M Hassan Bin Adeel

The document contains a student's lab report on tasks completed using Linux terminal commands. It includes [1] Creating and copying files using cat and cp [2] Terminating Firefox using pgrep and kill [3] Creating directories, moving files between them using mkdir and mv [4] Compressing directories into a zip file using zip [5] Unzipping the file [6] Testing a script that deletes text in brackets from files [7] Explaining cat, touch and echo commands with examples [8] Converting C code to C++ and compiling/running it.

Uploaded by

Hassan Adeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views5 pages

M Hassan Bin Adeel

The document contains a student's lab report on tasks completed using Linux terminal commands. It includes [1] Creating and copying files using cat and cp [2] Terminating Firefox using pgrep and kill [3] Creating directories, moving files between them using mkdir and mv [4] Compressing directories into a zip file using zip [5] Unzipping the file [6] Testing a script that deletes text in brackets from files [7] Explaining cat, touch and echo commands with examples [8] Converting C code to C++ and compiling/running it.

Uploaded by

Hassan Adeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Muhammad Hassan Bin Adeel

CS-11-B
386269

LAB-01

· Manjaro operating system already installed


· Manjaro is an arch based distro of linux
· All commands that work in ubuntu work in manjaro
· Screenshot is of OS screen of my pc
1. Create a file with the name file1.txt using the terminal; write some text in this file by
opening the file in any Linux editor. Create another file name file2.txt, copy the text
from file1 to file2, using the terminal. (Write a set of commands which you will use
to perform these steps).

· ‘cat’ command used to create and write in a file


· ‘cp’ command used to copy one file to other

2. Open Firefox browser and terminate the firefox process using the terminal by
finding its pid and killing the process.

· ‘pgrep’ command is used to find specific pid associated with firefox


· ‘kill’ command is used and signed number (indicating type of kill signal) and pid is
passed to pgrep command
3. Create directory dir1, place a file named file1 in it. Create another directory dir2,
place a file named file2 in it. Move file2 to dir1.

· ‘mkdir’ is used to make a directory


· ‘mv’ is used to move file to specified directory by giving path

4. Compress dir1 and dir2 into a zip file using the terminal. Name the zipped file
zipped_directories.

· ‘zip’ or ‘tar’ command is used to compress the file

5. Unzip the compressed file “zipped_directories” into /home/Labs/Documents


· ‘unzip’ command is used

6. Find out what the following script file does:

*************** file commands.sh******************


#!/bin/bash
echo "hello world"
for f in *.txt; do
    f2=${f%%.*} 
    echo filename $f2
    cat $f | sed 's/(.*)//g' > ${f2}_modified.txt
done
**********end of file commands.sh*************

Hint: use text files that contain strings like "aad(bbb)c c" for testing

Make this script file executable using the command chmod u=rwx commands.sh and run
using ./command.sh

When we execute the file, it deletes the string in brackets

7. What do the cat, touch and echo commands do? Show how they work using an
example.
The cat command is a utility command in Linux. One of its most common usages is to print the content of
a file onto the standard output stream. Other than that, the cat command also allows us to write some
texts into a file.

“ cat file1.txt”

The touch command is a standard command used in UNIX/Linux operating system which is
used to create, change and modify timestamps of a file. It creates the file without any content

“ touch file1.txt file2.txt ”

echo command in linux is used to display line of text/string that are passed as an argument .
This is a built in command that is mostly used in shell scripts and batch files to output status
text to the screen or a file. 

“ echo –e “hassan\bis\bhere” ”

8. Transform the above C code “hello.c” into C++, compile it, and then execute the
program. hint: use appropriate compiler for compiling C++ code.

#include <iostream>
using namespace std;
/* Hello World program */
#include<stdio.h>
int main() {
cout<<"Hello World"<<endl;
return 0;
}

You might also like