0% found this document useful (0 votes)
28 views4 pages

OS Commands

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 4

PRACTICAL 1

1.mkdir Mike
== create new folder in linux

2.cat >abc.txt
== concatenate file and print on the standard output

3.sort abc.txt
== sort lines of text

4.ls -l
== lists the file inside the folder

5.sudo useradd Mayank


== create new user

6.sudo chown Mayank abc.txt


== change owner of file

7.sudo groupadd Mygroup


== create new groupe account of name Mygroup

8.sudo chgrp mahesh abc.txt

9.sudo chmod u=rwx,g=rx,o=r abc.txt

10.ps

11.ps aux
== a:prints running processes from all user
u:shows user columns
x:prints processes those have not been executed

12.ps aux --sort -pid


== prints running processes in 'process id' wiser sorting

13.ps aux --sort pid

14.grep -i "unix" new.txt


== highlights the entered word

15.grep -c "unix" new.txt


== counts the number of lines

16.grep -o "unix" new.txt


== prints word entered

17.cd FAMT
== to change the current working directory in various operating systems

18.cd ..
== this command is used to move to the parent directory of current directory

PRACTICAL 2

Q1.A Display OS Version,Release no, kernel version


== cat /etc/ os-release
uname -r
grep '^VERSION' /etc/os-release
egrep '^(VERSION|NAME)=' /etc/os-release

Q1.B Display top 10 processes in ascending order


== ps aux --sort -pid|head -11

Q1.C display processes with highest memory usage


== ps aux |head -1; ps aux |sort -rnk 4|head -5

Q1.D Display current log in user and log name


== w

PRACTICAL 3

1. ls -a :list all files including hidden file starting with '.'.

2. ls -d :list directories - with ' */'.

3. ls -l :list with long format - show permissions.

4. ls -F :Append indicator (one of */=>@|) to entries.

5. ls -lh :This command will show you the file sizes in human readable format.

6. ls -r :list in reverse order.

7. ls -i :list file's inode(index) number.

8. ls -ltr :View Reverse Output Order by Date.

9. ls -t :sort by time & date.

10.ls -n :It is used to print group ID and owner ID instead of their names.

11.ls -m :A list of entries separated by commas should fill the width.

12.ls -g :This allows you to exclude the owner and group information columns.

13.ls -q :Force printing of non-graphic characters in file names as the


character `?';.

14.ls -Q :Place double quotations around the entry names

PRACTICAL 4

Q1. Create a child process in linux using the fork system call from child process
obtain process id of both child
and parents by using get pid and get ppid system call.
==

#include<stdio.h>
#include<unistd.h>
int main()
{
int pid;
pid = fork();
if(pid==0)
{
printf("\n After Fork");
printf("\n The new child process is created by fork system call
%d \n",getpid());
}
else
{
printf("\n Before fork");
printf("\n The parent process id is: %d",getppid());
printf("\n parent process executed successfully");
}
return 0;

Q2. Explore wait and wait pid before termination of process


==

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>

int main()
{
pid_t cpid;
if(fork==0)
{
exit(0);
}
else
{
cpid = wait(NULL);
}
printf("\n parent pid: %d \n ",getpid());
printf("\n child pid: %d", cpid);
return 0;
}

You might also like