0% found this document useful (0 votes)
3 views34 pages

OsLab Linux Commands

The document provides a comprehensive overview of basic Linux commands, including their descriptions, syntax, and sample input/output. Key commands covered include 'touch', 'mkdir', 'pwd', 'cd', 'ls', 'cp', 'rm', and many others, each with specific functionalities for file and directory management. The document serves as a practical guide for users to familiarize themselves with essential Linux command-line operations.

Uploaded by

honipi9957
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)
3 views34 pages

OsLab Linux Commands

The document provides a comprehensive overview of basic Linux commands, including their descriptions, syntax, and sample input/output. Key commands covered include 'touch', 'mkdir', 'pwd', 'cd', 'ls', 'cp', 'rm', and many others, each with specific functionalities for file and directory management. The document serves as a practical guide for users to familiarize themselves with essential Linux command-line operations.

Uploaded by

honipi9957
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/ 34

Experiment 1

Date:17-05-2022

Familiarization of Linux Commands


Aim
To familiarize and understand basic linux commands and their uses.

1 Commands
1.1 touch
1.1.1 Description
Used to make a new file in current directory.

1.1.2 Syntax
touch filename

1.1.3 Sample Input and Output

Figure 1.1: Output

1.2 mkdir
1.2.1 Description
Used to make a new directory in current directory.

1.2.2 Syntax
mkdir directory_name
1.3 pwd 1 COMMANDS

1.2.3 Sample Input and Output

Figure 1.2: Output

1.3 pwd
1.3.1 Description
Prints the present working directory

1.3.2 Syntax
pwd

1.3.3 Sample Input and Output

Figure 1.3: Output

1.4 cd
1.4.1 Description
Used to change directory

1.4.2 Syntax
cd directory_name

1.4.3 Sample Input and Output

Figure 1.4: Output

2
1.5 cat 1 COMMANDS

1.5 cat
1.5.1 Description
Views the content of a file

1.5.2 Syntax
cat filename

1.5.3 Sample Input and Output

Figure 1.5: Output

1.6 more
1.6.1 Description
Views the content of a file one scornful at a time

1.6.2 Syntax
more filename

1.6.3 Sample Input and Output

Figure 1.6: Output

1.7 ls
1.7.1 Description
List files in a directory.

1.7.2 Syntax
ls

3
1.8 ls -l 1 COMMANDS

1.7.3 Sample Input and Output

Figure 1.7: Output

1.8 ls -l
1.8.1 Description
Provides long listing of files.

1.8.2 Syntax
ls -l

1.8.3 Sample Input and Output

Figure 1.8: Output

1.9 ls -l -h
1.9.1 Description
Provides size of files in human readable form.

4
1.10 ls -F 1 COMMANDS

1.9.2 Syntax
ls -l -h

1.9.3 Sample Input and Output

Figure 1.9: Output

1.10 ls -F
1.10.1 Description
Make all the executable with * and directories with /

1.10.2 Syntax
ls -F

1.10.3 Sample Input and Output

Figure 1.10: Output

5
1.11 ls -a 1 COMMANDS

1.11 ls -a
1.11.1 Description
Show all the file in the present directory with special dot files.

1.11.2 Syntax
ls -a

1.11.3 Sample Input and Output

Figure 1.11: Output

1.12 cp
1.12.1 Description
Used to copy files and directories

1.12.2 Syntax
cp file1 file2
cp dir1 dir2

6
1.13 rm 1 COMMANDS

1.12.3 Sample Input and Output

Figure 1.12: Output

1.13 rm
1.13.1 Description
Remove a file.

1.13.2 Syntax
rm filename

7
1.14 rmdir 1 COMMANDS

1.13.3 Sample Input and Output

Figure 1.13: Output

1.14 rmdir
1.14.1 Description
Used to remove directory.

1.14.2 Syntax
rmdir directory_name

1.14.3 Sample Input and Output

Figure 1.14: Output

1.15 clear
1.15.1 Description
Used to clear the contents of the terminal.

1.15.2 Syntax
clear

8
1.16 man 1 COMMANDS

1.15.3 Sample Input and Output

Figure 1.15: Output

1.16 man
1.16.1 Description
View help of the specific command name.

1.16.2 Syntax
man command_name

9
1.17 tree 1 COMMANDS

1.16.3 Sample Input and Output

Figure 1.16: Output

