0% found this document useful (0 votes)
11 views

Basic Unix Commands

The document describes various Linux commands like mv, rm, mkdir, cd, pwd, w, last, bc, sed and their usage through examples. Commands like mv are used to move files, rm to remove files, mkdir and cd to create and navigate directories, pwd to print working directory, w to display user login details, last to view login history, bc for calculations and sed for searching and replacing text.

Uploaded by

hyndavi2210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Basic Unix Commands

The document describes various Linux commands like mv, rm, mkdir, cd, pwd, w, last, bc, sed and their usage through examples. Commands like mv are used to move files, rm to remove files, mkdir and cd to create and navigate directories, pwd to print working directory, w to display user login details, last to view login history, bc for calculations and sed for searching and replacing text.

Uploaded by

hyndavi2210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

1.

Command : mv
Description: This command helps to move the content in the file permanently to another file.
Example :

c15137@localhost:~$ cat >sample.txt


Iam Nivetha
My favourite color is black
^Z
[4]+ Stopped cat > sample.txt
c15137@localhost:~$ cat sample.txt
Iam Nivetha
My favourite color is black
c15137@localhost:~$ mv sample.txt samplefile.txt
c15137@localhost:~$ cat samplefile.txt
Iam Nivetha
My favourite color is black

2. Command : rm
Description : This command is used to remove the file.
Example :

c15137@localhost:~$ rm samplefile.txt
c15137@localhost:~$ cat samplefile.txt
cat: samplefile.txt: No such file or directory
c15137@localhost:~$

3. Command : mkdir,cd
Description : mkdir command is used to create a directory and add helps to add file in the
directory.cd command is used to change from current directory to the directory we need to navigate.
Example :

c15137@localhost:~$ mkdir sample


c15137@localhost:~$ cd sample
c15137@localhost:~/sample$ cd /
c15137@localhost:/$

4. Command :pwd
Description : This command helps to view the current Directory we are working with.
Example :

c15137@localhost:~$ pwd
/home/c15137
c15137@localhost:~$
5. (i) Command : w
Description : This command displays the login details for all the users.
Example :

c15137@localhost:~$ w
11:31:01 up 1:48, 1 user, load average: 0.24, 0.24, 0.31
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
c15137 pts/2 :0 09:43 0.00s 0.32s 0.00s w

(ii) Command : w -h
Description : This command is used to remove the header part.
Example :

c15137@localhost:~$ w -h
c15137 pts/2 :0 09:43 0.00s 0.32s 0.00s w -h

(iii) Command : w -u
Description : This command neglects userid and display the loggin details.
Example :

c15137@localhost:~$ w -u
11:31:22 up 1:49, 1 user, load average: 0.17, 0.22, 0.31
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
c15137 pts/2 :0 09:43 0.00s 0.32s 0.00s w -u

(iv)Command : w -s
Description : This command provides the short listing about the login details.
Example :

c15137@localhost:~$ w -s
11:31:37 up 1:49, 1 user, load average: 0.20, 0.23, 0.31
USER TTY FROM IDLE WHAT
c15137 pts/2 :0 0.00s w -s

(v) Command : w -l
Description: This command provides the long listing about the user who have logged in
Example :

' c15137@localhost:~$ w -l
11:50:30 up 2:08, 2 users, load average: 0.22, 0.35, 0.35
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
c15137 pts/2 :0 09:43 0.00s 0.33s 0.00s w -l
c15137 pts/3 :0 11:47 3:08 0.11s 0.11s bash
c15137@localhost:~$

(vi) Command : w -V
Description : This command provides the version details.
Example :
c15137@localhost:~$ w -V
procps version 3.2.8
c15137@localhost:~$
6. (i) Command : last -R
Description : Suppress and the display of the host name field of the user who have logged in
atlast.
Example :

c15137@localhost:~$ last -R
c15137 pts/3 Tue Feb 4 11:47 still logged in
wtmp begins Tue Feb 4 11:47:22 2014

(ii) Command : last -a


Description : Displays the logged in details of the last user along with the host name.
Example :

c15137@localhost:~$ last -a
c15137 pts/3 Tue Feb 4 11:47 still logged in :0
wtmp begins Tue Feb 4 11:47:22 2014

