+ All Categories
Home > Documents > Linux Command

Linux Command

Date post: 04-Jan-2016
Category:
Upload: chandan705136
View: 231 times
Download: 0 times
Share this document with a friend
Description:
Study of Linux Command and GUI
Popular Tags:
13
USE AND STUDY OF LINUX GUI AND COMMANDS COMPILED BY: CHANDAN PRASAD FUNDAMENTALS OF PROGRMMING LANGUAGES-I F.E ASSIGNMENT NO.1 AUGUST 3, 2015
Transcript

USE AND STUDY OF LINUX GUI AND

COMMANDS

COMPILED BY: CHANDAN PRASAD

FUNDAMENTALS OF PROGRMMING LANGUAGES-I

F.E

ASSIGNMENT NO.1

AUGUST 3, 2015

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 1

ASSIGNMENT NO: 1 COMPILED BY: - CHANDAN PRASAD

AIM: Use and Study of LINUX GUI and Commands.

OBJECTIVE: To learn how to use Linux GUI and Commands.

THEORY:

LINUX

Linux is one of popular version of UNIX operating System. It is open source as its source code

is freely available. It is free to use. Linux was designed considering UNIX compatibility. Its

functionality list is quite similar to that of UNIX.

COMPONENTS OF LINUX SYSTEM

Linux Operating System has primarily three components:

Kernel - Kernel is the core part of Linux. It is responsible for all major activities of this

operating system. It is consists of various modules and it interacts directly with the

underlying hardware. Kernel provides the required abstraction to hide low level hardware

details to system or application programs.

System Library - System libraries are special functions or programs using which

application programs or system utilities accesses Kernel's features. These libraries

implements most of the functionalities of the operating system and do not requires kernel

module's code access rights.

System Utility - System Utility programs are responsible to do specialized, individual

level tasks.

Kernel Mode vs User Mode

Kernel component code executes in a special privileged mode called kernel mode with full access

to all resources of the computer. This code represents a single process, executes in single address

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 2

space and do not require any context switch and hence is very efficient and fast. Kernel runs each

processes and provides system services to processes, provides protected access to hardware’s to

processes.

Support code which is not required to run in kernel mode is in System Library. User programs

and other system programs works in User Mode which has no access to system hardware’s and

kernel code. User programs/ utilities use System libraries to access Kernel functions to get

system's low level tasks.

BASIC FEATURES

Following are some of the important features of Linux Operating System.

Portable - Portability means software’s can works on different types of hardware’s

in same way. Linux kernel and application programs supports their installation on

any kind of hardware platform.

Open Source - Linux source code is freely available and it is community based

development project. Multiple team’s works in collaboration to enhance the

capability of Linux operating system and it is continuously evolving.

Multi-User - Linux is a multiuser system means multiple users can access system

resources like memory/ ram/ application programs at same time.

Multiprogramming - Linux is a multiprogramming system means multiple

applications can run at same time.

Hierarchical File System - Linux provides a standard file structure in which system

files/ user files are arranged.

Shell - Linux provides a special interpreter program which can be used to execute

commands of the operating system. It can be used to do various types of operations,

call application programs etc.

Security - Linux provides user security using authentication features like password

protection/ controlled access to specific files/ encryption of data.

Architecture

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 3

Linux System Architecture is consists of following layers:

Hardware layer - Hardware consists of all peripheral devices (RAM/ HDD/ CPU

etc.)

Kernel - Core component of Operating System, interacts directly with hardware,

provides low level services to upper layer components.

Shell - An interface to kernel, hiding complexity of kernel's functions from users.

Takes commands from user and executes kernel's functions.

Utilities - Utility programs giving user most of the functionalities of an operating

systems.

LINUX COMMAND (LAB ASSIGNMENT a1)

cat - A Unix/Linux command that can read, modify or concatenate text files,

most commonly used for displaying contents of files.

cat /etc/motd

This command will display the contents of the motd

cat > newfile

some notes I want to save in newfile.

CTRL-D

This creates a new file (named newfile). You type as much text as you wish, then type ctrl-D to

save the file.

root@SDR:/home/sunil# cat > chandan.c

Hi friends kindly press Ctrl+D to save

root@SDR:/home/sunil# ls -l

