Basic linux commands

Commands

useful link

 

1.  pwd – print working directory,In Unix-like and some other operating systems, the pwd command (print working directory) is used to output the path of the current working directory.

[root@nfsserver ~]# cd /var/log
[root@nfsserver log]# pwd
/var/log

2.  date – date command is used to display or eddit the current date and time of the  system.

[root@nfsserver log]# date
Wed Jun 10 02:27:59 EDT 2015

3.   who or w –  displays who is logged on to  Linux or Unix-like operating system using shell prompt. w command also show who is doing what.

[root@nfsserver log]# who
root     tty1         2015-05-21 22:51
root     pts/0        2015-06-10 02:13 (192.168.2.6)
hareram  pts/1        2015-06-10 02:36 (192.168.2.6)
hareshyam pts/2        2015-06-10 02:37 (192.168.2.6)

[root@nfsserver log]# w
 02:37:54 up 1 day,  4:09,  4 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                21May15  4:44m  0.50s  0.50s -bash
root     pts/0    192.168.2.6      02:13    0.00s  0.03s  0.00s w
hareram  pts/1    192.168.2.6      02:36   45.00s  0.00s  0.00s -bash
hareshya pts/2    192.168.2.6      02:37    8.00s  0.00s  0.00s -bash

 

4. whoami  – The whoami command writes the user name (i.e., login name) of the owner of the current login session to standard output.

[hareram@nfsserver ~]$ whoami
hareram
[hareram@nfsserver ~]$ id -un
hareram

5. man –  Command to display manual pages of Unix commands.

[root@nfsserver ~]# man head
Formatting page, please wait...
HEAD(1)                          User Commands                         HEAD(1)

NAME
       head - output the first part of files

SYNOPSIS
       head [OPTION]... [FILE]...

DESCRIPTION
       Print  the  first  10 lines of each FILE to standard output.  With more
       than one FILE, precede each with a header giving the file  name.   With
       no FILE, or when FILE is -, read standard input.

       Mandatory  arguments  to  long  options are mandatory for short options
       too.

       -c, --bytes=[-]K
              print the first K bytes of each  file;  with  the  leading  ‘-’,
              print all but the last K bytes of each file

       -n, --lines=[-]K
              print  the first K lines instead of the first 10; with the lead-
              ing ‘-’, print all but the last K lines of each file

5. info – Info is similar to man, with a more robust structure for linking pages together. Info pages are made using the texinfo tools, and can link with other pages, create menus and ease navigation in general.

5. –help –  shows help page for the given command

[root@nfsserver ~]# head --help
Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[-]K         print the first K bytes of each file;
                             with the leading -', print all but the last
                             K bytes of each file
  -n, --lines=[-]K         print the first K lines instead of the first 10;
                             with the leading -', print all but the last
                             K lines of each file
  -q, --quiet, --silent    never print headers giving file names
  -v, --verbose            always print headers giving file names
      --help     display this help and exit
      --version  output version information and exit

6. head –    Command to display the first “n” lines in a file

[root@nfsserver ~]# head -n8 test1
a
b
c
d
e
f
g
h

7. tail – Command to display the last “n” lines in a file

[root@nfsserver ~]# tail -n 8 test1
i
j
k
l
m
n
o
p

8. cd –   Change Directory is a basic command which is used to change your working directory from one to other.

9. mkdir  – create directory

9. rmdir  – removes empty directory.

[root@redhatclass linux]# rmdir test

10. cp  – cp command  is used to copy one or more files or directories from source to destination.

11. mv  – Linux mv command is used to move files and directories from one location to another. Apart from moving the files, it can also rename a file or directory.

12. ln  – There are two type of link:

  •  Softlink:
  • hardlink

13. rm  – remove files and directories

14. touch  – create an empty file and also update timestamp

15. echo  –

16. cat  –

17. vi  – text editor,

18. >  –

19. >>  –

20. read  –

21. wc –

22. sort  –

23. uniq  –

24. locate – very fast search command in linux

25. find  – slow but powerful search command in linux