7.Command : bc
Description : This command act as a calculator to perform Airthmetic operations.
Example :

c15137@localhost:~$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10+20
30
3*4
12
^Z
[35]+ Stopped bc
c15137@localhost:~$

8. Command : sed
Description : This command is used to replace one content by another content.
Example :

c15137@localhost:~$ cat samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
c15137@localhost:~$
(i) To Replace Unix as linux

c15137@localhost:~$ sed 's/Unix/linux/' samplefile.txt


linux is the best open source.Unix has sed command to replace.
linux is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
c15137@localhost:~$

(ii) To replace the 2nd occurance of Unix to linux

c15137@localhost:~$ sed 's/Unix/linux/2' samplefile.txt


Unix is the best open source.linux has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
c15137@localhost:~$

(iii) To replace all the Unix as linux

c15137@localhost:~$ sed 's/Unix/linux/g' samplefile.txt


linux is the best open source.linux has sed command to replace.
linux is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
c15137@localhost:~$

(iv) To replace all the 2nd occurance of Unix to linux

c15137@localhost:~$ sed 's/Unix/linux/2g' samplefile.txt


Unix is the best open source.linux has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
c15137@localhost:~$
(v) To show any word seperately or in highlighted manner

c15137@localhost:~$ sed 's/unix/{&}/' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
{unix} is the best open source.unix is the best open source.
{unix} is the best open source.unix is the best open source.
http:\\www.google.com

(vi) To show all the occurence of the same word seperately

c15137@localhost:~$ sed 's/unix/{&}/g' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
{unix} is the best open source.{unix} is the best open source.
{unix} is the best open source.{unix} is the best open source.
http:\\www.google.com

c15137@localhost:~$ cat >>samplefile.txt


unixunix is the best open source
^Z
[49]+ Stopped cat >> samplefile.txt
c15137@localhost:~$

(vii) To dublicate any word and enclose inside{}(we can use any symbols instead of {} eg.(),*..)

c15137@localhost:~$ sed 's/unix/{&&}/g' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
{unixunix} is the best open source.{unixunix} is the best open source.
{unixunix} is the best open source.{unixunix} is the best open source.
http:\\www.google.com
{unixunix}{unixunix} is the best open source

(viii) To make a duplicate copy of the replaced lines

c15137@localhost:~$ sed 's/unix/linux/p' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
linux is the best open source.unix is the best open source.
linux is the best open source.unix is the best open source.
linux is the best open source.unix is the best open source.
linux is the best open source.unix is the best open source.
http:\\www.google.com
linuxunix is the best open source
linuxunix is the best open source
It is an operating system.
c15137@localhost:
(ix) To suppress the duplicate copies and display the lines that have been replaced.

c15137@localhost:~$ sed -n 's/unix/linux/p' samplefile.txt


linux is the best open source.unix is the best open source.
linux is the best open source.unix is the best open source.
linuxunix is the best open source
c15137@localhost:~$

(x) To use multiple sed commands using |

c15137@localhost:~$ sed 's/Unix/linux/p' samplefile.txt |sed 's/source/system/'


linux is the best open system.Unix has sed command to replace.
linux is the best open system.Unix has sed command to replace.
linux is used by large number of users.
linux is used by large number of users.
unix is the best open system.unix is the best open source.
unix is the best open system.unix is the best open source.
http:\\www.google.com
unixunix is the best open system
It is an operating system.

(xi) To use multiple sed commands using -e

c15137@localhost:~$ sed -e 's/Unix/linux/p' -e 's/source/system/' samplefile.txt


linux is the best open source.Unix has sed command to replace.
linux is the best open system.Unix has sed command to replace.
linux is used by large number of users.
linux is used by large number of users.
unix is the best open system.unix is the best open source.
unix is the best open system.unix is the best open source.
http:\\www.google.com
unixunix is the best open system
It is an operating system.

(xii) Usage of multiple sed command ie.1st Unix is replaced as linux and the source is replaced as
system.

c15137@localhost:~$ sed -e '1 s/Unix/linux/p' -e 's/source/system/' samplefile.txt