total 52

drwxr-xr-x 2 root root 4096 Aug 6 14:35 chandan

-rw-r--r-- 1 root root 40 Aug 6 14:38 chandan.c

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Documents

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Downloads

-rw-r--r-- 1 sunil sunil 8980 Aug 5 11:31 examples.desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Music

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Pictures

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Public

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 4

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Templates

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Videos

cd - The cd command changes the current directory in Linux, and can toggle

between directories conveniently. It is similar to the CD and CHDIR commands

in MS-DOS.

cd [directory]

root@SDR:/home/sunil# cd chandan

root@SDR:/home/sunil/chandan# ls

chandan.c

cd ..- This command allow to roll back to parent directory.

root@SDR:/home/sunil/chandan# cd ..

root@SDR:/home/sunil#

chmod - chmod changes the access mode (permissions) of one or more files.

Only the owner of a file or a privileged user may change the mode.

Instead of using alphabets u, g, o for user, group, and others we can use numbers to specify file

permissions:

rwx = 111 = 7

rw- = 110 = 6

r-x = 101 = 5

r-- = 100 = 4

-wx = 011 = 3

-w- = 010 = 2

--x = 001 = 1

--- = 000 = 0

Command:

chmod go+rx filename = chmod 755 filename

Let’s change some of the permissions:

-rwxr-xr-x joe acctg archive.sh

-rw-rw-r-- joe acctg orgchart.gif

-rw-rw-r-- joe acctg personnel.txt

-rw-r--r-- joe acctg publicity.html

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 5

drwxrwxr-x joe acctg sales

-rw-r----- joe acctg topsecret.inf

-rwxr-xr-x joe acctg wordmatic

First, let’s prevent outsiders from executing archive.sh

Before: -rwxr-xr-x archive.sh

Command: chmod 754 archive.sh

After: -rwxr-xr-- archive.sh

Open up publicity.html for reading and writing by anyone.

Before: -rw-r--r-- publicity.html

Command: chmod 666 publicity.html

After: -rw-rw-rw- publicity.html

cp - The cp command copies files and directories, and copies can be made

simultaneously to another directory if the copy is under a different name.

cp sourcefile targetfile

root@SDR:/home/sunil# cp chandan.c chandan

root@SDR:/home/sunil# cd chandan

root@SDR:/home/sunil/chandan# ls

chandan.c

date - Date sets a system's date and time. Also a useful way to output/print

current information when working in a script file.

root@SDR:/home/sunil# date

Thu Aug 6 14:45:19 IST 2015

Set Date and Time using –set option: You can set date and time of your system using -s or –

set option as shown below...

root@SDR:/home/sunil# date

Mon August 03 22:02:24 IST 2015

root@SDR:/home/sunil# date -s "Sun August 03 21:00:00 IST 2015"

Sun August 03 21:00:00 PDT 2015

root@SDR:/home/sunil# date

Sun August 03 21:00:00 IST 2015

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 6

exit - The exit command terminates a script, and can return a value to the

parent script.

echo- This command display string or given variable value.

root@SDR:/home/sunil# echo HI FRIENDS

HI FRIENDS

ls - The ls command lists files and directories within the current working

directory, and admins can determine when configuration files were last

edited.

sdr@SDR:~$ ls

1.txt access.c~ bar chmod.c~ Downloads file1 lnknewf newdir Pictures stat.c

Templates umask.c~ acc a.out chmod Desktop Music newf Public stat.c~

umask Videos access.c chmod.c Documents examples.desktop

ls –l -displays a long listing of the files.

sdr@SDR:~$ ls -l

total 60

-rw-rw-r-- 1 sdr sdr 22 Jul 29 12:48 1.txt

-rwxrwxr-x 1 sdr sdr 8716 Jul 30 12:54 acc

-rw-rw-r-- 1 sdr sdr 634 Jul 30 12:54 access.c

-rw-rw-r-- 1 sdr sdr 628 Jul 30 12:54 access.c~

-rwxrwxr-x 1 sdr sdr 8728 Jul 29 12:41 a.out

-rw------- 1 sdr sdr 4736 Aug 1 2014 apue.h

-rw-r--r-- 1 sdr sdr 0 Aug 4 11:49 bar

