NEWS & UPDATES >> BCA BCSP064 Synopsis & Project Work Started for DEC 2017, IGNOU MCA MCSP060 Synopsis Work Started for DEC 2017, CONTACT 4 IGNOU Mini Project

What is Linux utilities and Basic Commands


What is Linux utilities and Basic Commands

The following is a list of commonly used commands which are organized under different categories for understanding and ease of use. Keys proceeded by a ^ character are CONTROL key combinations.

Terminal Control Characters

^h
backspace erase previously typed character
^u
erase entire line of input so far typed
^d
end-of-input for programs reading from terminal
^s
stop printing on terminal
^q
continues printing on terminal
^z
currently running job; restart with bg or fg
DEL, ^c
kill currently running program and allow clean-up before exiting
^\
emergency kill of currently running program with no chance of cleanup
Login and Authentication
Login
access computer; start interactive session
Logout
disconnect terminal session
Passwd
change local login password; you MUST set a non-trivial password


Information

date
show date and time

history
list of previously executed commands

pine
send or receive mail messages

msgs
display system messages

man
show on-line documentation by program name

info
on-line documentation for GNU programs

w, who
who is on the system and what are they doing

who am i  who is logged onto this terminal

top
show system status and top CPU-using processes

uptime
show one line summary of system status

finger
find out info about a user@system
File Management

cat
combine files

cp
copy files

ls
list files in a directory and their attributes

mv
change file name or directory location

rm
remove files

ln
create another link (name) to a file

chmod
set file permissions

des
encrypt a data file with a private key

find
find files that match specified criteria
Display Contents of Files



cat
copy file to display device

vi
screen editor for modifying text files

more
show text file on display terminal with paging control

head
show first few lines of a file(s)




tail                 show last few lines of a file; or reverse line order

grep              display lines that match a pattern

lpr                  send file to line printer

pr                   format file with page headers, multiple columns etc.

diff               compare two files and show differences

cmp             compare two binary files and report if different

od                  display binary file as equivalent octal/hex codes

file                 examine file(s) and tell you whether text, data, etc.

wc              count characters, words, and lines in a file


 Directories

cd                  change to new directory

mkdir          create new directory

rmdir            remove empty directory (remove files first)

mv                 change name of directory

pwd              show current directory

Devices

df                   summarize free space on disk device

du                  show disk space used by files or directories

Special Character Handling for C-shell

*                                match any characters in a file name

~user            shorthand for home directory of "user"

$name          substitute value of variable "name"

\                      turn off special meaning of character that follows

                                In pairs, quote string with special chars, except !

                            In pairs, quote string with special chars, except !, $

