ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

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
working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)