Sei sulla pagina 1di 4

Internal and External Commands in Linux

The UNIX system is command-based i.e things happen because of the commands that you key in.
All UNIX commands are seldom more than four characters long.
They are grouped into two categories:

Internal Commands : Commands which are built into the shell. For all the shell built-in
commands, execution of the same is fast in the sense that the shell doesn’t have to search the given
path for them in the PATH variable and also no process needs to be spawned for executing it.
Examples:

1.cd
cd is among the commands you will use most often on the command line. It changes your working
directory. Use it to move around within the hierarchy of your file system.

Syntax:
cd [-L | -P [-e]] directory

Ex. cd documents/work/accounting

2.mkdir
The mkdir command creates new directories in your file system.

Syntax:

mkdir [-m=mode] [-p] [-v] [-Z=context] directory [directory ...]

Ex. mkdir myfiles

3.Echo
The echo program displays text. It's a handy way to create customized output in your terminal.

Syntax:

echo [SHORT-OPTION]... [STRING]...

Ex. echo Hello, world!


4.type
The type command is used to find out if command is builtin or external binary file. It also indicate
how it would be interpreted if used as a command name.

Syntax:

type [OPTION]..

Example:

Type the following command at a shell prompt:


type ls

5.pwd
Print the name of the working directory.

Syntax:

pwd [OPTION]..

example:

Print the name of the working directory.


Pwd

External Commands : Commands which aren’t built into the shell. When an external
command has to be executed, the shell looks for its path given in PATH variable and also a new
process has to be spawned and the command gets executed. They are usually located in /bin or
/usr/bin. For example, when you execute the “cat” command, which usually is at /usr/bin, the
executable /usr/bin/cat gets executed.
Examples:

1.ls
ls” command is used to list directory contents. This post describes “ls” command used in Linux
along with usage examples and/or output.

Usage:
ls [OPTION]… [FILE]..

Ex. To display total information about Files/Directories(ls -l):


sanfoundry-> ls -l
total 8
-rw-rw-r-- 2 him himanshu 12 Jul 1 23:11 1.txt
-rw-rw-r-- 2 him himanshu 0 Jul 1 23:11 2.txt
drwxrwxr-x 2 him himanshu 4096 Jul 6 19:25 hello
drwxrwxr-x 2 him himanshu 4096 Jul 6 19:25 sample

2.cat
cat stands for "catenate." It reads data from files, and outputs their contents. It is the simplest way
to display the contents of a file at the command line.

Examples:Displaying Text Files

The simplest way to use cat is to give it the name of a text file. It will display the contents of the
text file on the screen. For instance:
cat mytext.txt

3.Find
find searches for files in a directory hierarchy.
find syntax:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]

Ex.
Locate and print all files and directories in and beneath three different starting directories: the
current directory, /home/jeff, and /home/stacy.
find /usr/bin /usr/lib -name '*zip*'

4.sort
sort is a simple and very useful command which will rearrange the lines in a text file so that they
are sorted, numerically and alphabetically.
sort syntax:
sort [OPTION]... [FILE]...

Example:
Let's say you have a file, data.txt, which contains the following ASCII text:
apples
oranges
pears
kiwis
bananas

To sort the lines in this file alphabetically, use the following command:
sort data.txt

..which will produce the following output:


apples
bananas
kiwis
oranges
pears

5.man
On Linux and other Unix-like operating systems, man is the interface used to view the system's
reference manuals.

Syntax:
man -k [apropos options] regexp ...
example:
man man

View the manual page for the man command.

Potrebbero piacerti anche