-rwxr-x--- 1 sdr sdr 8727 Aug 4 12:26 chmod

-rw------- 1 sdr sdr 460 Aug 4 12:25 chmod.c

In this long listing, the first character is’d’ or '-'. It distinguishes between file types. The entries

with a '-' (dash) are regular files, and ones with’d’ are directories. Next 9 characters are

permissions ('rwxr-xr-x' in first listing). The number following the permissions is link count.

Link count follows user and group owner. In above example, the file owner is ‘sdr ‘and group

owner ‘sdr’ as well. Next is the size of file. And then time stamp before the name of file (or

directory).

sdr@SDR:~$ ls -ls

total 60

4 -rw-rw-r-- 1 sdr sdr 22 Jul 29 12:48 1.txt

12 -rwxrwxr-x 1 sdr sdr 8716 Jul 30 12:54 acc

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 7

4 -rw-rw-r-- 1 sdr sdr 634 Jul 30 12:54 access.c

4 -rw-rw-r-- 1 sdr sdr 628 Jul 30 12:54 access.c~

12 -rwxrwxr-x 1 sdr sdr 8728 Jul 29 12:41 a.out

8 -rw------- 1 sdr sdr 4736 Aug 1 2014 apue.h

0 -rw-r--r-- 1 sdr sdr 0 Aug 4 11:49 bar

12 -rwxr-x--- 1 sdr sdr 8727 Aug 4 12:26 chmod

4 -rw------- 1 sdr sdr 460 Aug 4 12:25 chmod.c

sdr@SDR:/home/sunil$ ls -lsS

total 44

12 -rw-r--r-- 1 sunil sunil 8980 Aug 5 11:31 examples.desktop

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Desktop

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Documents

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Downloads

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Music

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Pictures

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Public

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Templates

4 drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Videos

The Linux ls command is used to list files and directories. While it has many options, I thought

I'd list the most common ls command uses I'm aware of.

The ls command options I use most of the time are -a ("show all") and -l ("long listing"). Put

together, like this:

sdr@SDR:~$ ls –al

This means "show a long listing of all files in the current directory".

sdr@SDR:~$ ls -la

total 84

drwxr-xr-x 20 sdr sdr 4096 Aug 6 14:25 .

drwxr-xr-x 4 root root 4096 Aug 5 11:31 ..

-rw-rw-r-- 1 sdr sdr 22 Jul 29 12:48 1.txt

-rwxrwxr-x 1 sdr sdr 8716 Jul 30 12:54 acc

-rw-rw-r-- 1 sdr sdr 634 Jul 30 12:54 access.c

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 8

-rw-rw-r-- 1 sdr sdr 628 Jul 30 12:54 access.c~

-rwxrwxr-x 1 sdr sdr 8728 Jul 29 12:41 a.out

-rw------- 1 sdr sdr 4736 Aug 1 2014 apue.h

-rw-r--r-- 1 sdr sdr 0 Aug 4 11:49 bar

-rw------- 1 sdr sdr 2542 Aug 6 13:31 .bash_history

-rw-r--r-- 1 sdr sdr 220 Jul 29 16:24 .bash_logout

-rw-r--r-- 1 sdr sdr 3637 Jul 29 16:24 .bashrc

drwx------ 15 sdr sdr 4096 Aug 5 11:27 .cache

-rwxr-x--- 1 sdr sdr 8727 Aug 4 12:26 chmod

-rw------- 1 sdr sdr 460 Aug 4 12:25 chmod.c

man - Short for "manual," man allows a user to format and display the user

manual built into Linux distributions, which documents commands and other

aspects of the system.

mkdir - Creates a new directory.

mkdir directoryname

root@SDR:/home/sunil# mkdir chandan

root@SDR:/home/sunil# ls -l

total 48

drwxr-xr-x 2 root root 4096 Aug 6 14:35 chandan

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Documents

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Downloads

-rw-r--r-- 1 sunil sunil 8980 Aug 5 11:31 examples.desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Music

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Pictures

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Public

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Templates

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Videos

mv - The mv command moves files and directories. Copies sourcefile to

targetfile then deletes the original sourcefile.

mv sourcefile targetfile

root@SDR:/home/sunil# mkdir Tempdir // this is an example of Make Directory

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 9