26. grep  –

27. egrep  –

28. more – command to display file which allows forward scrolling.

29. less  – command to display file which allows backward and forward scrolling.

30. history  –

31.tree –   list contents of directories in a structure like format under Linux operating systems

[root@nfsserver ~]# tree -LCd 1 /
/
├── bijan
├── bin
├── boot
├── cbb
├── dev
├── dir1
├── etc
├── home
├── lib
├── lib64
├── lost+found
├── media
├── misc
├── mnt
├── net
├── nfsshare
├── opt
├── proc
├── rhel6
├── root
├── sbin
├── selinux
├── srv
├── sys
├── test
├── tmp
├── usr
└── var

-L 1 = show only one level

-C = show colours

-d = show only directory

32. whatis –

33. which –  to show path of a command

34. whereis  – find and locate the binary, source, and manual page files for a given command.

35. tar –  The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip inLinux.

[root@nfsserver ~]# pwd
/root
[root@nfsserver ~]# ls -l
-rw-------. 1 root root 1857 Oct 11 2014 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 Jun 11 13:36 class
drwxr-xr-x. 3 root root 4096 Jun 9 20:15 Desktop
drwxr-xr-x. 3 root root 4096 Oct 11 2014 Documents
drwxr-xr-x. 4 root root 4096 Dec 27 21:27 Downloads
-rw-r--r--. 1 root root 50712 Oct 11 2014 install.log
-rw-r--r--. 1 root root 10033 Oct 11 2014 install.log.syslog

 

compress the class directory in current directory

[root@nfsserver ~]# tar -cvzf archive.tar.gz class
class/
class/saroj
class/school
class/history
class/number
class/tutorial
class/ba
class/commands
class/b
class/bidur
class/fdkjfk
class/a
class/bijan
class/sudhir
class/aloodum
class/ab
class/bijan.orig

list the contents of archive.tar.gz

[root@nfsserver ~]# tar -tvzf archive.tar.gz
drwxr-xr-x root/root         0 2015-06-11 13:36 class/
-rw-r--r-- root/root       217 2015-06-10 18:55 class/saroj
-rw-r--r-- root/root        54 2015-06-09 20:44 class/school
-rw-r--r-- root/root     23312 2015-06-10 19:55 class/history
-rw-r--r-- root/root        16 2015-06-10 19:34 class/number
-rw-r--r-- root/root       217 2015-06-10 18:54 class/tutorial
-rw-r--r-- root/root        51 2015-06-10 19:11 class/ba
-rw-r--r-- root/root       217 2015-06-10 18:56 class/commands
-rw-r--r-- root/root        17 2015-06-10 19:09 class/b
-rw-r--r-- root/root        72 2015-06-10 19:33 class/bidur
-rw-r--r-- root/root       235 2015-06-10 18:58 class/fdkjfk
-rw-r--r-- root/root        17 2015-06-10 19:09 class/a
-rw-r--r-- root/root       168 2015-06-11 13:35 class/bijan
-rw-r--r-- root/root       235 2015-06-10 18:56 class/sudhir
-rw-r--r-- root/root       256 2015-06-10 19:01 class/aloodum
-rw-r--r-- root/root        51 2015-06-10 19:10 class/ab
-rw-r--r-- root/root         0 2015-06-11 13:36 class/bijan.orig

 

untar the archive.tar.gz  in /tmp folder

[root@nfsserver ~]# tar -xvzf archive.tar.gz -C /tmp
class/
class/saroj
class/school
class/history
class/number
class/tutorial
class/ba
class/commands
class/b
class/bidur
class/fdkjfk
class/a
class/bijan
class/sudhir
class/aloodum
class/ab
class/bijan.orig
[root@nfsserver ~]# cd /tmp
[root@nfsserver tmp]# ls
class  hello 
[root@nfsserver tmp]# ls class/
a  ab  aloodum  b  ba  bidur  bijan  bijan.orig  commands  fdkjfk  history  number  saroj  school  sudhir  tutorial

 

 

 

 

 

Leave a Reply