linux is the best open source.Unix has sed command to replace.
linux is the best open system.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open system.unix is the best open source.
unix is the best open system.unix is the best open source.
http:\\www.google.com
unixunix is the best open system
It is an operating system.
(xiii)To replace the 1st occurance of Unix in the 1st line as linux.

c15137@localhost:~$ sed '1 s/Unix/linux/' samplefile.txt


linux is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.

(xiv)To replace the 1st occurance of Unix in the 1st to 3rd line as linux.

c15137@localhost:~$ sed '1,3 s/Unix/linux/' samplefile.txt


linux is the best open source.Unix has sed command to replace.
linux is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.

(xv)To replace the 1st occurance of best from 2nd line to last line as BEST.

c15137@localhost:~$ sed '2,$ s/best/BEST/' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the BEST open source.unix is the best open source.
unix is the BEST open source.unix is the best open source.
http:\\www.google.com
unixunix is the BEST open source
It is an operating system.

(xiv) To find Unix in the given content and replace open as OPEN

c15137@localhost:~$ sed '/Unix/ s/open/OPEN/' samplefile.txt


Unix is the best OPEN source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
(xv) To delete 2nd line.

c15137@localhost:~$ sed '2 d' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.

(xvi) To delete all the line starting from 3rd line.

c15137@localhost:~$ sed '3,$ d' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.

(xvii) To display the line that contains unix.This acts like grep.

c15137@localhost:~$ sed -n '/unix/p' samplefile.txt


unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unixunix is the best open source

(xviii) To display the line that not contains unix.This acts like grep -v

c15137@localhost:~$ sed -n '/unix/!p' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
http:\\www.google.com
It is an operating system.

(xix)To duplicate every line.

c15137@localhost:~$ sed 'p' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
http:\\www.google.com
unixunix is the best open source
unixunix is the best open source
It is an operating system.
It is an operating system.
(xx) To add some content below the line where the word Unix

c15137@localhost:~$ sed '/Unix/ a "HI FRIENDS"' samplefile.txt


Unix is the best open source.Unix has sed command to replace.
"HI FRIENDS"
Unix is used by large number of users.
"HI FRIENDS"
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
c15137@localhost:~$ sed '/Unix/ a HI FRIENDS' samplefile.txt
Unix is the best open source.Unix has sed command to replace.
HI FRIENDS
Unix is used by large number of users.
HI FRIENDS
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.

(xxi) To add some content above the line where the word Unix

c15137@localhost:~$ sed '/Unix/ i HI FRIENDS' samplefile.txt


HI FRIENDS
Unix is the best open source.Unix has sed command to replace.
HI FRIENDS
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.

(xxii) To change the content that starts with Unix.

c15137@localhost:~$ sed '/Unix/ c HI FRIENDS' samplefile.txt


HI FRIENDS
HI FRIENDS
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
(xxiv) To replace every best as Best

c15137@localhost:~$ sed 'y/best/Best/' samplefile.txt


Unix is the Best open source.Unix has sed command to replace.
Unix is used By large numBer of users.
unix is the Best open source.unix is the Best open source.
unix is the Best open source.unix is the Best open source.
http:\\www.google.com
unixunix is the Best open source
It is an operating system.

9. (i) Command : grep


Description : This command helps to find the word in the file and display the entire line that
conatins that word.
Example :

c15137@localhost:~$ cat samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
unix is the best open source
Unix is very easy to learn.Unix sed command is very important

c15137@localhost:~$ grep Unix samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
Unix is very easy to learn.Unix sed command is very important

(ii) Command : grep -v


Description : This command display the line that does not contains the word that have been
mentioned.
Example :

c15137@localhost:~$ grep -v unix samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
http:\\www.google.com
It is an operating system.
Unix is very easy to learn.Unix sed command is very important
c15137@localhost:~$
(iii) Command : grep -i
Description : This command helps to find the word(Ignores the Case) in the file and display the
entire line that conatins that word.

Example :
c15137@localhost:~$ grep -i Unix samplefile.txt
Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unixunix is the best open source
unix is the best open source
Unix is very easy to learn.Unix sed command is very important
l inuxandunix are the open source
unix unix unix
unix is easy to learn
unix unix unix
c15137@localhost:~$