1.17 tree
1.17.1 Description
Used to list or display the contents of a directory in a tree like format.

1.17.2 Syntax
tree directory_name

10
1.18 locate 1 COMMANDS

1.17.3 Sample Input and Output

Figure 1.17: Output

1.18 locate
1.18.1 Description
Used to find files using filename.

1.18.2 Syntax
locate [options] file_name

1.18.3 Sample Input and Output

Figure 1.18: Output

1.19 kill
1.19.1 Description
kill command is used to terminate the process manually.

1.19.2 Syntax
kill [options] pid

11
1.20 less 1 COMMANDS

1.19.3 Sample Input and Output

Figure 1.19: Output

1.20 less
1.20.1 Description
Views content of a file one scornful at a time. less command is similar to the more command
but faster than more.

1.20.2 Syntax
less filename

12
1.21 who 1 COMMANDS

1.20.3 Sample Input and Output

Figure 1.20: Output

1.21 who
1.21.1 Description
Used to display who is logged in.

1.21.2 Syntax
who

1.21.3 Sample Input and Output

Figure 1.21: Output

1.22 top
1.22.1 Description
Used to display resource being used in the system.

1.22.2 Syntax
top

13
1.23 chmod 1 COMMANDS

1.22.3 Sample Input and Output

Figure 1.22: Output

1.23 chmod
1.23.1 Description
Used to modify file access right.

1.23.2 Syntax
chmod options permissions filename

14
1.24 chown 1 COMMANDS

1.23.3 Sample Input and Output

Figure 1.23: Output

1.24 chown
1.24.1 Description
It is used to change the user and/ or group ownership of a given file, directory or symbolic link.

1.24.2 Syntax
chown [options] user [:group] file(s)

15
1.25 redirection (>) 1 COMMANDS

1.24.3 Sample Input and Output

Figure 1.24: Output

1.25 redirection (>)


1.25.1 Description
Overwrites the file with output of the command.

1.25.2 Syntax
Command > filename

16
1.26 redirection (») 1 COMMANDS

1.25.3 Sample Input and Output

Figure 1.25: Output

1.26 redirection (»)


1.26.1 Description
Appends the file with output of the command.

1.26.2 Syntax
Command >> filename

17
1.27 redirection (<) 1 COMMANDS

1.26.3 Sample Input and Output

Figure 1.26: Output

1.27 redirection (<)


1.27.1 Description
Used to redirect standard input to a file.

18
1.28 piping (|) 1 COMMANDS

1.27.2 Syntax
command < filename

1.27.3 Sample Input and Output

Figure 1.27: Output

1.28 piping (|)


1.28.1 Description
Used to redirect standard output of one command to the standard input of another command.

1.28.2 Syntax
command1 | command2

19
1.29 Filters (sort) 1 COMMANDS

1.28.3 Sample Input and Output

Figure 1.28: Output

1.29 Filters (sort)


1.29.1 Description
Sorts the standard input and sends the output to standard output.

1.29.2 Syntax
sort filename

1.29.3 Sample Input and Output

Figure 1.29: Output

20
1.30 Filters (uniq) 1 COMMANDS

1.30 Filters (uniq)


1.30.1 Description
Given a sorted stream of data from standard input , it removes the duplicate lines of data and
return the result to the standard output.

1.30.2 Syntax
uniq filename

1.30.3 Sample Input and Output

Figure 1.30: Output

1.31 Filters (grep)


1.31.1 Description
Examines each line of data it receives from standard input and outputs all lines that contains a
specific pattern of characters.

1.31.2 Syntax
grep “string” filename

21
1.32 Filters (fmt) 1 COMMANDS

1.31.3 Sample Input and Output

Figure 1.31: Output

1.32 Filters (fmt)


1.32.1 Description
Reads the text from standard input and output formatted text to standard output.

1.32.2 Syntax
fmt filename

22
1.33 Filters (pr) 1 COMMANDS

1.32.3 Sample Input and Output

Figure 1.32: Output

1.33 Filters (pr)


1.33.1 Description
Takes the data from the standard input and splits data into pages with page breaks, footers and
headers in preparation for printing.

1.33.2 Syntax
pr filename

23
1.34 Filters (head) 1 COMMANDS

1.33.3 Sample Input and Output

Figure 1.33: Output

1.34 Filters (head)


1.34.1 Description
Outputs the first few lines of a file and returns it to the standard output.

