Basic Unix Commands
Basic Unix Commands
Command : mv
Description: This command helps to move the content in the file permanently to another file.
Example :
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 :
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
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 :
(vii) To dublicate any word and enclose inside{}(we can use any symbols instead of {} eg.(),*..)
(xii) Usage of multiple sed command ie.1st Unix is replaced as linux and the source is replaced as
system.
(xiv)To replace the 1st occurance of Unix in the 1st to 3rd line as linux.
(xv)To replace the 1st occurance of best from 2nd line to last line as BEST.
(xiv) To find Unix in the given content and replace open as OPEN
(xvii) To display the line that contains unix.This acts like grep.
(xviii) To display the line that not contains unix.This acts like grep -v
(xxi) To add some content above the line where the word Unix
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:~$
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:~$
c15137@localhost:~$ history -c
c15137@localhost:~$
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:~$
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:~$ 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:~$