ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Operating Systems

UNIX Basic Commands

Updated on October 24, 2015

Description

Unix is one of the most secured OS and is Character User Interface (CUI)

We are providing the Unix commands for basic level learners with good examples.

Please go through the hubpage and do the practice all the commands in your Unix environment.

UNIX Basic Commands

With examples

#1 ls: List out the contents of home directory

Usage: ls [options]

options -l list out the files & directories with details like permissions, group, owner, date etc…

-la: list out the files & directories along with hidden files & directories.

-lrt: sort the files by lastly modified

#2 ls -la: List out the files & directories along with hidden files & directories.

$ ls -la

drwxr-xr-x+ 1 User None 0 Jul 16 23:11 .

drwxr-xr-x+ 1 User None 0 Jun 28 18:05 ..

d-wx------+ 1 User None 0 Jun 20 17:48 temple

-rw-r--r-- 1 User None 6 Jun 17 23:23 file1

Note: . (dot) & .. (dot dot) are the hidden directories/files, temple and file1 are the shown directory and file

#3 ls -lrt: This command is sort the directories and files by lastly modified time/date

$ls -lrt

d-wx------+ 1 User None 0 Jun 20 17:48 abc1

d-wx------+ 1 User None 0 Jun 20 11:48 abc2

-rw-r--r-- 1 User None 70 Jul 16 23:07 file1

-rw-r--r-- 1 User None 6 Jun 18 10:10 file2

-rw-r--r-- 1 User None 7 Jun 18 10:15 file1

Note: Check the Time and date of directories and files which are sorted.

#4 mkdir <directory name>: Creates new directory

$mkdir David

$ls –la

drwxr-xr-x+ 1 User None 0 Jul 16 23:11 .

drwxr-xr-x+ 1 User None 0 Jun 28 18:05 ..

d-wx------+ 1 User None 0 Aug 20 16:46 David

Note: Directory created with the name David use the command ‘ls –la ‘ to check the created directory.

#5 mkdir <dir1 dir2 dir3>:To create multiple directories.

$mkdir Hillary Jhonson Rosy Nancy

$ls –la

drwxr-xr-x+ 1 User None 0 Jul 16 23:11 .

drwxr-xr-x+ 1 User None 0 Jun 28 18:05 ..

d-wx------+ 1 User None 0 Aug 20 16:50 Hillary

d-wx------+ 1 User None 0 Aug 20 16:50 Jhonson

d-wx------+ 1 User None 0 Aug 20 16:50 Rosy

d-wx------+ 1 User None 0 Aug 20 16:50 Nancy

Note: Multiple directories named Hillary Jhonson Rosy Nancy created at a time.

#6: rmdir <directory name>: Removes/Deletes particular directory.

$rmdir Rosy

$ls –la

drwxr-xr-x+ 1 User None 0 Jul 16 23:11 .

drwxr-xr-x+ 1 User None 0 Jun 28 18:05 ..

d-wx------+ 1 User None 0 Aug 20 16:50 Hillary

d-wx------+ 1 User None 0 Aug 20 16:50 Jhonson

d-wx------+ 1 User None 0 Aug 20 16:50 Nancy

Note: The directory ‘Rosy’ has been removed successfully.

#7 pwd = Find out what directory you are in (present working directory).

#8 cd <directory name>:change directory or enter into the particular directory.

#9 cd .. :This Command will bring back the user to previous position/directory.

#10 cd ../../ : This bring back the user to two directories. You can extend this cd command to go back to n number of directories.

$ pwd

/home/user/group/Hillary

Hillary is the present working directory

$ cd ..

$ pwd

/home/user/group

*We came out from the directory Hillary

or

$ cd ../ ../

/home/user/

*Here we came out from the two directories (Hillary and group) at a time.

#11a cat >filename : Creates new file. Cat is the command to create the file and we can enter the data at the time of file creation and has to hit Ctrl+Z to save the file.

#11b touch <filename>: Creates new empty file.

#12 cat >> <filename> :To append the information to the file.

#13 cat filename :Displays the contents of the file.

#14 rm filename : Removes/Deletes the particular file.

Output: $ cat >file1

This is a test file (hit ctrl+Z)

$ cat >>file1

check this once. (hit ctrl+Z)

$ cat file1

This is a test file

check this once.

#15 mv <oldname> <newname> :Renames file/directory.

$ls –lrt

-rw-r--r-- 1 User None 6 Jun 18 10:10 abc

-rw-r--r-- 1 User None 6 Jun 18 10:15 def

$mv abc xyz

-rw-r--r-- 1 User None 6 Jun 19 10:18 xyz

-rw-r--r-- 1 User None 6 Jun 18 10:10 def