(iv) Command : grep -w


Description : This command displays the line that contains the exact word.ie if the given word
is the substring of any word then it ignores that line.
Example :

c15137@localhost:~$ grep -w unix samplefile.txt


unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unix is the best open source
unix unix unix
unix is easy to learn
unix unix unix
c15137@localhost:~$

(v) Command : grep -c


Description : This command count the number of ocuurance.
Example :

c15137@localhost:~$ grep -c unix samplefile.txt


8
c15137@localhost:~$

(vi) Command : grep –color


Description : This command is used to set the color to highlight the word.
Example :

c15137@localhost:~$ grep --color='auto' unix samplefile.txt


unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unixunix is the best open source
unix is the best open source
linuxandunix are the open source
unix unix unix
(vii) Command : grep -H
Description : This command prints the matching line with the file name.
Example :

c15137@localhost:~$ grep -H is red.txt samplefile.txt


red.txt:This is my lap
samplefile.txt:Unix is the best open source.Unix has sed command to replace.
samplefile.txt:Unix is used by large number of users.
samplefile.txt:unix is the best open source.unix is the best open source.
samplefile.txt:unix is the best open source.unix is the best open source.
samplefile.txt:unixunix is the best open source
samplefile.txt:It is an operating system.
samplefile.txt:unix is the best open source
samplefile.txt:Unix is very easy to learn.Unix sed command is very important
samplefile.txt:unix is easy to learn
c15137@localhost:~$

(viii) Command : grep -n


Description : This command displays the line which contains the word with the line number.
Example :

c15137@localhost:~$ grep -n unix samplefile.txt


3:unix is the best open source.unix is the best open source.
4:unix is the best open source.unix is the best open source.
6:unixunix is the best open source
8:unix is the best open source
11:linuxandunix are the open source
12:unix unix unix
14:unix is easy to learn
16:unix unix unix
c15137@localhost:~$

(ix) Command : grep –max-count


Description : This command searches for the word and display only the line equal to maxcount
Example :

c15137@localhost:~$ grep --max-count=3 unix samplefile.txt


unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unixunix is the best open source
c15137@localhost:~$

(x) Command : grep -T


Description : This command ignores the tab space in the file and the dispaly the line that
matches the word that have been mentioned.
Example :

c15137@localhost:~$ grep -T unix samplefile.txt


unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
unixunix is the best open source
unix is the best open source
linuxandunix are the open source
unix unix unix
unix is easy to learn
unix unix unix
c15137@localhost:~$

(xi) Command : grep –after-context=num


Description : This command searches for the word and displays the line that are after the word
occur for the first time .The line count is equal to the num value.
Example :

c15137@localhost:~$ grep --after-context=2 unixunix samplefile.txt


unixunix is the best open source
It is an operating system.
unix is the best open source
c15137@localhost:~$

(xii) Command : grep –before-context=num


Description : This command searches for the word and displays the line that are before to the
word occur for the first time .The line count is equal to the num value.
Example :

c15137@localhost:~$ grep --before-context=3 unixunix samplefile.txt


unix is the best open source.unix is the best open source.
unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
c15137@localhost:~$

(xiv) Command : grep –context=num


Description : This command searches for the word and displays the line that are before and
after to the word occur for the first time .The line count is equal to the num
value.
Example :

c15137@localhost:~$ grep --context=2 unixunix samplefile.txt


unix is the best open source.unix is the best open source.
http:\\www.google.com
unixunix is the best open source
It is an operating system.
unix is the best open source
c15137@localhost:~$
(xv) Command : grep -o
Description : This command is use some pattern to search for the content in the file.This
displays only value that matches the pattern.
Example :

c15137@localhost:~$ grep -o '[0-9]*' samplefile.txt red.txt


samplefile.txt:123456
red.txt:523679
red.txt:764783264
c15137@localhost:~$

(xvi) Command : grep –regexp


Description : This command is use some pattern to search for the content in the file.This
displays the entire line matches the pattern.
Example :

c15137@localhost:~$ grep --regexp='[0-9]*' Unix samplefile.txt red.txt