1.34.2 Syntax
head -n filename
(n – number of lines to be printed, default value = 10)

24
1.35 Filters (tail) 1 COMMANDS

1.34.3 Sample Input and Output

Figure 1.34: Output

1.35 Filters (tail)


1.35.1 Description
Outputs the last few lines of a file and returns it to the standard output.

1.35.2 Syntax
tail -n filename
(n – number of lines to be printed, default value = 10)

25
1.36 Filters (tr) 1 COMMANDS

1.35.3 Sample Input and Output

Figure 1.35: Output

1.36 Filters (tr)


1.36.1 Description
Translates characters, can be used to perform tasks such as uppercase to lowercase conversions.

1.36.2 Syntax
tr [:lower:] [:upper:]

1.36.3 Sample Input and Output

Figure 1.36: Output

26
1.37 Job control (ps) 1 COMMANDS

1.37 Job control (ps)


1.37.1 Description
List the processes running in the system.

1.37.2 Syntax
ps

1.37.3 Sample Input and Output

Figure 1.37: Output

1.38 su
1.38.1 Description
Temporarily become super user. It is used to switch from one user to another.

1.38.2 Syntax
su username

1.38.3 Sample Input and Output

Figure 1.38: Output

1.39 alias
1.39.1 Description
It lets the user to give names of his/her choice to a command or sequence of commands.

1.39.2 Syntax
alias alternatename=command

27
1.40 df 1 COMMANDS

1.39.3 Sample Input and Output

Figure 1.39: Output

1.40 df
1.40.1 Description
The df command shows the size used and available space on the mounted file system of your
computer. Human readable (-h) option displays the sizes in mb or gb instead of bytes The
exclude (-x) option allows you to tell df to disount filesystems you are not interested in.

1.40.2 Syntax
df [options] filename

28
1.41 diff 1 COMMANDS

1.40.3 Sample Input and Output

Figure 1.40: Output

1.41 diff
1.41.1 Description
Compares two text files and shows the difference between them. The -y (side by side) option
shows the line differences side by side The -w (width) option lets you specify the maximum line
width to use to avoid wraparound lines The suppress-common-lines prevents diff from listing the
matching lines, letting you focus on the lines which have differences.

1.41.2 Syntax
diff [options] filename1 filename2

29
1.42 echo 1 COMMANDS

1.41.3 Sample Input and Output

Figure 1.41: Output

1.42 echo
1.42.1 Description
It prints the string of text to the terminal window.

1.42.2 Syntax
echo “string of text”

1.42.3 Sample Input and Output

Figure 1.42: Output

30
1.43 find 1 COMMANDS

1.43 find
1.43.1 Description
Used to track down files that the user know exists but forgot its path.

1.43.2 Syntax
find startlocation -name *filename*

1.43.3 Sample Input and Output

Figure 1.43: Output

1.44 free
1.44.1 Description
Gives a summary of memory usage with computer. -h option provides human friendly numbers
and units.

1.44.2 Syntax
free option

1.44.3 Sample Input and Output

Figure 1.44: Output

1.45 groups
1.45.1 Description
It tells which group the user is a member of

31
1.46 gzip 1 COMMANDS

1.45.2 Syntax
groups username

1.45.3 Sample Input and Output

Figure 1.45: Output

1.46 gzip
1.46.1 Description
Used to compress the files. By default, it removes the original file and leaves you with the
compressed version. To retain both, use -k (keep) option.

1.46.2 Syntax
gzip option filename

1.46.3 Sample Input and Output

Figure 1.46: Output

1.47 history
1.47.1 Description
The history command lists the commands you have previously issued on the command line. You
repeat any of the command from history list by typing an exclamation mark(!) and the number
of the command from the history list.

1.47.2 Syntax
history

32
1.48 mv 1 COMMANDS

1.47.3 Sample Input and Output

Figure 1.47: Output

1.48 mv
1.48.1 Description
Used to move files and directories from directory to directory.

1.48.2 Syntax
mv dir/file dirname

33
1.49 shutdown 1 COMMANDS

1.48.3 Sample Input and Output

Figure 1.48: Output

1.49 shutdown
1.49.1 Description
Using shutdown with no parameters will shutdown the computer in one minute, shutdown now
command will shutdown computer immediately.

1.49.2 Syntax
shutdown option

1.49.3 Sample Input and Output

Figure 1.49: Output

34

You might also like