EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Unix Tutorial Unix Shell Commands
Secondary Sidebar
Unix Tutorial
  • Advanced
    • Array in Unix
    • Functions in Unix
    • Unix File Permissions
    • Unix File System
    • Unix Shell Commands
    • Crontab in Unix
    • egrep command in Unix
    • For Loop in Unix
    • VI Editor in Unix
    • What is Unix Shell
    • Gnome Development
    • UNIX interview questions
    • Cheat sheet for UNIX
    • Unix Sort by Column
    • Find Command in Unix
    • Gnome Version
  • Basic
    • What is Unix
    • Uses of Unix
    • Career In Unix
    • Install UNIX
    • Unix Architecture
    • Unix Commands
    • VI Command in Unix
    • AWK Command in Unix
    • Paste Command in Unix
    • SED Command in Unix
    • Sort Command in Unix
    • WHO Command in Unix
    • Unix Operators
    • UNIX Administrator

Related Courses

Linux Training Course

Kali Linux Training

Red Hat Training Course

Unix Shell Commands

By Savi JaggaSavi Jagga

Unix Shell Commands

What is Unix Shell Commands?

Unix shell commands are one of the four layers of Unix architecture, enabling human interaction with the operating system to intimate it to begin certain processes by giving commands through the interpreter. It consists a set of commands like cp, grep, cat, id, mv etc., that are pre-defined and stored in the libraries. Unix shell commands are of three types basic, intermediate and advanced, consisting of various commands like ls, cat, rm, mv, mkdir, chmod, find, chown, chgrp, head, tail, grep, ln, cut etc.

UNIX Architecture

Here is the following UNIX architecture mention below

UNIX Architecture

  • Layer-1: Hardware

This layer consists of all the hardware resources being used.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,502 ratings)
  • Layer-2: Kernel 

The kernel is like the heart of the operating system. It is the mode of interaction between the hardware and operating system. It also manages tasks, resources using scheduling processes for the smooth functioning of the system.

  • Layer-3: Shell commands

It is the way for a human to interact with the operating system and tell it to start certain processes. An interpreter is used where we give the command for the operating from the set of all commands for which the definition has been defined and stored in the libraries.

Some examples of commands are cp, mv, cat, grep, id, wc, nroff, a.out and more.

  • Layer-4: Application Layer

It executes the given external applications. It is an outermost layer to execute the applications.

List of Unix Shell Commands

Here is the list of the following Unix Shell Commands mention below:

  • Basic.
  • Intermediate.
  • Advanced.

Let us see the above List of Unix Shell Commands in detail

1. Basic Unix Shell Commands

a. Listing files (ls) – ‘ls’ command is used to list out all the files in a directory.

Syntax-

ls -<option> directory_name

Example-

ls test
option Description
ls -a To list all files with the hidden files starting with ‘.’
ls –color Shows colored list which can be [=always/never/auto]
ls -d To list all directories
ls -F To add one char of  to the entries
ls -i To list all files ignoring the case
ls -l To list all the details of the file
ls -la list long format including hidden files
ls -lh list long format with the readable file size
ls -ls list with the long format with the file size
ls -r list in reverse order
ls -R list recursively directory tree
ls -s list file size
ls -S sort by file size
ls -t sort by time & date
ls -X sort by extension name

b. Creating & Viewing Files –  ‘cat command can be used to create the file or view the contents of the file.

Syntax –

cat >filename  

Example –  cat > test1.dat – will create a file and will wait for the input to be written into the file.

cat filname – will display the contents of the file on the screen.

c. Deleting Files – ’rm’ command is used to delete a file from the directory.

Syntax-

rm filename
Tag Description
-f, –force ignore nonexistent files, never prompt.
-i prompt before every removal.

d. Moving and Re-naming files – ‘mv’ command is used for moving a file from one location to another. This command can also be used for renaming the file as the source file gets deleted and a new file gets created.

Syntax–

mv <source_file> <target_file>

Example – mv test1.dat test2.dat – here contents of test1 file gets copied to test2.dat in the same directory, and test1.dat file gets deleted.

e. Making directories – Unix also provides us with the command to make our own directory. It is just like making our own folder where all relevant files can be stored.

Syntax –

mkdir  <dir_name>

Example – mkdir /abi/sand/results – this command will create a directory at /abi/sand path . This command will not work if /abi/sand/ path doesnot exist.

2. Intermediate

a. Chmod – Sometimes, when we need to write into the file that is write-protected, we need to change the permissions given to a file or directory. Here ‘chmod’ command is used to give suitable permissions. But one should know the pattern for giving permissions.

Permissions are given as rwxrwxrwx

Intermediate

We must set permission to 1 if we need to enable it and 0 if it needs to be disable.

For instance, if one wants to only read and execute permissions to users and others but all permissions to the group. Then we must set it as ‘101111101’. And that means ‘575’ if converted to decimal in triplets. Thus for giving permissions, we give the command as