grep: Unix: No such file or directory
samplefile.txt:Unix is the best open source.Unix has sed command to replace.
samplefile.txt:Unix is used by large number of users.
samplefile.txt:unix is the best open source.unix is the best open source.
samplefile.txt:unix is the best open source.unix is the best open source.
samplefile.txt:http:\\www.google.com
samplefile.txt:unixunix is the best open source
samplefile.txt:It is an operating system.
samplefile.txt:unix is the best open source
samplefile.txt:Unix is very easy to learn.Unix sed command is very important
samplefile.txt:123456adbcd
samplefile.txt:linuxandunix are the open source
samplefile.txt:unix unix unix
samplefile.txt:
samplefile.txt:unix is easy to learn
samplefile.txt:
samplefile.txt:unix unix unix
samplefile.txt:
red.txt:This is my lap
red.txt:523679afssda764783264bsadb
c15137@localhost:~$

10. (i) Command : history


Description : This commands gives the list of commands we have worked in until now.
Example :

c15137@localhost:~$ history
history -d
history -a
history
man history
cat > historyfile.txt
history -a historyfile.txt
cat historyfile.txt
vi historyfile.txt
history
c15137@localhost:~$

(ii) Command : history – c


Description : This command clears the history of commands.
Example :

c15137@localhost:~$ history -c
c15137@localhost:~$

(iii) Command : history -a


Description : This command helps to store all commands we have used into a file.
Example :

c15137@localhost:~$ cat > historyfile.txt


^Z
[15]+ Stopped cat > historyfile.txt
c15137@localhost:~$

c15137@localhost:~$ history -a historyfile.txt


c15137@localhost:~$ cat historyfile.txt
history
man history
cat > historyfile.txt
history -a historyfile.txt
cat historyfile.txt
vi historyfile.txt
history
cat historyfile.txt
history -a historyfile.txt
c15137@localhost:~$

11. (i) Command : find -name filename


Description : This command is used to find the files located along with the directory
Example :

c15137@localhost:~$ find -name samplefile.txt


./sample/samplefile.txt
./samplefile.txt
c15137@localhost:~$
(ii) Command : find -iname filename
Description : This command is used to find the files located along with the directory by
ignoring the CASE of the filename.
Example :

c15137@localhost:~$ find -iname samplefile.txt


./sample/samplefile.txt
./Samplefile.txt
./SAMPLEFILE.txt
./samplefile.txt
c15137@localhost:~$

(iii) Command : find -maxdepth 1 -name “filename”


Description : This command searches for the filename only in the current working
directory.
Example :

c15137@localhost:~$ find -maxdepth 1 -name "samplefile.txt"


./samplefile.txt
c15137@localhost:~$

find -maxdepth 2 -name “filename”-This command checks for file in current


directory and also within a any other directory

c15137@localhost:~$ find -maxdepth 2 -name "samplefile.txt"


./sample/samplefile.txt
./samplefile.txt

Note : find -maxdepth 3 -name “filename” checks for current directory , other
directory and also directory with in other directory so on.........
c15137@localhost:~$ find -maxdepth 3 -name "samplefile.txt"
./sample/samplefile.txt
./sample/samp/samplefile.txt
./samplefile.txt
c15137@localhost:~$

(iv) Command : find -not -name filename


Description : This command displays the file name other than the file that have been
mentioned .
Example :

c15137@localhost:~$ find -not -name samplefile.txt


./Downloads/hive-0.7.0/src/metastore/src/gen-javabean/org/apache
./Downloads/hive-0.7.0/src/metastore/src/gen-javabean/org/apache/hadoop
./Downloads/hive-0.7.0/src/metastore/src/gen-javabean/org/apache/hadoop/hive
./Downloads/hive-0.7.0/src/metastore/src/gen-
javabean/org/apache/hadoop/hive/metastore
./Downloads/hive-0.7.0/src/metastore/src/gen-
javabean/org/apache/hadoop/hive/metastore/api
./Downloads/hive-0.7.0/src/metastore/src/java
c15137@localhost:~$

(v) Command : find -type d


Description : This command helps to find the directories.
Example :

c15137@localhost:~$ find -type d


