type Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

The type command in Linux is a shell built-in command used to determine the type of command for a given command name. This command allows you to distinguish between shell built-ins, aliases, files on the disk, and keywords, thus it plays a crucial role in understanding and troubleshooting shell scripts.

Syntax of type Command in Linux

The basic syntax of the type command in Linux is as follows:

Where:

  • type: The command itself, used to determine the command type.
  • [-aftpP]: Options to modify the behavior of the type command.
  • [name ...]: The command name for which you want to determine the type.
Sharpen Your Fundamentals with Free Learning

Options in type Command in Linux

  1. -a: This option prints all locations containing an executable named 'name'. This includes aliases and functions, if and only if the '-p' option is not also used.

    For example -

    Output:

    The 'ls' command is an alias and also an executable located at /bin/ls.

  2. -t: If the '-t' option is used, 'type' outputs a single word indicating the command type. The possible output words are 'alias', 'keyword', 'function', 'builtin', 'file' or 'not found'.

    For example -

    Output:

    The 'echo' command is a shell builtin.

  3. -p: The '-p' option returns either the name of the disk file that would be executed, or nothing if 'type -t name' would not return 'file'.

    For example -

    Output:

    The 'ls' command would execute the disk file located at /bin/ls.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Find the type of the 'pwd' command.:

    Output:

    Explanation: The 'pwd' command is a shell builtin.

  • Use type command to find whether 'ls' is an alias or an executable.:

    Output:

    Explanation: The 'ls' command is both an alias and an executable located at /bin/ls.

Tips

  • Use type with the '-a' option to get all information about a command.

  • Use 'type -p' to know the path of the executable file for the given command.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of type Command in Linux

  • Find the type of multiple commands at once:

    Output:

    Explanation: The 'ls' command is an alias and an executable, whereas 'pwd' and 'echo' are shell builtins.

  • Use type to find out whether a command is a function:

    Output:

    Explanation: The command 'someFunction' is a function.

  • Use type to find out if a command doesn't exist:

    Output:

    Explanation: The command 'nonExistentCommand' does not exist.

Conclusion

  • The type command in Linux is a powerful tool for understanding and debugging shell scripts.

  • It helps you distinguish between built-in commands, aliases, files on disk, and keywords.

  • You can also use it to find the path of the executable file for a given command.