KEMBAR78
Linux Basics for MCA Students | PDF | Computer File | Filename
0% found this document useful (0 votes)
54 views81 pages

Linux Basics for MCA Students

The document discusses 10 Linux commands: mkdir, ls, cd, rmdir, pwd, cat, cp, rm, mv, and head. It provides the syntax, examples of use, and common options for each command. The commands covered allow users to create and remove directories and files, navigate directories, view and concatenate file contents, copy and move files or directories, and view the beginning of files.

Uploaded by

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

Linux Basics for MCA Students

The document discusses 10 Linux commands: mkdir, ls, cd, rmdir, pwd, cat, cp, rm, mv, and head. It provides the syntax, examples of use, and common options for each command. The commands covered allow users to create and remove directories and files, navigate directories, view and concatenate file contents, copy and move files or directories, and view the beginning of files.

Uploaded by

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

LINUX Assignment

1) MKDIR COMMAND :- The mkdir command is used to create a new


directory under any directory.

Synatax:

$ mkdir [option] <directories name…> [enter]

option of mkdir

➢ -p :- With the help of mkdir -p command you can create sub-directories


of a directory. It will create parent directory first, if it doesn't exist. But if
it already exists, then it will not print an error message and will move
further to create sub-directories.

➢ -v :- mkdir -v' command will print a message with every new file
created.

Example

$ mkdir MCA

$ mkdir -v m

$ mkdir -p A/B/C

$ mkdir -p -v x/y/z

OUTPUT-

1|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

2) ls command:- The ls is the list command in Linux. It will show the full
list or content of your directory. Just type ls and press the enter key. The
whole content will be shown

Synatax:

$ ls [option] <directories/file name..> [enter]

option of ls command

➢ ls-a :- The (ls -a) command will enlist the whole list of the current
directory including the hidden files.
➢ ls-l :- It will show the list in a long list format.
➢ ls -R will list all the files in the sub-directories as well.

Example :

$ ls

$ ls -a

$ ls -l

$ ls -al

$ ls -R x

$ ls -l mca

2|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

OUTPUT-

3|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

3) Cd :- Linux cd command is used to change the current working


directory.

The cd stands for 'change directory.' It is one of the most frequently


used commands in the Linux terminal.

Syntax :

$ Cd [option] <directories/file name..> [enter]

Options-

• Cd .. (with to dots) to move one directory up.


• Cd to go straight to the home folder.
• Cd – (with a hypen) to move to your previous directory.
• cd / (with a forward slash) to move your root directory.

Example

$ cd x

$ cd x/y

$ cd ..

$ cd –

Output-

cl

4|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

4) rmdir:-This command is used to delete a directory. But will not be able


to delete a directory including a sub-directory. It means, a directory has to
be empty to be deleted.

Syntax:

$ rmdir [option] <directories name> [enter]

Option of rmdir command

-P :- This command will delete a directory including its sub-directories


all at once. In below picture, all sub-directories have been deleted with
'rmdir -p' command.

-v :- rmdir -v' command will print a message with every directories


deleted

Example-
$ rmdir z
$ rmdir -v y
$ rmdir -p -v X/Y/Z

Output –

5|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

6|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

5) pwd : The pwd command is used to display the location of the current
working directory.

syntax:-

$ pwd [enter]

example:-

$ pwd

Output-

7|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

6) cat command:- cat command is very frequently used in linux . It read


data from the file and gives their content as output. It help as to create ,
view concatenate files

syntax

$ cat [option] <file_ name> [enter]

Option:

• cat > filename create a new file.


• cat filename1 filename2 > filename3 joins two file(1 and 2) and
stores the output of them in a new file (3).
• cat filename displays the content of file.

Example

$ cat > file1.txt

$ cat > file1.txt file2.txt > file3.txt

$ cat file1.txt

$ cat file1.txt file2.txt file3.txt

Output-

8|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