./Downloads/hive-0.7.0/src/serde/src/java/org/apache/hadoop/hive
./Downloads/hive-0.7.0/src/serde/src/java/org/apache/hadoop/hive/serde2
./Downloads/hive-
0.7.0/src/serde/src/java/org/apache/hadoop/hive/serde2/binarysortable
./Downloads/hive-0.7.0/src/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary
./Downloads/hive-
0.7.0/src/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/objectinspector
./Downloads/hive-
0.7.0/src/serde/src/java/org/apache/hadoop/hive/serde2/dynamic_type
./Downloads/hive-0.7.0/src/serde/src/java/org/apache/hadoop/hive/serde2/lazy
c15137@localhost:~$

(vi) Command : find -type f


Description : This command helps to find all the regular files.
Example :

c15137@localhost:~$ find -type f


./Downloads/hive0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/generic/GenericUDA
FHistogramNumeric.html
./Downloads/hive0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/generic/GenericUDA
FVarianceSample.html
./Downloads/hive-
0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/generic/GenericUDFStruct.html
./Downloads/hive0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/generic/GenericUDF
OPEqualOrLessThan.html
./Downloads/hive-0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/UDFPosMod.html
./Downloads/hive0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.
html
./Downloads/hive-
0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.html
./Downloads/hive-
0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/UDFOPNegative.html
./Downloads/hive-0.7.0/docs/api/org/apache/hadoop/hive/ql/udf/UDFLn.html
c15137@localhost:~$

(vii) Command : find -type f “.*”


Description : This command is used to find all the hidden files.
Example :

c15137@localhost:~$ find -type f -name ".*"


./.profile
./.goutputstream-XH1OAX
./.pentaho/.vercheck
./.bashrc
./.thunderbird/ite1bzeh.default/.parentlock
./.Xauthority
./.gtk-bookmarks
./.ICEauthority
./.goutputstream-Y85TAX
./.goutputstream-DUU28W
./.kettle/.spoonrc
./.xsession-errors.old
./.dmrc
c15137@localhost:~$

(viii) Command : find -size


Description : This command helps find the file with the size that have been mentioned.
Example :

c15137@localhost:~$ find -size 10M


./.mozilla/firefox/7jejaze1.default/places.sqlite
c15137@localhost:~$

c15137@localhost:~$ find -size +10M


./.mozilla/firefox/7jejaze1.default/urlclassifier3.sqlite
./Desktop/P/pdi-ce-4.3.0-stable.zip
./Desktop/P/TwelveLakhRows.txt
./Documents/Rams/Unix/pentaho-big-data-plugin-TRUNK-SNAPSHOT.tar.gz
./Documents/Rams/Unix/pdi-ce-4.4.0-SNAPSHOT-big-data.tar.gz
./.local/share/zeitgeist/activity.sqlite-wal
./Downloads/zookeeper-3.3.5.tar
./Downloads/hive-0.7.0.tar.gz
./Downloads/Hadoop Materials.zip
./Downloads/pdi-ce-4.3.0-stable.zip
./Downloads/Varaprasad/5a-HBaseToHdfs/Files/USD50K~
c15137@localhost:~$

c15137@localhost:~$ find -size -10M


./.local/share/Trash/info/picture2045871868.png.trashinfo
./.local/share/Trash/info/picture1320874052.png.trashinfo
./.local/share/Trash/info/style624134308.css.trashinfo
./.local/share/Trash/info/picture312203007.png.trashinfo
./.local/share/Trash/info/picture234739266.png.trashinfo
./.local/share/Trash/info/Zip.zip.trashinfo
c15137@localhost:~$
(ix) Command : find -newer “filename”
Description : This command displays the filename that have been modified.
Example :

c15137@localhost:~$ find -newer "samplefile.txt"


.
./sample
./sample/samp
./sample/samp/samplefile.txt
./red.txt
./.pulse
./.pulse/76133b772ce2c4ef42dfd93d0000000a-default-sink
./.pulse/76133b772ce2c4ef42dfd93d0000000a-default-source
./.pulse/76133b772ce2c4ef42dfd93d0000000a-runtime
./.Xauthority
./.gvfs
./samplefile
c15137@localhost:~$

