1.shell Commands
1.shell Commands
23.2.21
AIM: To study and learn about basic, directory and file related Linux commands.
NAME
--------
date - print or set the system date and time
Output
----------
Wed Sep 13 13:24:54 IST 2006
**************************************************************************************
NAME
--------
cal - displays a calendar
Example 2
--------------
@linux ~]$ cal -3
Example 3
-------------
[@linux ~]$ cal 09 2005
**************************************************************************************
NAME
---------
pwd - print name of current/working directory
Example
-------
[@linux ~]$ pwd
Output
------
/home/itrmd/sri
**************************************************************************************
NAME
---------
man - format and display the on-line manual pages
SYNTAX
--------------
$ man
$ man <command name>
Example 1
-------------
[@linux ~]$ man
Output 1
-----------
What manual page do you want?
Example 2
-------------
[@linux ~]$ man date
**************************************************************************************
NAME
--------
bc - An arbitrary precision calculator language
Example
-------
[@linux ~]$ bc
5+8
Output
------
13
NAME
---------
who - shows who is logged on
Output 1
--------
[@linux ~]$ who
SYNTAX
--------
$ who am i
output
------
-sh-3.00$ who am i
juliana pts/8 Sep 20 13:16 (10.2.3.18)
************************************************************************************
NAME
---------
echo - display a line of text
SYNTAX
1) $ echo [STRING]
2) $ echo "string"
example 1
---------
[@linux ~]$ echo "god"
output 1
--------
god
Example 2
---------
[@linux ~]$ echo tiger
output 2
--------
tiger
<<P.T.DOWN>>
2.DIRECTORY RELATED COMMANDS
NAME
--------
ls - list directory contents
SYNTAX
--------
1) ls
2) ls [OPTION]... [FILENAME]...
Example
-------
[@linux ~]$ ls -l a
Output
------
-rw-rw-r-- 1 sri sri 39 Jul 28 12:36 a
Example
-------
[@linux ~]$ ls
Output
------
a a.out ee.c fiio.c lsprg.c new.c sem12.c sss.c
*******************************************************************************
NAME
---------
mkdir - make directory
SYNTAX
$ mkdir DIRECTORY NAME
example
-------
[@linux ~]$ mkdir cool
[@linux ~]$ ls
cool
**********************************************************************************
NAME
---------
cd - Change Directory
SYNTAX
--------
$ Cd [dirname]
output
-------
[@linux ~]$ cd cool
[@linux cool]$
**********************************************************************************
Name
--------
cd .. -to exit form current directory
SYNTAX
--------
$ cd ..
output
------
[@linux cool]$ cd ..
[@linux ~]$
***********************************************************************************
NAME
--------
rmdir - remove files or directories
SYNTAX
--------
$ rmdir [dirctory name]
output
------
[@linux ~]$ rmdir cool
[@linux ~]$ ls
a a.out f1.c gg l sss.c
************************************************************************************
<<P.T.DOWN>>
3.FILE RELATED COMMANDS
NAME
---------
cat > - To create a file
SYNTAX
$ cat > [FILENAME]
Example
--------
[@linux ~]$ cat > hhh
sat
cat
mat
output
------
[@linux ~]$ ls
a a.out cool f1.c fiio.c hat hhh
**************************************************************************************
NAME
---------
cat - displays files on the standard output
SYNTAX
$ cat [FILENAME]
Example
--------
[@linux ~]$ cat hhh
output
------
hat
cat
mat
**************************************************************************************
NAME
--------
cat >> - To concatenate a file
SYNTAX
$ cat >> [FILENAME]
Example
--------
[@linux ~]$ cat >> hhh
bat
output
------
[@linux ~]$ cat hhh
hat
cat
mat
bat
**************************************************************************************
NAME
---------
grep - print lines matching a pattern
SYNTAX
--------
grep "PATTERN" [FILEname]
REF:
----
[@linux ~]$ cat hhh
hat
cat
mat
bat
Example
-------
[@linux ~]$ grep "b" hhh
output
-----
bat
**************************************************************************************
NAME
--------
egrep - print lines matching multiple pattern
SYNTAX
--------
egrep "PATTERN 1|pattern 2" [FILEname]
REF:
---
[@linux ~]$ cat hhh
hat
cat
sat
bat
Example
-------
[@linux ~]$ egrep "b|c" hhh
output:
------
bat
cat
**************************************************************************************
NAME
---------
wc - print the number of lines, words, and bytes in files
SYNTAX
--------
wc [OPTION] [FILENAME]
REF:
---
[@linux ~]$ cat hhh
hat
cat
mat
bat
Example 1:
---------
[@linux ~]$ wc hhh
output
------
3 4 17 hat
Example 2
---------
[@linux ~]$ wc -l hhh
output
------
3 hat
Example 3
---------
[@linux ~]$ wc -c hhh
output
------
17 hat
Example 4
---------
[@linux ~]$ wc -w hhh
output
------
4 hat
**************************************************************************************
NAME
----
chmod - change file access permissions
SYNTAX
--------
chmod <category> + <permision> <filename>
category:
_________
u-single users
g-group of users
o-other users
permission:
___________
r-readable
w-writable
x-executable
Example 1
---------
[@linux ~]$ ls -l sss
Access: (0664/-rw-rw-r--)
[@linux ~]$ chmod u+x sss
output 1
--------
[@linux ~]$ chmod u+x sss
Access: (0764/-rwxrw-r--)
**************************************************************************************
NAME
---------
find - search/locate for files in a directory hierarchy
SYNTAX
--------
find [filename]
*******************************************************************************
NAME
--------
join - join lines of two files on a common field
SYNTAX
--------
join FILE1 FILE2
REF:
---
[@linux ~]$ cat >fi
e
r
t
[@linux ~]$ cat >fj
g
r
t
Example:
--------
[@linux ~]$ join fi fj
Output
------
r
t
************************************************************************************
NAME
---------
cp - copy files and directories
SYNTAX
--------
cp SOURCEFILE DESTINATIONFILE
**************************************************************************************
NAME
---------
mv - move (rename) files
SYNTAX
--------
mv SOURCEfile DESTINATIONfile
**************************************************************************************
NAME
---------
paste - merge lines of files
SYNTAX
--------
paste filename1 filename2
**************************************************************************************
NAME
---------
cut - remove sections from each line of files
SYNTAX
--------
cut [OPTION] [FILENAME]
REF:
----
[@linux ~]$ cat hhh
hat
cat
mat
bat
Example 1
-------
[@linux ~]$ cut -c1 hhh
output 1
--------
h
c
m
b
**************************************************************************************
NAME
---------
tail - output the last part of files
SYNTAX
tail [OPTION] [FILENAME]
REF:
----
[@linux ~]$ cat hhh
hat
cat
mat
bat
Example
-------
[@linux ~]$ tail -1 hhh
output
-----
bat
**************************************************************************************
NAME
---------
head - output the first part of files
SYNTAX
--------
head [OPTION] [FILENAME]
REF:
----
[@linux ~]$ cat hhh
hat
cat
mat
bat
Example
-------
[@linux ~]$ head -1 hhh
output
------
hat
**************************************************************************************
NAME
---------
sort - sort lines of text files
SYNTAX
--------
sort [OPTION] [FILEnNAME]
REF:
----
[@linux ~]$ cat hhh
hat
cat
mat
bat
EXample
-------
[@linux ~]$ sort hhh
Output
-----
bat
cat
mat
hat
**************************************************************************************
NAME
---------
uniq - remove duplicate lines from a sorted file
SYNTAX
--------
uniq [OPTION]... [INPUT [OUTPUT]]
REF:
---
[@linux ~]$ cat hei
cat
sat
sat
rat
bat
bat
Example
-------
[@linux ~]$ uniq hei
cat
sat
rat
bat
**************************************************************************************
NAME
---------
tee - read from standard input and write to standard output and/or file(s)
SYNTAX
--------
command [option] [filename] | tee [FILE]
REF:
---
[@linux ~]$ cat hei
cat
sat
sat
rat
bat
bat
Example
-------
[@linux ~]$ sort hei | tee bbb
output
------
[@linux ~]$cat bbb
bat
bat
cat
rat
sat
sat
**************************************************************************************
Name
---------
Sed
Sed is a Stream Editor used for modifying the files in linux. Whenever you want to make
changes to the file automatically, sed command is used