0% found this document useful (0 votes)
78 views8 pages

Basic LINUX Commands and Its Use.: Course Teacher: SAC

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

Lecture Content CSEC228.

Course Teacher: SAC

1. Basic LINUX commands and its Use.

The Linux file system is the structure in which all the information on your computer is
stored. Files are organized within a hierarchy of directories. Each directory can contain files,
as well as other directories.

If you were to map out the files and directories in Linux, it would look like an upside-down
tree. At the top is the root directory, which is represented by a single slash ( / ).

Below that is a set of common directories in the Linux system, such as bin, dev, home, lib ,
and tmp , to name a few. Each of those directories, as well as directories added to the root,
can contain subdirectories.

1
Lecture Content CSEC228.2

Some of the Linux directories that may interest you include the following:

 /bin - Contains common Linux user commands, such as ls, sort , date , and chmod .
 /boot - Has the bootable Linux kernel and boot loader configuration files (GRUB).
 /dev - Contains files representing access points to devices on your systems. These include
terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* or sc* ), RAM ( ram* ), and CD-
ROM ( cd* ). (Applications normally access these devices directly through the device files,
but end users rarely access them directly.)
 /etc - Contains administrative configuration files.
 /home - Contains directories assigned to each user with a login account.
 /media - Provides a location for mounting devices, such as remote file systems and
removable media (with directory names of cdrom , floppy , and so on). In Fedora and RHEL,
many removable media are mounted automatically in this directory when the media is
inserted (CD or DVD) or connected (USB pen drives or cameras ).
 /proc - Provides a mechanism for the kernel to send information to processes.
 /root - Represents the root user's home directory.
 /sbin - Contains administrative commands and daemon processes.
 /sys - A /proc -like file system, added with the Linux 2.6 kernel and intended to contain files
for getting hardware status and reflecting the system's device tree as it is seen by the
kernel. It pulls many of its functions from /proc .
 /tmp - Contains temporary files used by applications.

2
Lecture Content CSEC228.2

 /usr - Contains user documentation, games , graphical files (X11), libraries (lib), and a variety
of other user and administrative commands and files.
 /var - Contains directories of data used by various applications. In particular, this is where
you would place files that you share as an FTP server ( /var/ftp ) or a Web server (
/var/www ). It also contains all system log files ( /var/log ). In time, FTP, HTTP, and similar
services will move to the /srv directory to adhere to the Linux Standards Base (
www.freestandards.org/spec ).

COMMAND :

1.Date Command :

This command is used to display the current data and time.

Syntax :

$date
$date +%ch

Options :

a = Abbrevated weekday.
A = Full weekday.
b = Abbrevated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number.
d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone .

To change the format :


Syntax :

3
Lecture Content CSEC228.2

$date „+%H-%M-%S‟

2.Calender Command :

This command is used to display the calendar of the year or the particular month of
calendar year.

Syntax :
a.$cal <year>
b.$cal <month> <year>

Here the first syntax gives the entire calendar for given year & the second Syntax gives
the calendar of reserved month of that year.

3.Echo Command :

This command is used to print the arguments on the screen .

Syntax : $echo <text>

4.Banner Command :

It is used to display the arguments in „#‟ symbol .

Syntax : $banner <arguments>

5.’who’ Command :

It is used to display who are the users connected to our computer currently.

Syntax : $who – option‟s

Options : -

H–Display the output with headers.


b–Display the last booting date or time or when the system was lastely rebooted.

6.’who am i’ Command :

Display the details of the current working directory.

Syntax : $who am i

4
Lecture Content CSEC228.2

9.’CLEAR’ Command :

It is used to clear the screen.

Syntax : $clear

10.’MAN’ Command :

It help us to know about the particular command and its options & working. It is like
„help‟ command in windows .

Syntax : $man <command name>

11.LIST Command :

It is used to list all the contents in the current working directory.

Syntax : $ ls – options <arguments>


If the command does not contain any argument means it is working in the Current directory.

Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.

DIRECTORY RELATED COMMANDS :

1.Present Working Directory Command :

To print the complete path of the current working directory.

Syntax : $pwd

2.MKDIR Command :

To create or make a new directory in a current directory .

Syntax : $mkdir <directory name>

5
Lecture Content CSEC228.2

3.CD Command :

To change or move the directory to the mentioned directory .

Syntax : $cd <directory name.

4.RMDIR Command :

To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>

FILE RELATED COMMANDS :

1.CREATE A FILE :

To create a new file in the current directory we use CAT command.

Syntax : $cat > <filename.


The > symbol is redirectory we use cat command.

2.DISPLAY A FILE :

To display the content of file mentioned we use CAT command without „>‟ operator.

Syntax : $cat <filename.

Options –s = to neglect the warning /error message.

3.COPYING CONTENTS :

To copy the content of one file with another. If file doesnot exist, a new file is created
and if the file exists with some data then it is overwritten.

Syntax : $ cat <filename source> >> <destination filename>


$ cat <source filename> >> <destination filename> it is avoid overwriting.

Options :

-n content of file with numbers included with blank lines.

Syntax :
$cat –n <filename>

6
Lecture Content CSEC228.2

4.SORTING A FILE :
To sort the contents in alphabetical order in reverse order.

Syntax :
$sort <filename >

Option : $ sort –r <filename>

5.COPYING CONTENTS FROM ONE FILE TO ANOTHER :


To copy the contents from source to destination file . so that both contents are same.

Syntax :
$cp <source filename> <destination filename>
$cp <source filename path > <destination filename path>

6.MOVE Command :
To completely move the contents from source file to destination file and to remove the
source file.
Syntax :
$ mv <source filename> <destination filename>

7.REMOVE Command :
To permanently remove the file we use this command .

Syntax :
$rm <filename>

8.WORD Command :
To list the content count of no of lines , words, characters .
Syntax :

$wc<filename>

Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.

FILTERS AND PIPES

HEAD : It is used to display the top ten lines of file.

Syntax: $head<filename>

7
Lecture Content CSEC228.2

TAIL : This command is used to display the last ten lines of file.

Syntax: $tail<filename>

PAGE : This command shows the page by page a screen full of information is displayed after
which the page command displays a prompt and passes for the user to strike the enter key to
continue scrolling.

Syntax: $ls –a\p

MORE : It also displays the file page by page .To continue scrolling with more command ,
press the space bar key.

Syntax: $more<filename>

SORT : This command is used to sort the data in some order.

Syntax: $sort<filename>

PIPE : It is a mechanism by which the output of one command can be channelled into the input of
another command.

Syntax: $who | wc-l

TR :The tr filter is used to translate one set of characters from the standard inputs to another.

Syntax: $tr “[a-z]” “[A-Z]”

You might also like