(x) Command : find -anewer “filename”


Description : This command displays the filename that have been accessed after modification
takes place.
Example :

c15137@localhost:~$ find -anewer "samplefile.txt"


./.cache/evolution
./.cache/.fr-GghANq
./.cache/.fr-GghANq/SCREENSHOTS
./.cache/indicator
./.cache/indicator/sound
./.cache/indicator/sound/album-art-cache
./.cache/.fr-xAg31g
./.cache/.fr-xAg31g/SCREENSHOTS
./.cache/compizconfig-1
./.cache/compizconfig-1/wall.pb
c15137@localhost:~$

(xi) Command : find -perm


Description : This command helps to find the permissions for the files.
Example :

c15137@localhost:~$ find -perm 777


./.pulse/76133b772ce2c4ef42dfd93d0000000a-runtime
./.mozilla/plugins/libnpjp2.so
./.mozilla/firefox/7jejaze1.default/lock
c15137@localhost:~$
(xii) Command : find -amin,find -mmin,find -cmin
Description : These commands helps to find the file based on the access time,modification
time or change in file at particular time respectively(time is denotes as minutes).
Example :

c15137@localhost:~$ find -mtime -60


./historyfile.txt
./.xsession-errors
./samplefile.txt.gz
./.cache
./.cache/telepathy
./.cache/telepathy/logger
./.cache/telepathy/logger/sqlite-data
./.cache/unity-lens-video
./.cache/unity-lens-video/videos.db
c15137@localhost:~$

c15137@localhost:~$ find -ctime -60


./.compiz-1/session/10fca3286b78513f00138899353296128500000132430033
./.compiz-1/session/10bde103ca7a270758138985075186600000000244830033
./.compiz-1/session/10560c8971537ddff8139089997195272700000217300033
./.compiz-1/session/1087532e1e23dd087d138907111659920100000226930033
./.compiz-1/session/10349fb201a0b2a8c4138865471574411000000274200033
./.compiz-1/session/103b96c47853a512ef138865483992041200000281080033
./.compiz-1/session/103ebbdb05377a1b33138848569982468400000058870033
c15137@localhost:~$

(xiii) Command : find -atime,find -mtime,find -ctime


Description : These commands helps to find the file based on the access day,modification
day or change in file at particular day respectively.
Example :

c15137@localhost:~$ find -atime -1


./Downloads/hadoop-
0.21.0/common/docs/api/org/apache/hadoop/contrib/failmon/class-use
./Downloads/hadoop-0.21.0/common/docs/api/org/apache/hadoop/ipc
./Downloads/hadoop-0.21.0/common/docs/api/org/apache/hadoop/ipc/class-use
./Downloads/hadoop-0.21.0/common/docs/api/org/apache/hadoop/record
./Downloads/hadoop-0.21.0/common/docs/api/org/apache/hadoop/record/meta
c15137@localhost:~$

c15137@localhost:~$ find -ctime -1


./sample12.txt
./.dbus/session-bus/76133b772ce2c4ef42dfd93d0000000a-0
./.goutputstream-B1H4AX
./.compiz-1/session
./.compiz-1/session/1055d04fefc0de0af139157423530438600000015830033
./.compiz-1/session/1021704eab247d1821139148715954335800000015900033
./samplefile.txt
./historyfile.txt
./.xsession-errors
c15137@localhost:~$

c15137@localhost:~$ find -mtime -1


./.thumbnails/normal/62d114a9989e69b9fda02b123d415180.png
./sample12.txt
./.dbus/session-bus/76133b772ce2c4ef42dfd93d0000000a-0
./.goutputstream-B1H4AX
./.compiz-1/session
./.compiz-1/session/1055d04fefc0de0af139157423530438600000015830033
./.compiz-1/session/1021704eab247d1821139148715954335800000015900033
./samplefile.txt
./historyfile.txt
./.xsession-errors
c15137@localhost:~$

(xiv) Command : find /directory -name filename


Description: This command helps to find the file in particular directory.
Example :

c15137@localhost:~$ find /home/c15137/sample -name "samplefile.txt"


/home/c15137/sample/samplefile.txt
/home/c15137/sample/samp/samplefile.txt
c15137@localhost:~$