*Renamed the filename ‘abc’ as ‘xyz’

#16 mv <filename> <destination> :To move the file/directory from one location to another location.

$mv /home/user/Jack/xyz /home/user/Jhon/xyz

Or

$mv xyz /home/user/Jhon/xyz

* The file xyz has been moved to the location /home/user/Jhon from its current location /home/user/Jack.

#17 cp <filename> <destination> :For copying file/directory

$cp def /home/user/Jhon

*The file def has been copied to the location /home/user/Jhon from its current location /home/user/Jack.

*file copied to the directory Jhon from the directory Jack is existing in both directories where as in mv command file existing in Jhon directory only


#18 more : This command is also displays the content of the file like the command “cat Filename”.

#19 wc : wc (word count) displays a count of lines, words and characters in a file.

Syntax: wc [-options] [filename]

$ wc test1

2 6 27 test1

2 - lines, 6 - words, 27 - characters.

#21: man : man command provides information about the requested command

Syntax: man [command]

Eg: man wc

Displays all the information about the command wc

#22 ~ : we will get the path of own home directory.

output:$ ~

/home/group/user/Jack: is a directory

#23: ~username : we will get the path of particular user home directory.

output:$ ~ username

/model/decisionfs_home/raripira: is a directory


#24: find :To search for a file on the server from root.

Syntax: find . -name "<file name>"

Output: find . –name def.txt

./def.txt


#25 grep :"Global Regular Expression Print", is used to search the information(text, files... ) which is matched with the given pattern and by default displays the matching information.

$ ls -lrt | grep - i Mike

drwxrwx--- 2 rose group1 3 jun 13 13:23 Mike

$ ls -lrt | grep - i Ames

Note: In the above example“Ames” text pattern is not existing, hence it doesn’t print anything.

|(pipe) = We can connect two commands together so that the output from one program becomes the input of the next program. Two or more commands connected in this way form a pipe.

To make a pipe, put a vertical bar (|) on the command line between two commands. When a program takes its input from another program, performs some operation on that input, and writes the result to the standard output, it is referred to as a filter.


#26: /etc/passwd: Is a file contains account information, such as username, password, user id, login directory, and login shell.

syntax: grep -i username /etc/passwd

$grep -i Wilson /etc/passwd

jwilson:x:61617:2015:Wilson Jhon:/model/decisionfs_home/raripira:/bin/sh

a b c d e f g

where:

a. username.

b. password (An x character indicates that password is encrypted).

c. User id (uid).

d. group id (gid).

e. Fullname

f. Home directory

g. Login shell


#27: id <username> :we will get user id, group id along with username and primary group name respectively.

output: id raripira

uid=61617 (raripira) gid=2015 (decisionfs)

#28: groups <username> : we will get the list of primary group and secondary groups of the user.

output:

$groups kemily

fraud maarg trial

Note:fraud is primary group, maarg and trial are secondary groups of user kemly.

#29: listusers -g <group name> :It shows all the users in that particular group with their username and fullnam

$listusers -g group1

Jhond Jhon David

Millerd Miller David

Venkatp Venkat Polu

#30 listusers -l <user id> : Shows the Username of that ID.

Output:

$ listusers -l emilyk

emilyk Emily Kim


#31 finger :Displays the list of logged in users , it usually lists the login name, full name and possibly other details.

Output:

$ finger

Login Name TTY Idle When Where

Chinnap chinna Polu pts/2 4:29 Tue 04:19 10:45:118:81

Pradeepv Pradeep Vara pts/23 21 Tue 06:20 10:45:118:189

Eg:

$ finger chinnap :we will get the information about the chinnap


Login:chinnap Name: (Chinnap chinna Polu)

Directory: /home/chinnap Shell: /bin/bash

On since Mon Nov 1 18:45 (IST) on :0 (messages off)

On since Mon Nov 1 18:46 (IST) on pts/0 from :0.0

New mail received Fri May 7 10:33 2010 (IST)

Unread since Sat Jun 7 12:59 2008 (IST) No Plan.

Rating

4.8 out of 5 stars from 4 ratings of this Hubpage

Is this helpful to you

See results

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Saran kumar 22 months ago

      Good article

    • profile image

      sravani 22 months ago

      Good article... It is useful alot to unix learners.

    • profile image

      Purna Kishore 22 months ago

      good commands for learners

    • profile image

      Bhanu Teja 22 months ago

      Covered the basic unix commands as well as examples are good. Best hub for people who are new to unix environment.

    • profile image

      Chinna 22 months ago

      Good Hub for Unix basic learners and examples are nice.

    • Venkat Poluboyina profile image
      Author

      Venkat Poluboyina 22 months ago

      Very useful to the beginners.