0% found this document useful (0 votes)
4 views

Operating System With Linux

Uploaded by

harshkum766
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Operating System With Linux

Uploaded by

harshkum766
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

OPERATING SYSTEM WITH LINUX

(LINUX COMMANDS)

PRACTICAL FILE

Submitted By: Submitted To:


RAMAN KUMAR MANJHI Dr. KAVITA MITTAL
Roll No. - 038
MCA-I
INDEX
S. No. Commands Page No. Date
BASIC COMMANDS
1 echo 3
2 date 5
3 hostname 6
4 arch 7
5 uname 7
6 uptime 7
7 whoami 8
8 who 8
DIRECTORY MANAGEMENT COMMANDS
9 pwd 9
10 cd 9
11 ls 10
12 mkdir 11
13 rmdir 11
FILE COMMANDS
14 wildcards (*, ?, []) 12
15 copy(cp) 13
16 rename (mv) 13
17 remove file (rm) 14
18 word count (wc) 15
19 display file (file) 15
20 concatenate files(cat) 16
21 touch 17
22 paste 18
23 sort 19
24 cut 21
25 head and tail 22
26 spell 24
27 finger 24

2
OPERATING SYSTEM WITH LINUX
28 clear 25
29 grep 25
30 chmod 26
MEMORY MANAGEMENT COMMANDS
31 Display System Memory 30
32 Display Memory in Bytes 30
33 Display Memory in Kilobytes 30
34 Display Memory in Megabytes 31
35 Display Memory in Gigabytes 31
36 Display Total Line 31
37 Disable Display of Buffer Adjusted Line 32
38 Display Memory Status for Regular Intervals 32
39 Show Low and High Memory Statistics 33
40 Check Free Versions 33

3
OPERATING SYSTEM WITH LINUX
BASIC COMMANDS
1. echo Command

Echo is a built-in command in the bash and C shells that writes its arguments to standard
output.

Syntax:
echo [option(s)] [string(s)]

Here,
[options] = The various options available for modifying the behavior of the `echo`
command.
[string] = It is the string that we want to display.

Example:
i. Display message on screen
Harsh

ii. Display the value of a variable


Harsh
Harsh

iii. Show the values of environmental variables. For example, to see the value of HOME,
the environmental value that shows the current user’s home directory.
Harsh

iv. Show a user’s PATH environmental variable


Harsh

v. Append message and command output on screen


Harsh

Options available with echo commands:


a. ‘-n’: The -n option can be used to stop echo from adding the newline to output.

4
OPERATING SYSTEM WITH LINUX
Example:
Harsh
Harsh

b. ‘-e’: The -e option is used to enable echo’s interpretation of additional instances


of the newline character as well as the interpretation of other special characters,
such as:
o ‘\n’ - this option creates a new line from where it is used.
o ‘\t’ - this option is used to create horizontal tab spaces.
o ‘\v’ - this option is used to create vertical tab spaces
o ‘\\’ - this is used to add backslash
o ‘\b’ - it removes all the spaces in between the text
o ‘\c’ - suppress trailing new line with backspace interpreter ‘-e’ to continue
without emitting new line.
o ‘\r’ - carriage return with backspace interpreter ‘-e’ to have specified
carriage return in output.
o ‘\a’ - alert return with backspace interpreter ‘-e’ to have sound alert.
Example:
Harsh

c. Redirecting `echo` Output: The output of the `echo` can be redirected to a file
instead of displaying it on the terminal. We can achive this by using the `>` or
`>>` operators for output redirection.

Example:
• Write message File created to a file called log.txt
Harsh
Harsh

Harsh

• Append message File deleted to the file log.txt


Harsh
Harsh

2. date Command

5
OPERATING SYSTEM WITH LINUX
Linux “date” command returns you the date and time when you call it
without any options.

Syntax:
date [option]... [+format]

Here,
[option] = The various options available for modifying the behavior of the `date`
command.
[format] = It is used to display the current time in the given FORMAT.

Example:
Display the current date and time using “date” command.
Harsh

Formatting options available with date commands:


i. To just get the date:
Harsh

ii. To get the date, complete with date, month, and year:
Harsh

iii. To get the day of the week along with the rest of the date:
Harsh

There are several other possibilities of formatting that the “date” command offers. Some
of them are:
%D date (mm/dd/yy)
%d day of month (01..31)
%m month (01..12)
%y last two digits of year (00..99)
%a locale’s abbreviated weekday name (Sun..Sat)
%A locale’s full weekday name, variable length (Sunday..Saturday)
%b locale’s abbreviated month name (Jan..Dec)
%B locale’s full month name, variable length (January..December)
%H hour (00..23)
%I hour (01..12)
6
OPERATING SYSTEM WITH LINUX
%Y year (1970…)