12. Command :head


Description : This command gives the number of lines (starting from the first) that have been
mentioned for the given file.
Example :

c15137@localhost:~$ head -3 samplefile.txt


Unix is the best open source.Unix has sed command to replace.
Unix is used by large number of users.
unix is the best open source.unix is the best open source.
c15137@localhost:~$

13. Command :tail


Description : This command gives the number of lines (starting from the last) that have been
mentioned for the given file.
Example :

c15137@localhost:~$ tail -4 samplefile.txt


unix is easy to learn

unix unix unix

c15137@localhost:~$
14. Command : Kill
Description : This command helps to kill the PID .
Example :

c15137@localhost:~$ su hduser
Password:
hduser@localhost:/home/c15137$ start-all.sh
starting namenode, logging to /usr/local/hadoop/bin/../logs/hadoop-hduser-
namenode-localhost.out
localhost: starting datanode, logging to /usr/local/hadoop/bin/../logs/hadoop-hduser-
datanode-localhost.out
localhost: starting secondarynamenode, logging to
/usr/local/hadoop/bin/../logs/hadoop-hduser-secondarynamenode-localhost.out
starting jobtracker, logging to /usr/local/hadoop/bin/../logs/hadoop-hduser-jobtracker-
localhost.out
localhost: starting tasktracker, logging to /usr/local/hadoop/bin/../logs/hadoop-
hduser-tasktracker-localhost.out
hduser@localhost:/home/c15137$ jps
7227 Jps
6929 TaskTracker
6185 NameNode
6409 DataNode
6631 SecondaryNameNode
6715 JobTracker
hduser@localhost:/home/c15137$ kill -9 6929
hduser@localhost:/home/c15137$ jps
7244 Jps
6185 NameNode
6409 DataNode
6631 SecondaryNameNode
6715 JobTracker
hduser@localhost:/home/c15137$

15.Command : zip,unzip
Description : These commands helps to compress and uncompress the files respectively.
Example :

c15137@localhost:~$ zip sample.zip samplefile.txt sampl1.txt SAMPLEFILE.txt


adding: samplefile.txt (deflated 60%)
adding: sampl1.txt (stored 0%)
adding: SAMPLEFILE.txt (stored 0%)

c15137@localhost:~$ unzip -l sample.zip


Archive: sample.zip
Length Date Time Name
--------- ---------- ----- ----
492 2014-02-05 11:08 samplefile.txt
10 2014-02-04 10:55 sampl1.txt
0 2014-02-06 10:19 SAMPLEFILE.txt
--------- -------
502 3 files
16. Command : du -b
Description : This command helps to display the apparent (ie) exact size of all the files.
Example :

c15137@localhost:~$ du -b
4163 ./.cache/software-center/software-center-agent.db.tmp
4096 ./.cache/software-center/rnrclient
1060864 ./.cache/software-
center/reviews.ubuntu.com_reviews_api_1.0_review-stats-
pkgnames.p__5.1.db.dbenv
2724022 ./.cache/software-center/software-center-agent.db
4096 ./.cache/software-center/download-cache
870179 ./.cache/software-center/piston-helper
5739552 ./.cache/software-center
4097 ./.cache/dconf
1981737 ./.cache/libimobiledevice/icons
c15137@localhost:~$

17.Command : ls -s
Description : This command display all the files along with the size.
Example :

c15137@localhost:~$ ls -s
total 152
8 Basic unix Commands.docx 4 historyfile.txt 4 sampl1.txt 0 Samplefile.txt
4 sample.txt.gz 4 Videos
16 Basic unix Commands.odt 4 Music 4 sample 0 SAMPLEFILE.txt
4 sample.zip
4 Desktop 4 Pictures 4 sample12.txt 4 samplefile.txt.gz
4 samplsac.txt
4 Documents 4 Public 4 samplefile 4
samplesamplefilename.txt.gz 4 samp.txt.gz
4 Downloads 16 pur.ktr 4 samplefile1.txt 4 sampletest.txt
4 Templates
12 examples.desktop 4 red.txt 4 samplefile.txt 4 sample.txt
4 tmp
c15137@localhost:~$

You might also like