Example –

chmod 575 file1.dat

b. Find – This command is used to find the files or directories in a particular directory and its subdirectories.

Syntax –

find <options> <paths>

Example –

Option Description
-atime n Returns true if the file was accessed n days ago
-ctime n Returns true if the file was changed n days ago
-mtime Returns true if file contents were modified n days ago
-name Return true if filename matching a particular pattern
-size Returns true if the file size is n blocks.
-type c Returns true if the file being searched is of type c( if c = ‘f’ means it is a file; if it ‘d’ means it is a  directory)

Example – If someone wants to search for file names ‘test1’ in the directory, he should give a command like  –

find –type f –name test1 /abi/sand

–  This command will give all test1 file in /abi/sand directory

c. chown – change ownership of the file. Sometimes someone wants to change the owner of the file so that someone who is currently working in that file has all access to that file. Only the owner of the file has the right to change the file ownership.

Syntax:

chown [owner] [file]

Example: Change the owner of test1 to user name ‘aaggasa’, assuming that the current user currently owns it

> chown aaggasa test1

d. chgrp: change the group ownership of the file. This command is used to change the group to which the file belongs. Only the owner of the file has the right to change the file ownership.

Syntax:

chgrp [group] [file]

Example: Change the group of test1 to group2, assuming the current user currently owns it.

> chgrp group2 test1

e. Head: Unix gives us this command-line utility to extract the first part of the file. It writes the result on standard output.

Syntax –

head <option> <filename>
Option Description
-n Used to specify the number of lines to be fetched
–c Used to specify the number of bytes to be fetched.
-q Used to suppress the header line.

Example – If someone wants to extract the first 5 lines of the file, we must use

>head –n 5 /abi/sand/test1.dat

Note – By default UNIX will show 10 lines in case no option is specified with the head command.

f. Tail: Unix gives us this command-line utility to extract the first part of the file. It writes the result on standard output.

Syntax –

tail <option> <filename>
Option Description
-n Used to specify the number of lines to be fetched
–c Used to specify the number of bytes to be fetched.
-q Used to suppress the header line.

Example – If someone wants to extract the first 5 lines of the file, we must use

>head –n 5 /abi/sand/test1.dat

Note – By default UNIX will show 10 lines in case no option is specified with the head command.

3. Advanced Unix Shell Commands

a. Grep: This is a command utility that helps to search a particular pattern or character in the file. It returns all the lines that match the pattern in that particular file.

Syntax-

grep <options> <pattern> <files>
Option Description
-n Display the matched lines and their line numbers.
-v To print the lines that do not match the pattern.
-l To display the list of filenames.
-c The count of lines that matches the pattern can be extracted.
-h Display the matched lines, but do not display the filename
-i Ignores, the case for matching
-w To Match the whole word in the expression

b. ln: make links and symlinks to files and directories. A symbolic link is made up of a special type of file that contains a reference to another file. This helps to create a link between files. There are 2 types of links”-

  1. Soft link – It refers to the abstract path to a file.
  2. Hard Link – It refers to the exact location of that file,

To create a soft link ‘ln’ command is used.

Syntax –

ln -s {source_filename} {symbolic_filename}

Example – If we want to create a softlink link l1 to the path ‘/abi/sand/dir1’, then we must execute the following command:-

>ln link1 /abi/sand/dir1

This command will create a link to the directory in the current directory

To check the link execute-

ls –l

Output – lrwxrwxrwx 1 priya  priya    16 2007-09-25 22:53 link1 -> /abi/sand/dir1

c. cut –  This command utility is used to extract a particular column from a file. To extract a column, we need to specify the delimiter that will help distinguish the columns in that file.

Syntax–

cut <options> <file>
Option Description
-c For fixed-width fields, the -c option is used.
-d For specifying the delimiter. By default, the delimiter is a tab.
-b For specifying the number of bytes to be extracted
-f For specifying the field number that needs to be extracted.

Example – If someone wants to extract the second field from the ‘city.txt’ file where ‘|’ is treated as a delimiter for the columns.

cut –d "|" –f 2 city.txt

Conclusion

Unix Commands is a very powerful tool that helps the user execute the processes and do various tasks they want. Its inbuilt parser helps in development using various scripting languages. With its powerful set of commands utility, one can perform all the features even that need to read from registers.

Recommended Articles

This is a guide to Unix Shell Commands. Here we discuss the List of Unix Shell Commands (Basic, Intermediate, Advanced) with Unix Architecture. You may also have a look at the following articles to learn more –

  1. What is Unix Shell?
  2. Unix File System
  3. UNIX Administrator
  4. Unix Operators
Popular Course in this category
Red Hat Linux Training Program (4 Courses, 1+ Projects)
  4 Online Courses |  1 Hands-on Project |  29+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Linux Training Program (16 Courses, 3+ Projects)4.9
Kali Linux Training (3 Courses, 3+ Projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more