Other option-

• With -n option see the line number of a file in the output terminal.

9|Page NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• With -b option see the line numbers of a file in the output


terminal(ignore any gap between paragraphs)

• See with -e option that ‘$’ is shows at the end of line and also in
space showing ‘$’ if there is any gap between paragraphs.

10 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• With -T option we could see TAB space is filled up with ‘I’


character.

• Append in existing file with ‘>>’ (double greater than) symbol.

11 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

7) Cp command :- this command used to copy file or group of files or


directory. Create an exact of a file on a disk with different file name.

Syntax:-
$ Cp [option] source destination [enter]
$ Cp [option] source directory [enter]
$ Cp [option] source-1 source-2 source-n directory [enter]

Example:- $cp file1.txt file2.txt

Option-
• -i(Intractive): i stand for intractive copying . with this option
system first warns the user before overwriting the destination file.

• -b (backup): with this option cp command creates the backup of


the destination file in the same folder with the different name and
in different format.

12 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• -R :- this option used to copy directory of on directory to another


directory.

13 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

8) rm command :- rm command is used to delete files.


Syntax :-
$ rm [option] [dir./file name] [enter]

Example:-
$ rm test.txt
$ rm -i test1.txt
$ rm -v test2.txt
$ rm -r MCA
$ rm -v -i -r A

Output-

Option of rm command
• -i :- before asked deleting each files. Are you sure deleting
this file.
• -I : - instead, which will only ask once and only if you are
trying to delete three or more files.
• -r :- will recursively delete a directory and all its contents (
normally rm will not delete directories , while rmdir will only
delete empty directories).
• -f:- will forcibly delete files without asking.

14 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

9) mv command :- the mv command is used to rename and move and


files and directories from one location to another.
Syntax:-
$ mv [option] source destination [enter]
$ mv [option] source-1 source-2 source-n directory [enter]
Example :- $ mv file1.txt m
$ mv file2.txt file2.txt~ os

Option of mv command
• -I :- if the destination fie exist it will be overwritten. To
prompt for confirmation, us the –I option.
• -f :- the –f option overrides this minor protection and
overwrites the destination file forcefully and deletes the
source file.
• -n :- with –n option, mv prevent an existing file from being
overwritten in the following example the effect is for nothing
to happen as a file would be overwritten.
• -version :- this option is used to display the version of mv
which is currently running on you system.

Example-

15 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

16 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

10) Head command :- the head command, as the name implies , print the
top n number of data of the given input. By default it prints the first 10
lines of the specified files.
Syntax: -
$ head [option] [file name] [enter]
Example:-
$ head file1.txt

Option of head command :-


• - n: - -n option show the number of line, if given number of lines.
Output :-

17 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• -c :- the -c option allows to print a specific number of bytes.

18 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

11) tail command : -the tail command is a command – line utility for
outputting the last part of files given to it via standard input . it writes
result to standard output. By default tail return the last ten lines of each
file the it is given. It may also be used to follow a file in real time and
watch as new lines written to it.

Syntax :-
$ tail [option] [file name] [enter]
Example:-
$ tail file1.txt

19 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

Option of tail command


• -n :- this option used to show the output of file given number
of lines.

• -c :- to limit the number of bytes shown with tail pass the –c


option . instead of limitin by number of lines this will limit by
the number of bytes passed to the –c option . in the following
example the output is limited to 16 bytes.

• -q :- To suppress the header line pass the -q option. This can be


useful to combine files.

20 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

21 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

12) Ps command :- ps command is used to list the currently running


processes and their Pids along with some other information depends on
different option.

Example:

22 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

13) Date command :- the date command display or set the sytem date. It
is most commonly used to print the date and time in different formats and
calculate future and past dates
Syntax:- Date <format
Example-

Option of date command :-


• Format option:- the output of the date command can be formatted with
a sequence of format control characters preceded by a + sign. The
format control start with the % symbol and are substituted by their
values.

