Operating System With Linux
Operating System With Linux
(LINUX COMMANDS)
PRACTICAL FILE
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
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
4
OPERATING SYSTEM WITH LINUX
Example:
Harsh
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
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
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…)
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
Harsh
Harsh
Harsh
7
OPERATING SYSTEM WITH LINUX
c. ‘-f’ - long host name (FQDN)
4. arch Command
Syntax:
arch
Example:
5. uname Command
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
Syntax:
who [-H] [-m] [ami] [file]
‘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:
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
Syntax:
cd [directory name]
Example:
Harsh
Harsh
10
OPERATING SYSTEM WITH LINUX
d. ‘cd ../’ - This will move you back one directory
Harsh
11.ls Command
Syntax:
ls [options]
Example:
Harsh
b. ‘-R’ - List current directory and all other directories within current directory
Harsh
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
Syntax:
mkdir [directory name]
Example:
Harsh
Harsh
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 (*, ?, [])
Options Use
* It is used to represent any character.
It is used to represent any single
?
character.
Examples:
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
Harsh
Syntax:
cp oldfile newfile
Example:
Harsh
Harsh
Harsh
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
a. rm -i [letter(s)]* - Remove a file interactively with the file names stating with
letter(s) provided by the user.
Harsh
Harsh
Harsh
Harsh
Harsh
Harsh
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
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
This will combine two file i.e, file1 and file2 into newfile.
Syntax:
cat [file1] [file2] > [newfile]
Example:
Harsh
Harsh
17
OPERATING SYSTEM WITH LINUX
Syntax:
cat [filename]
Example:
Harsh
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
‘-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
Syntax:
paste [option] [files]
Example:
Harsh
Harsh
Harsh
Example:
19
OPERATING SYSTEM WITH LINUX
Harsh
Harsh
Harsh
Example:
Harsh
Harsh
Harsh
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
Example:
Harsh
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
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
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
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
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
Syntax:
finger [username]
Example:
Harsh
25
OPERATING SYSTEM WITH LINUX
28.Clear Command
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]
Example:
Harsh
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:
27
OPERATING SYSTEM WITH LINUX
The letters used in symbolic mode:
‘r’ Read Permission
‘w’ Write Permission
‘x’ Execute Permission
Examples:
Read and write for Owner, and no permission to the group and other:
Harsh
Harsh
2. Octal Mode
28
OPERATING SYSTEM WITH LINUX
In this method we specify permission using three-digit number, where
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:
Syntax:
# free
Example:
Syntax:
# free -b
Example:
Syntax:
# free -k
30
OPERATING SYSTEM WITH LINUX
Example:
Syntax:
#free -m
Example:
Syntax:
#free -g
Example:
31
OPERATING SYSTEM WITH LINUX
Syntax:
#free -t
Example:
Syntax:
#free -o
Example:
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:
Syntax:
# free -V
Example:
33
OPERATING SYSTEM WITH LINUX