`                                  In pairs, substitute output from enclosed command

Controlling Program Execution for C-shell

&                            run job in background

DEL, ^c             kill job in foreground

^z                           suspend job in foreground

fg                           restart suspended job in foreground

bg                          run suspended job in background

;                              delimit commands on same line

( )                           group commands on same line

!                              re-run earlier command from history list

ps                           print process status

kill                         kill background job or previous process

nice                       run program at lower priority

at                            run program at a later time

crontab                run program at specified intervals

limit                      see or set resource limits for programs

alias                      create alias name for program (in .login)

sh, csh                 execute command file

Description of Commonly Used UNIX Commands

The description for the most commonly used UNIX commands is given below in an alphabetic order.

a)      cat

cat allows you to read multiple files and then print them out. You can combine files by using the > operator and append files by using >>.

Syntax: cat [argument] [specific file] Example:

cat abc.txt

If you want to append three files (abc.txt, def.txt, xyz.txt), give the command as,

cat abc.txt def.txt xyz.txt > all

b)     cd, chdir

cd (or chdir) stands for ―change directory‖. This command is the key command to move around your file structure.

Syntax: cd [name of directory you want to move to]

When changing directories, start with / and then type the complete file path, like

cd /vvs/abc/def

in this eg. You are moving from vvs directory to abc directory then move to def directory .

You can also move relative to the current directory by typing cd vvs/abc/def

To move relative to the parent directory of your current directory, use Cd ../vvs/abc/def

c ) chmod

chmod (which stands for ―change mode‖) changes who can access a particular file. A ―mode‖ is created by combining the various options from who, opcode, and permission.

Syntax: chmod [option] mode file

If you look at a list of files using the long list command ls –l, you'll see the permissions, owner, file size, modification time, and filename. The first column of the list shows who can read, write, and execute the files or directories, in other words, the permissions. It basically shows who has permission to do what to a given file or directory. r stands for ―read‖ and means that you're allowed to read the file or directory. w stands for ―write‖ and gives permission to edit or change the file as well as create, move, rename, or remove a directory. x stands for ―execute‖ which gives permission to run a file or search a directory. Every file or directory has four sets of rwx permissions. The first set represents the user (u), the second set represents the group (g), the third set represents other (o), and the fourth set represents all

(a). The column will look like this: rwxrwxrwx

Each set of rwx represents user, group, and other respectively. Only the owner of a file or a privileged user may change the permissions on a file. There are two ways to change permissions on a file or directory, either numerically or by using lettered commands. Both ways use the command chmod. To add permissions to a file, you use +, to remove permissions you use-.

For example, take a file:

-rw-r--r-- 1 yash mony 476 Apr 14 17:13 vvs.txt

To allow a group (mony, in this case) ―write‖ access, you would type:

chmod g+w vvs.txt

If you wanted to remove ―read‖ ability from ―other‖ you would type:

chmod o-r vvs.txt

It is also possible to specify permissions using a three-digit sequence. This is a more efficient way to change permissions (or at least it requires less typing), so use this method if it doesn't confuse you. Each type of permission is given an octal value. Read is given the value of 4, write is given the value of 2, and execute is given the value of 1. These values are added together for each user category. The permissions are changed by using a three-digit sequence with the first digit representing owner permission, the second digit representing group permission, and the third digit representing other permission. For example, if you wanted to make vvs.txt readable, writable, and executable for the user, readable and writable for the group, and readable for other, you would type: chmod 764 vvs.txt

The first digit means readable and writable for the user (4+2+1), the second digit means readable and writable for the group (4+2+0), and the third digit means readable for other (4+0+0). if you want to change the permissions on a directory tree use the -R option. chmod –R will recursively change the permissions of directories and their contents.

d)     cp

The cp command copies files or directories from one place to another. You can copy a set of files to another file, or copy one or more files under the same name in a directory. If the destination of the file you want to copy is an existing file, then the existing file is overwritten. If the destination is an existing directory, then the file is copied into that directory.
Syntax: cp [options] file1 file2 If you want to copy the file favourites.html into the directory called laksh, you give

the command as:

cp favourites.html /vvs/laksh/

A handy option to use with cp is -r. This recursively copies a particular directory and all of its contents to the specified directory, so you won't have to copy one file at a time.

e)      date

The date command can be used to display the date or to set a date. In unix the term date includes the time as well.

Syntax: date [option] [+format]

date [options] [string]

The first structure shows how date can be used to display the current date. A certain format can be specified in which the date should be displayed. Check the Unix manual for specific formats and options. The second structure allows you to set the date by supplying a numeric string. Only privileged users will be able to use this second command structure.

f)    diff

diff displays the lines that differ between two given files.

Syntax: diff [options] [directory options] file1 file2

diff can be an extremely valuable tool for both checking errors and building new pages. If you run a diff between two files, you'll be shown what differences the files have line by line. The lines referring to file1 are marked with the < symbol. The lines referring to file2 are marked by the > symbol. If the file is a directory, diff will list .the file in the directory that has the same name as file2. If both of the files are directories, diff will list all the lines differing between all files that have the same name. If you have a file that is not working properly, it can be a great help to check it against a similar file that is working. It will often quickly alert you to a line of code that's missing.

A handy option to use if you want to generally compare two files without noting the complex differences between them is the -h option (h stands for half-hearted). Using -i as an option will ignore differences in uppercase and lowercase characters between files, and -b will ignore repeating blanks and line breaks.

g)   exit

The exit command allows you to terminate a process that is currently occurring. For example, if you wanted to leave a remote host that you were logged onto (see rlogin also), you should type exit. This would return you to your home host.

h)      find

find searches through directory trees beginning with each pathname and finds the files that match the specified condition(s). You must specify at least one pathname and one condition.

Syntax: find pathname(s) condition(s)

There are several handy conditions you can use to find exactly what you want. The -name condition will find files whose names match a specified pattern. The structure for the name condition is: find pathname -name pattern

The condition -print will print the matching files to the pathname specified. - printcan also be used in conjunction with other conditions to print the output. If you wanted to find all the files named favorites.html in the directory Ram, then

you'd do this:

find /Ram -name favorites.html –print

This looks through the directory Ram and finds all the files in that directory that contain favorites.html, then prints them to the screen. Your output would look like this:

/Ram/sixteen_candles/favorites.html

/Ram/favorites.html

/Ram/breakfast_club/favorites.html

All meta-characters (!, *, ., etc.) used with -name should be escaped (place a \ before the character) or quoted. Meta-characters come in handy when you are searching for a pattern and only know part of the pattern or need to find several similar patterns.

For example, if you are searching for a file that contains the word ―favorite‖, then use the meta-character * to represent matching zero or more of the preceding characters.

This will show you all files which contain favorite.

find /Ram  -name '*favorite*' -print This looks through the directory Ram and finds all the files in that directory that contain the word ―favorite‖. The output would look like this:

/Ram/sixteen_candles/favorites.html

/Ram/favorites.html

/Ram/least_favorites.html

/Ram/breakfast_club/favorites.html

/Ram/favorite_line.html

The -user condition finds files belonging to a particular user ID or name.

i) grep

The grep command searches a file or files for lines that match a provided regular expression (―grep‖ comes from a command meaning to globally search for a regular expression and then print the found matches).

Syntax: grep [options] regular expression [files]

To exit this command, type 0 if lines have matched, 1 if no lines match, and 2 for errors. This is very useful if you need to match things in several files. If you wanted to find out which files in our vvs directory contained the word

―bca‖ you could use grep to search the directory and match those files with that word. All that you have to do is give the command as shown:

grep ‗bca' /vvs/*

The * used in this example is called a meta-character, and it represents matching zero or more of the preceding characters. In this example, it is used to mean ―all files and directories in this directory‖. So, grep will search all the files and directories in vvsand tell you which files contain ―bca‖.

j)     head

Displays the first ten lines of a file, unless otherwise stated.             Syntax: head

[-n] [files]

For example, the following command will display the first 15 lines of favourites.html.

head -15 favourites.html

k)     kill

kill ends the execution of one or more process ID's. In order to do this you must own the process or be designated a privileged user. To find the process ID of a certain job give the command ps.

Syntax: kill [options] PIDs

There are different levels of intensity to the kill command, and these can be represented either numerically or symbolically. kill -1 or HUP makes a request to the server to terminate the process, while kill -9 or kill KILL forces a process to terminate absolutely. Most politely, UNIX users will attempt to kill a process using-1 first before forcing a process to die.

l)              ls

ls will list all the files in the current directory. If one or more files are given, ls will display the files contained within ―name‖ or list all the files with the same name as ―name‖. The files can be displayed in a variety of formats using various options.

Syntax: ls [options] [names]

ls is a command you'll end up using all the time. It simply stands for list. If you are in a directory and you want to know what files and directories are inside that directory, type ls. Sometimes the list of files is very long and it flies past your screen so quickly .You miss the file you want. To overcome this problem give the command as shown below:

ls | more

The character | (called pipe) is typed by using shift and the \ key. | more will show as many files as will fit on your screen, and then display a highlighted

―more‖ at the bottom. If you want to see the next screen, hit enter (for moving one line at a time) or the spacebar (to move a screen at a time). | more can be used anytime you wish to view the output of a command in this way. A useful option to use with ls command is -l. This will list the files and directories in a long format. This means it will display the permissions (see chmod), owners, group, size, date and time the file was last modified, and the filename.

drwxrwxr-x  vvs   staff 512 Apr 5 09:34 sridhar.txt

-rwx-rw-r-- vvs    staff 4233 Apr 1 10:20 resume.txt

-rwx-r--r-- vvs    staff 4122 Apr 1 12:01 favourites.html

There are several other options that can be used to modify the ls command, and many of these options can be combined. -a will list all files in a directory, including those files normally hidden. -F will flag filenames by putting / on directories, @ on symbolic links, and * on executable files.

m)        man

The man command can be used to view information in the online Unix manual.


Syntax: man [options] [[section] subjects]

man searches for information about a file, command, or directory and then displays it on your screen. Each command is a subject in the manual. If no subject is specified, you must give either a keyword or a file. You can also search for commands that serve a similar purpose. For example, if you want more information about the chmod command, you should type:

man chmod

A screen will then appear with information about chmod. Type q to quit.

n) mkdir

mkdir creates a new directory.

Syntax: mkdir [options] directory name

For example, to create a directory called parkhyath in the present working directory, give the command as,

mkdir prakhyath

o) more

more displays the contents of files on your screen.

Syntax: more [options] [files]

To have the next line displayed, hit the return key, otherwise press the spacebar to bring up the next screen. Press h for assistance with other commands, n to move to the next file, or q to quit.

p) less

less is similar to more in that it displays the contents of files on your screen. Unlike more, less allows backward and forward movement within the file. It does not read the whole file before displaying its contents, so with large files less displays faster than more. Press h for assistance with other commands or q to quit.

Syntax: less [options] [files]

q) mv

mv moves files and directories. It can also be used to rename files or directories.

Syntax: mv [options] source target

If you wanted to rename vvs.txt to vsv.txt, you should give the command as:


   
mv vvs.txt vsv.txt

After executing this command, vvs.txt would no longer exist, but a file with name

vsv.txt would now exist with the same contents.

r)    passwd

The passwd command creates or changes a user's password. Only the owner of the password or a privileged user can make these changes.

Syntax: passwd [options] files

s) pwd

pwd prints the pathname of the current directory. If you wanted to know the path of the current directory you were in you give the command as pwd. You will get the complete path.

t) rm

rm removes or deletes a link to a file from a directory. If a file has more than one link then removing a link does not delete the file. But when the last link to a file is removed, the file gets deleted.

A link is a name of a file.  In unix a file can have many names.

Syntax: rm [options] files

In order to remove a file, you must have write permission to the directory where the file is located. While removing a which does't have write permission on, a prompt will come up asking you whether or not you wish to override the write protection.

The -r option is very handy and very dangerous. -r can be used to remove a directory and all its contents. If you use the -i option, you can possibly catch some disastrous mistakes because it'll ask you to confirm whether you really want to remove a file before going ahead and doing it.

u) rmdir

rmdir allows you to remove or delete directories but not their contents. A directory must be empty in order to remove it using this command.

Syntax: rmdir [options] directories

If you wish to remove a directory and all its contents, you should use rm -r.

Check Your Progress 

1.    Practice to install Fedora 10 in your pc.

 Overview of UNIX/ LINUX Operating System
 Even after thirty years of its creation UNIX is still regarded as one of the most
versatile, flexible and powerful operating systems in the computer world. It was
created at Bell Labs in 1970 written in the C programming language, which was
developed at the same time. It supports large numbers of simultaneous users, runs with few alterations on many hardware platforms (provides some platform independence) and of course it was and is a simple, elegant, and easy to use (at least compared to its predecessors) Linux is a relatively new UNIX flavor derived from the work of Linus Torvalds, who was interested to develop a UNIX for academic use. Linux is one of the many versions of the UNIX operating system. Working on Linux means working on one of the flavors of UNIX. The main advantage that Linux is absolutely free, you need not spend even the cost CD it can be entirety free downloadable from the Internet. (No registration fees, no costs per user, free updates, and freely available Operating System and Networking Lab source code). It is portable (means can be configured on any processor like Intel, Solaris, etc), dual-bootable, fast, reliable, secure and versatile. These properties make it popular among the System Administrators. While working on it you may realize many more important features and advantages of Linux. Most of the exercises are command line based but similar exercises you can try on your GUI based Linux.

Fedora 10, also known as Cambridge, was released on November 25th, 2008, and it brings faster boot experience with Plymouth, better printing, better webcam support, improved wireless network connection sharing, better software maintenance and update. We will learn how to install the DVD edition of the Fedora 10 operating system on your PC. Why the DVD edition? Because we believe it offers most of the applications you'll need. However, this guide will make things very simple for you, but if you get stuck somewhere in the middle of the installation and you need help, do not hesitate to use our commenting system at the end of the article.


2.    First try to execute the following commands on your               operating system and write down the results and use of         each  command.

  man ( find manual help)

  cd

  ls, ls -a  (try to find out other options of ls using man)

  cd .

  pwd

  cd ..

  ls -al

  ls -al | more

  cat passwd 22

  cd –

  chmod

We hope you will stop here and you will keep digging more and more commands but do it after the session.


               Try it your self

Check Your Progress 


1          Try to explore the file system, write what is there in /bin, /usr/bin, /sbin, /tmp and /boot. Find and list the devices that are available in your system.

2          Make your own subdirectories called rc1 and rc2 in your home directory, mca? Ok, now delete the subdirectory called rc2 .

3          Create a file called ignou.txt that contains the words "hello I am student of IGNOU". Now copy this file and paste to other director. Copied? Can you move the file also from one directory to another?

4          In the previous question you have a file ignou.txt; change its permission to rwxrwxr-x. You can try different possibilities to changes in its permissions. One possibility may be rwxr-xr-x permissions. Find out what are the different commands available that can be used to change the permissions of a file/files.

5          Display the names of all files in the home directory using find .Can you display the names of all files in the home directory that are bigger than 500KB.

6          Display a sorted list of all files in the home directory that contain the Word ignou inside them. Hint: Use find and grep and sort. Can you use locate to find all filenames that contain the word ignou?

7          Use egrep to try to find out which lines in an ignou.txt file are satisfied by the regular expression given: (^ [0-9]{1,5}[a-zA-z ]+$)|none and check the result with different combinations of lines.

8          Change your password and write down the restrictions for given password.


         Try exercise 1-8 yourself.


No comments:

Post a Comment