• %a - Locale’s abbreviated short weekday name

• %A- locale’s abbreviated full weekday.

• %b- locale’s abbreviated short month name.

• %B- locale’s abbreviated full month name.

23 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• %d – day of month

• %H – hours

• %I- hour

• %j – day of year

• % m-month

• %M- minuts

• %S- second

• %y – full year

Output :-

24 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• -d :- the –d option allows you to operate on a specific date. You can


specify the date as a human – readable date string .

25 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

14) Calendar command:- to display a calendar.

Syntax :-

Cal <year> <month> <day>

Example-

Option of cal command :-

• -m :- display a Monday as the first day of the week

• -j :- display Julian dates(day one based, numbered from january1)

26 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• -y :- display a calendar for the current year

27 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

15) Wc command :-the wc command allows to count the number of


lines, words, characters, and bytes of each given file or standard input and
print the result.

Syntax:

Wc <option> <enter>

• -l : lines print the number of lines.

• -w : print the number of words.

• -m : print the number of characters.

• -c : print the number of bytes.

• -L : print the length of the longest line

Example-

28 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

16) Echo command :- echo command in linux is used to display line of


text /string that are passed as an argument.

Syntax

Echo <option> <strint>

Example-

29 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

17) Touch command: The touch command used to create, change and
modify timestamps of a file. create a blank new file.
Syntax:
Touch<option> filename

Example :- $ touch file5.txt

Option of touch command :-

• -a; this command is used to change access time only . to change or


update the last access or modification times of a file touch –a command is
used.

Example:

• -c : this command is used to check whether a file is created or not .if


not created don’t create it. This command avoids creating files.
Example-

30 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

• -m : This is used to change the modification time only. It only updates


last modification time.

Example-

31 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

18) Clear command : this command used to clear the terminal screen.

Syntax-
Clear
Example:

32 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

19) Whoami command : it display the username of the current user


when this is invoked .

Syntax :-
Whoami [enter]
Example-

33 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

20) Chmod command : - chmod is another linux command used to


change the read , write, and execute permissions of file and directories.

Syntax: -

$ chmod [reference][operator][mode] file...

References are :

u : owner

g ; group

o ; other

a : all

Operatoes are-

+ : for adding permission

- : for remaining permission

Modes are :

r : permission to read the file.

w : permission to write (or delete) the file

x : permission to execute the file

Example: -

34 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

35 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

21) 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 [enter]

Example-

36 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

22) Vi command:- the vi editor opes in this mode, land it only


understands commands in this mode, you can move the cursor and cut, copy,
paste the text this mode also saves the changes you have made to the file
command are case sensitive.

Syntax :-

Vi <filename>

Example:-

Output-

37 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

23) Shell script :- shell script is a program to write a series of commands


for the sell to execute. It can combine lengthy and repetitive sequences of
commands into a single and simple script that can be stored and execute
anytime which, reduces programming efforts.

Syntax –

Vi filename.sh

Example:-

Create a shell file in vi editor

38 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

24) expr command:- The expr command evaluate a given expression and
display its corresponding output.It is used for:

• Basic operations like addition , subtraction, multiplication,


division, and modulus on integers.
• Evaluating regular expression , string operations like substring,
length of strings etc.

Syntax :-

$ expr expression

Example:- $ expr 3 +7

39 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

40 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

25) test command:- A test command is a command that is used to test the
validity of a command. It checks whether the command/expression is true
or false.

It is used to check the type of file and the permissions related to a file.

Test command returns 0 as a successful exit status if the


command/expression is true, and returns 1 if the command/expression is
false.

Syntax:-

test [expression]

• -eq: equal to
• -ne: not equal
• -ge: greater than or equal to
• -gt: greater than
• -le less than or equal to
• -lt: less than

Example:-

test "variable1' operator "variable2"

41 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

42 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