root@SDR:/home/sunil# ls -l

total 56

drwxr-xr-x 2 root root 4096 Aug 6 14:40 chandan

-rw-r--r-- 1 root root 40 Aug 6 14:38 chandan.c

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Documents

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Downloads

-rw-r--r-- 1 sunil sunil 8980 Aug 5 11:31 examples.desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Music

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Pictures

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Public

drwxr-xr-x 2 root root 4096 Aug 6 14:42 Tempdir

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Templates

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Videos

root@SDR:/home/sunil# mv chandan.c Tempdir // Move Directory

root@SDR:/home/sunil# ls Tempdir

chandan.c

passwd - Passwd updates a user's authentication tokens (changes the current

password).

pwd - The pwd (print working directory) command displays the name of the

current working directory. A basic Linux command.

root@SDR:/home/sunil# pwd

/home/sunil

ps – Display the running processes

root@SDR:/home/sunil# ps

PID TTY TIME CMD

2543 pts/0 00:00:00 su

2546 pts/0 00:00:00 bash

2629 pts/0 00:00:00 ps

rmdir -Deletes the specified directory, provided it is already empty.

rmdir directoryname

root@SDR:/home/sunil# rmdir chandan

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 10

rmdir: failed to remove ‘chandan’: Directory not empty

root@SDR:/home/sunil# cd chandan/

root@SDR:/home/sunil/chandan# ls

chandan.c

root@SDR:/home/sunil/chandan# rm chandan.c // Remove File

root@SDR:/home/sunil/chandan# ls

root@SDR:/home/sunil/chandan# cd ..

root@SDR:/home/sunil# rmdir chandan

root@SDR:/home/sunil# ls

Desktop Documents Downloads examples.desktop Music Pictures Public Tempdir

Templates Videos

RPM - Red Hat Package Manager (RPM) is a command-line driven program

capable of installing, uninstalling and managing software packages in Linux.

To install apache using rpm.

root@SDR:/home/sunil# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm

To upgrade apache using rpm.

root@SDR:/home/sunil# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm

To uninstall/remove apache using rpm.

root@SDR:/home/sunil# rpm -ev httpd

shutdown - Shutdown is a command that turns off the computer and can be

combined with variables such as -h for halt after shutdown or -r for reboot after

shutdown.

su - The su command makes it possible to log in under a different user name

from a running session. When using the command without specifying a user

name, you will be prompted for the root password. Specify a user name and the

corresponding password to use the environment of the respective user. The

password is not required from root, as root is authorized to assume the identity of

any user.

su [username]

sdr@SDR:/home/sunil$ su //SuperUser Login

Password:

root@SDR:/home/sunil# ls -l

total 44

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Desktop

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 11

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Documents

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Downloads

-rw-r--r-- 1 sunil sunil 8980 Aug 5 11:31 examples.desktop

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Music

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Pictures

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Public

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Templates

drwxr-xr-x 2 sunil sunil 4096 Aug 5 11:33 Videos

sudo - Sudo allows a system admin to give certain users the ability to run some

(or all) commands at the root level, and logs all commands and arguments.

tty – Print the file name of the terminal connected to standard input.

root@SDR:/home/sunil# tty

/dev/pts/0

whoami - whoami prints or writes the user/login name associated with the

current user ID to the standard output.

root@SDR:/home/sunil# who

sdr :0 2015-08-06 14:25 (:0)

sdr pts/0 2015-08-06 14:27 (:0)

root@SDR:/home/sunil# whoami

root

root@SDR:/home/sunil# who am i

sdr pts/0 2015-08-06 14:27 (:0)

wc-(word count) This command counts lines, words and letters of the input given

to it.

root@SDR:/home/sunil# wc /etc/passwd

35 57 1698 /etc/passwd

The /etc/passwd file has 35 lines, 57 words, and 1698 letters present in it.

yum- To install apache using yum.

root@SDR:/home/sunil# yum install httpd

To upgrade apache using yum.

root@SDR:/home/sunil# yum update httpd

8/3/2015 ASSIGNMENT NO: 1 Compiled By: - Chandan Prasad 12

To uninstall/remove apache using yum.

root@SDR:/home/sunil# yum remove httpd


Recommended