Options available with date commands:


a. ‘-s’ - set time described by STRING

b. ‘-u’ - print or set Coordinated Universal Time (UTC)


Harsh

3. hostname Command

Hostname is the program that is used to either set or display the current
host, domain or node name of the system.

Syntax:
hostname [options] [name]

Here,
[option] = The various options available for modifying the behavior of the `hostname`
command.
[name] = The hostname can be changed by using the ‘-b’ option from root only.

Example:
Display the hostname of the current user.
Harsh

Options available with hostname commands:

a. ‘-b’ - set default hostname if none available.


Harsh

Harsh

Harsh
Harsh

b. ‘-a’ - alias names

7
OPERATING SYSTEM WITH LINUX
c. ‘-f’ - long host name (FQDN)

d. ‘-i’ - addresses for the host name

e. ‘-s’ - short host name

f. ‘-d’ - DNS domain name

4. arch Command

This command is used to get architecture type (print machine architecture)

Syntax:
arch

Example:

5. uname Command

This command prints name of current system.

Syntax:
uname

Example:

6. uptime Command

This command tells how long the system has been running.

8
OPERATING SYSTEM WITH LINUX
Syntax:
uptime

Example:

7. whoami Command

This prints the user name associated with the current effective user
ID.

Syntax:
whoami

Example:

8. who Command

This command displays who is on the system.

Syntax:
who [-H] [-m] [ami] [file]

‘-H’ - Output column headings above the regular output.


Example:

‘ami’ - In the “C” locale, limit the output to describing the invoking user, equivalent to
the -m option. The am and I or I must be separate arguments.

Example:

‘-m’ - Output only information about the current terminal.


‘-u’ - List only those users who are currently logged in.

9
OPERATING SYSTEM WITH LINUX
DIRECTORY MANAGEMENT COMMANDS
9. pwd Command

pwd is the basic command that can be to display the directory that you are currently in or
your working directory.

Syntax:
pwd

Example:

Harsh
Harsh

10.cd Command

To switch to another directory, the command cd is used.

Syntax:
cd [directory name]

Example:
Harsh
Harsh

Options available with cd command:

a. ‘cd’ - This will place you in your home directory


Harsh

b. ‘cd /’ - This will move you to the root directory

c. ‘cd /etc’ - This will move you to the /etc directory.


Harsh

10
OPERATING SYSTEM WITH LINUX
d. ‘cd ../’ - This will move you back one directory
Harsh

11.ls Command

The command ls is used to list the contents of a directory.

Syntax:
ls [options]

Example:
Harsh

Options available with ls command:

a. ‘-l’ - Long listing


Harsh

b. ‘-R’ - List current directory and all other directories within current directory

Harsh

Harsh

c. ‘-a’ - List hidden files

d. ‘-r’ - List in reverse alphabetically order


Harsh

11
OPERATING SYSTEM WITH LINUX
e. ‘-t’ - List more recent accessed files first
Harsh

f. ‘-CF’ - List in column format and append ‘*’ to executable files, ‘@’ to symbolic
linked files, ‘/’ to directories
Harsh

12.mkdir Command

The command mkdir is used to create a new directory.

Syntax:
mkdir [directory name]

Example:
Harsh
Harsh

13.rmdir Command / rm -r Command

The command rmdir is used to delete an empty directory. The command rm -r is used to
delete the existing directory with a particular name and all directories and files in it.

Syntax:
rmdir [existing empty directory name] / rm -r [existing directory name]

Example: rmdir
Harsh
Harsh

Example: rm -r
Harsh

Harsh

Harsh
Harsh

12
OPERATING SYSTEM WITH LINUX
FILE COMMANDS
14.WildCards (*, ?, [])

Wildcard characters are used to help find file or directory names.

Options Use
* It is used to represent any character.
It is used to represent any single
?
character.

Values entered within square bracket


[from-to] represent a range (from-to) for a single
character

Values entered within square brackets


[!from-to] represent a range (from-to) to exclude
for a single character.

Examples:

a* - all files starting with the letter ‘a’.


Harsh

*t - all files where the last character is a ‘t’.


Harsh

l*t - all files that start with the letter ‘l’ and end with ‘t’.
Harsh

th?? - all files that start with ‘th’ and are only four characters long

Harsh

13
OPERATING SYSTEM WITH LINUX
[a-c]* - all files that start with ‘a, b or c’

Harsh

x[A-C]* - all files that start with the letter ‘x’ and the second character contains ‘A, B or
C’.

Harsh

[!M-O]* - all files except those that start with ‘M, N or O’

Harsh

15. Copy Files (cp command)

To copy a file, the command cp is used.

Syntax:
cp oldfile newfile

Example:
Harsh

Harsh
Harsh

16.Rename files (mv command)