26) who command:- who command is used to find out the following
information :

1. Time of last system boot

2. Current run level of the system

3. List of logged in users and more.

Description : The who command is used to get information about


currently logged in user on to system.

Syntax :- $who [options] [filename]

Examples :-

1. The who command displays the following information for each user
currently logged in to the system if no option is provided :

Login name of the users

Terminal line numbers

Login time of the users in to system

Remote host name of the user

Output :-

43 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

27) exit command:- exit command in linux is used to exit the shell where
it is currently running. It takes one more parameter as [N] and exits the
shell with a return of status N. If n is not provided, then it simply returns
the status of last command that is executed.

Syntax:-

exit [n]

Example:-

44 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

1.Write a shell script for addition, subtraction, multiplication, division,


modulo division.

Program :-

45 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

2. Write a Linux shell script to check the given year is leap year?

Program :-

46 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

3.Write a Linux shell script to check given number is prime or not?

Program :-

47 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

4. Write a shell program to print Fibonacci series.


Program :-

48 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

5. Write a Linux shell script to calculate factorial of given number.

Program :-

49 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

6. Write a Linux shell script for Armstrong number.

Program :-

50 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

7. Write a Linux shell script to check largest no of three number.

Program :-

51 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

8. Write a shell script to see date, time, username, current directory.

Program :-

52 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

9. Write a Linux shell script to swapping variable.

Program :-

53 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

10. Write a Linux shell script to check given no odd or even.

Program :-

54 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

11. Write shell script to find multiplication table using for loop.

Program :-

55 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

12. Write a Linux shell script to print employee payroll (basic, DA, HRA,
PF, Gross salary, Net Salary).

Program :-

56 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

13.Write a Linux shell script to perform all arithmetic operation using


command line argument.

Program :-

57 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

14. Write a shell script to accept character and check for following?
• If user enter character (A-Z) then show upper case letter.
• If user enter character (a-z) then show lower case letter.
• If user enters digital no (0-9) then show digital number.
*, $, #, @ show its special character.

Program :-

58 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

15. Write a Linux shell script show various system configurations?


• Currently log user and His/her login name.
• Your current shell.
• Your current directory.
• Your operating system type.
• Show mouse setting.
• Show keyboard
• Show network setting.
• Show Path
currently logged number of users

Program :-

59 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

16. Write a shell script to check given name is a file or a directory or special
file or not?
Program :-

60 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

17. Write a shell script to determine whether given file exist or not, existing
file name supplied by command line argument also check for sufficient no
of command line argument.

Program :-

61 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

18. Write shell script to copy the content is one file to another file.

Program :-

62 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

19. Write a shell script to print addition of given of all digits.

Program :-

63 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

20. Write a shell script to search element present in list or not. (Binary &
Linear Search).

Program :- Binary Search-

64 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

65 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

Linear Search :-

66 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

21. Write a shell script for bubble & selection sort.

Program :-

Bubble sort :-

67 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

68 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

Selection Sort :-

69 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

22. Write a Linux shell script to sort the given no in ascending or


descending orders?

Program :-

70 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

71 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

23. Write a Linux shell script to implement read, write and execute
permission.

Program :-

72 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

73 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

24. Write a Linux shell script to print the following pattern.


1
22
333
4444
55555

Program :-

74 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

25. Write a Linux script to print the following pattern using for loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Program :-

75 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

26. Write a Linux shell script to implement break & continue statement.

Program :-

76 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

27. Write a Linux shell script to calculate area of circle & rectangle.

Program :-

77 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

28 .Write a Linux shell script to count no of file in directory.

Program :-

78 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

29. Write a shell script to generate all combination of 1, 2 and 3.

Program :-

79 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

80 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER


LINUX Assignment

30. Write a shell script to check given string or number is palindrome or


not.

Program :-

81 | P a g e NITIN KUMAR SINGAUR MCA 1ST SEMESTER

You might also like