21-05-2014, 04:43 PM
Basic Linux Commands
1370327418-basiclinuxcommands.pdf (Size: 227.87 KB / Downloads: 32)
Calender
◮ cal: Command to see calender for any specific month or a
complete year
◮ cal [ [month] year]
$ cal april 2009
April 2009
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
date
◮ date: displays the current date
$ date
Tue Apr 21 21:33:49 IST 2009
kuteer$ date +"%D %H:%M:%S"
04/21/09 21:35:02
◮ Options:
◮ d - The da of the month (1-31)
◮ y - The last two digits of the year
◮ H,M,S - Hour Minute and second respectively
◮ D - the date in mm/dd/yy
◮ For more information see man date
echo and printf
◮ echo: Print message on the terminal
◮ usage: echo “<message>”
$ echo "Welcome to the workshop"
Welcome to the workshop
◮ printf: Print the formatted message on the terminal
◮ Syntax of printf is same as C language printf statement
◮ usage: printf “<formatted message”
$ printf "the amount is %d\n" 100
the amount is 100
Calculator
◮ bc: A text based calculator
$ bc
2*10+20-9+4/2 [Input]
33 [Output]
[ctrl+d] [Quit]
◮ xcalc is graphical based calculator
script: Record your session
◮ script command records your session and stores it in a file
$ script
Script started, file is typescript
$ echo "this is a sample script"
this is a sample script
$ [ctrl+d]
Script done, file is typescript
◮ By default if you dont specify any file name the contents
will be stored in file name typescipt
$ cat typescript
Script started on Tuesday 21 April 2009 10:07:00
$ echo "this is a sample script"
this is a sample script
$
Script done on Tuesday 21 April 2009 10:07:34 PM
passwd: Changing your password
◮ passwd command allows you to change your password
kuteer:˜/workshop$ passwd
Changing password for srihari.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
WHO: Who are the users?
◮ who command tells you the users currently logged on to
the system
kuteer:˜$ who
srihari pts/0 2009-04-15 11:58 (:10.129.41.3)
nithin pts/1 2009-04-15 16:09 (:10.129.20.5)
avadhut pts/2 2009-04-13 14:39 (:10.129.45.20)
anil pts/3 2009-04-13 16:32 (:10.129.23.45)
man - The reference Manual
◮ man displays the documentation for a command
◮ usage: man <command name>
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the
none of -cftuvSUX nor --sort.
Linux file system
◮ Standard directory structure
◮ / - the topmost
◮ /dev - all the devices are accessible as files
◮ /var - “variable” data such as mails, log files, databases
◮ /usr - almost all the packages installed
◮ /etc - configuration files
◮ /home - home directories for all the users
◮ /root - home directory of the privileged user root
◮ /mnt - used to mount other directories/partitions.
File Attributes
◮ To see the file attributes type ls -l on your terminal
kuteer:˜$ ls -l
$<$permissions$>$ $<$owner$>$ $<$group$>$
drwxr-xr-x 2 srihari srihari 144 2009-04-02
-rw-r--r-- 1 srihari srihari 1548 2009-03-29
drwxr-xr-x 2 srihari srihari 48 2009-03-19
-rw-r--r-- 1 srihari srihari 3570 2009-03-23
◮ The file Testing.java has the following permissions -rw-r–r–
◮ It has 10 characters, first character is d if its directory and -
if its file.
◮ Next 9 characters are divided into three groups with a set
of 3 characters each
Changing the File attributes
◮ chmod Changing the permissions of the file
kuteer:˜$ chmod o+x Testing.java
kuteer:˜$ ls -l Testing.java
-rw-r--r-x 1 srihari srihari 3570 2009-03-23 10:52
kuteer:˜$ chmod 655 Testing.java
kuteer:˜$ ls -l Testing.java
-rw-r-xr-x 1 srihari srihari 3570 2009-03-23 10:
Changing ownership
◮ chown command is used for changing the ownership and
also group of the file
kuteer:˜$ chown guest Testing.java
kuteer:˜$ ls -l Testing.java
-rw-r-xr-x 1 geust srihari 3570 2009-03-23 10:52
kuteer:˜$ chown guest:guest Testing.java
kuteer:˜$ ls -l Testing.java
-rw-r-xr-x 1 geust guest 3570 2009-03-23 10:52 T
File system commands
◮ Deleting Files - rm
◮ Copying and moving files - cp, mv
◮ Creating directories - mkdir
◮ Deleting Empty Directory - rmdir
$ rm Testing.java
//deletes the file Testing.java
$ cp Testing.java Copy.java
//creates the copy of Testing.java
$ mv Testing.java Test.java
//renames the file Testing.java to Test.java
$ mkdir newDir
//Creates directory newDir
$ rmdir newDir
//deletes directory newDir newDir should be empt
cat : Concatenate Files
◮ cat command is used to display the contents of a small file
on terminal
◮ usage: cat <file name>
$ cat sample3.txt
Unix (officially trademarked as UNIX, sometimes
..
◮ cat when supplied with more than one file will concatenate
the files without any header information
$ cat sample3.txt sample4.txt
/*contents of sameple3.txt*/
/*Followed by contents of sample4.txt without an
tac : concatenate files in reverse
◮ tac command is used to display the contents of a small file
in reverse order on terminal
◮ usage: tac <file name>
$ tac sample3.txt
/*displays sample3.txt in reverse order*/
◮ tac when supplied with more than one file will concatenate
the reverse contents of files without any header information
$ tac sample3.txt sample4.txt
/*print sample3.txt in reverse order*/
/*print sample4.txt in reverse order without any
more, less : paging output
◮ more and less commands are used to view large files one
page at a time
◮ usage: more <file name>
◮ usage: less <file name>
$ more sample1.txt
/*sample1.txt will be displayed one page
at a time */
$ less sample1.txt
/*sample1.txt will be displayed one page
at a time */
◮ less is the standard pager for linux and in general less is
more powerful than more
wc : statistic of file
◮ wc command is used to count lines, words and characters,
depending on the option used.
◮ usage: wc [options] [file name]
$ wc sample1.txt
65 2776 17333 sample1.txt
◮ Which means sample1.txt file has 65 lines, 2776 words,
and 17333 characters
◮ you can just print number of lines, number of words or
number of charcters by using following options:
◮ -l : Number of lines
◮ -w : Number of words
◮ -c : Number of characters
wc : statistic of file
◮ wc command is used to count lines, words and characters,
depending on the option used.
◮ usage: wc [options] [file name]
$ wc sample1.txt
65 2776 17333 sample1.txt
◮ Which means sample1.txt file has 65 lines, 2776 words,
and 17333 characters
◮ you can just print number of lines, number of words or
number of charcters by using following options:
◮ -l : Number of lines
◮ -w : Number of words
◮ -c : Number of characters
grep : searching for a pattern
◮ grep scans its input for a pattern, and can display the
selected pattern, the line numbers or the filename where
the pattern occurs.
◮ usage: grep options pattern filename(s)