The command mv is used to rename a file.

Syntax:
mv oldfilename newfilename

Example:
Harsh

Harsh
Harsh

14
OPERATING SYSTEM WITH LINUX
17.Remove file (rm command)

This command is used to remove objects such as files, directories, symbolic links and so
on.

Syntax:
rm [option][file]

Example:
Harsh

Harsh
Harsh
Harsh

Options available with rm command:

a. rm -i [letter(s)]* - Remove a file interactively with the file names stating with
letter(s) provided by the user.
Harsh

Harsh

Harsh

b. rm -rf - Remove a directory forcefully.

Harsh

Harsh

Harsh
Harsh

c. rm -d - It removes an empty directory and works only if the named directory is


empty.
Harsh

Harsh
Harsh

15
OPERATING SYSTEM WITH LINUX
18.Count the number of lines, words or characters (wc)

The command wc is used to count lines, words or characters in a file or piped results
from another command.

Syntax:
wc [option] [file]

Example:
Harsh

Options available with wc command:

‘-c’ - It is used to print the byte counts.


Harsh

‘-l’ - It is used to print the newline counts.


Harsh

‘-w’ - It is used to print the word counts.


Harsh

19.Display file type (file command)

The command file is used to display a description for the type.

Syntax:
file [filename]

Example:
Harsh

Harsh

16
OPERATING SYSTEM WITH LINUX
20.Concatenate files (cat command)

The command cat is a multi-purpose utility and is mostly used with TEXT files.
The cat command has multiple functions –

a. Create a new file and optionally allow the manual entry of contents
i. cat > [filename]
ii. Example: cat > list.txt will create a file named list and allow you to enter
contents.
iii. Press Control-D to exit entry mode.
iv. WARNING: If “list” already existed, this command would replace the old
file with the contents of the new file.

Syntax:
cat > [filename]

Example:
Harsh

b. Combine text files

This will combine two file i.e, file1 and file2 into newfile.

Syntax:
cat [file1] [file2] > [newfile]

Example:
Harsh
Harsh

c. Display the contents of a file

17
OPERATING SYSTEM WITH LINUX
Syntax:
cat [filename]

Example:

Harsh

d. Delete the contents of a file

Syntax:
cat /dev/null > [filename]

Example:
Harsh
Harsh

21.Touch command

Touch command is used to create a file. It can change file access and modification time.

Syntax:
touch [option] [filename(s)]

Example:

Harsh
Harsh

Options available with touch command:

‘-a’ - Change the access time of file. Do not change the modification time unless -m is
also specified.

Example:
Harsh
Harsh

18
OPERATING SYSTEM WITH LINUX
‘-c’ - Do not create a specified file if it does not exist. Do not write any diagnostic
messages concerning this condition.

Example:
Harsh
Harsh

‘-m’ - Change the modification time of file. Do not change the access time unless -a is
also specified.

Example:
Harsh
Harsh

22.Paste command

Merge corresponding or subsequent lines of files.

Syntax:
paste [option] [files]

Options available with paste command:

To merge two files horizontally with tab as delimiter.

Example:
Harsh

Harsh

Harsh

To merge two files horizontally with ‘|’ and ‘,’ as delimiters.

Example:

19
OPERATING SYSTEM WITH LINUX
Harsh

Harsh

Harsh

To merge two files sequentially with tab as delimiter.

Example:
Harsh

Harsh

Harsh

To merge the standard input with a file horizontally.

Example:
Harsh
Harsh

23.Sort command

SORT command is used to sort a file, arranging the records in a particular order.

Syntax:
sort [option] [file]

Example:
Harsh

Harsh

20
OPERATING SYSTEM WITH LINUX
Options available with sort command:
‘-f’ - fold lower case to upper case characters

Example:
Harsh

Harsh

‘-r’ - the result of comparisons

Example:
Harsh

‘-n’ - according to string numerical value

Example:
Harsh

Harsh

21
OPERATING SYSTEM WITH LINUX
24.Cut command

The cut command takes a vertical slice of a file, printing only the specified columns or
fields.

Syntax:
cut [option] [file]

Example:
Harsh

Harsh

Options available with cut command:

‘-b’ - select only these bytes

Example:
Harsh

Harsh

22
OPERATING SYSTEM WITH LINUX
‘-d’ - use DELIM instead of TAB for field delimiter

‘-f’ - select only these fields; also print any line that contains no delimiter character,
unless the -s option is specified

Example:
Harsh

Harsh

25.Head & Tail command

Head: The head command displays the first few lines at the top of a file. By default, head
will show the first ten lines of a file, but you can also tell it how many lines to display.

Syntax:
head [-number | -n number] [filename]

Example:
Harsh

Harsh

Option available with head command:

23
OPERATING SYSTEM WITH LINUX
‘-n’ - The number of the lines you want to display.

Example:
Harsh

Harsh

Tail: The tail command displays the last few lines of a file.

Syntax:
tail [ number | -n number] [file]

Example:
Harsh

Harsh

Option available with tail command:

24
OPERATING SYSTEM WITH LINUX
‘-n’ - The number of last n lines of the file that you want to display.

Example:
Harsh

26.Spell Command

Looks through a text file and reports any words that it finds in the text file that are not in
the dictionary.

Syntax:
Spell [filename]

Example:
Harsh

Harsh

27.Finger command

Lists information about the user.

Syntax:
finger [username]

Example:
Harsh

25
OPERATING SYSTEM WITH LINUX
28.Clear Command

To clear the complete screen.

Syntax:
clear

Example:
Harsh
Harsh

29.grep command

grep searches the input files for lines containing a match to a given pattern list.

Syntax:
grep [options] pattern [files]

grep [‘word’] [filename]


grep [‘string1 string2’] [filename]
cat [file] | grep [‘something’]

Example:
Harsh

Options available with grep command:

Case insensitive search (-i): The ‘-i’ option enables to search for a string case
insensitively in the given file.

Example:
Harsh

26
OPERATING SYSTEM WITH LINUX
Displaying the count of number of matches (-c): We can find the number of lines that
matches the given string/pattern

Example:
Harsh

Harsh

Display the file names that matches the pattern (-l): We can just display the files that
contains the given string/pattern.

Example:
Harsh

Checking for the whole words in a file (-w): By default, grep matches the given
string/pattern even if it is found as a substring in a file.

Example:
Harsh

30.chmod command

The `chmod` command is used to modify this permission so that it can grant or restrict
access to directories and files.

Syntax:
chmod [options] [mode] [File_name]

The different “modes” available in Linux helps in setting new permissions that have to be
applied to files or directories. There are two types of modes:

1. Symbolic Mode, the symbols used in this:


‘+’ Add Permission
‘-‘ Remove Permission
Set the permissions to the
‘=’
specified values

27
OPERATING SYSTEM WITH LINUX
The letters used in symbolic mode:
‘r’ Read Permission
‘w’ Write Permission
‘x’ Execute Permission

The references used in symbolic mode:


‘u’ Owner
‘g’ Group
‘o’ Others
‘a’ All

Examples:

Removing read permission from the owner:


Harsh
Harsh

Granting the read and write permission to the user:


Harsh
Harsh

Read and write for Owner, and no permission to the group and other:
Harsh
Harsh

2. Octal Mode

The digits used in octal mode are:


4 Read Permission
2 Write Permission
1 Execute Permission

28
OPERATING SYSTEM WITH LINUX
In this method we specify permission using three-digit number, where

First digit specifies the permission for Owner.


Second digit specifies the permission for Group.
Third digit specifies the permission for Others.

Examples:

Command that gives all three permissions to everyone (owner, group and other):

Harsh
Harsh
Harsh
Harsh

Command that gives the owner can write, read and execute a file, group and
other can only read and execute a file:

29
OPERATING SYSTEM WITH LINUX
MEMORY MANGEMENT COMMANDS:

31. Display System Memory


Free command used to check the used and available space of physical memory and swap
memory in KB. See the command in action below.

Syntax:
# free

Example:

32. Display Memory in Bytes


Free command with option -b, display the size of memory in Bytes.

Syntax:
# free -b

Example:

33. Display Memory in Kilobytes


Free command with option -k, display the size of memory in (KB) Kilobytes.

Syntax:
# free -k

30
OPERATING SYSTEM WITH LINUX
Example:

34. Display Memory in Megabytes


To see the size of the memory in (MB) Megabytes use option as -m.

Syntax:
#free -m

Example:

35. Display Memory in Gigabytes:


Using -g option with free command, would display the size of the memory in
GB(Gigabytes).

Syntax:
#free -g

Example:

36. Display Total Line


Free command with -t option, will list the total line at the end.

31
OPERATING SYSTEM WITH LINUX
Syntax:
#free -t

Example:

37. Disable Display of Buffer Adjusted Line


By default the free command display “buffer adjusted” line, to disable this line use option
as -o.

Syntax:
#free -o

Example:

38. Display Memory Status for Regular Intervals


The -s option with number, used to update free command at regular intervals. For
example, the below command will update free command every 5 seconds.

Syntax:
# free -s 5

Example:

32
OPERATING SYSTEM WITH LINUX
39. Show Low and High Memory Statistics
The -l switch displays detailed high and low memory size statistics.

Syntax:
# free -l

Example:

40. Check Free Versions


The -V option, display free command version information.

Syntax:
# free -V

Example:

33
OPERATING SYSTEM WITH LINUX

You might also like