15 Basic Unix Commands One Must Know

A command is an instruction given by a user to a computer to do something, such as to print number of files in a directory. Commands are generated by typing them in at the command line or command prompt(in Windows) and then pressing the ENTER key, which passes them to the shell. Here I will be showing some very important Linux commands.

 

What is a shell?

A shell is a program that reads commands that are typed on a keyboard and then executes (i.e., runs) them. So, shells are the most basic method for a user to interact with the system.

Every Unix-like operating system has at least one shell, and most have several. The default shell on most Linux systems is the bash shell. Some other types of shells are:

  1. Bourne shell,
  2. C shell, and
  3. Korn shell.

 

Unix/Linux Commands

Now let us look into some of the commands that one must know while using any types of Unix based operating systems. These commands are unavoidably important to know.

 

Note: Here I have used square brackets [] to indicate parameters that a command can take.

 

1. man [command]

Shows all information about the command.

Example: ls is a command in Unix. If you want to know what really is its purpose, type the command shown below and press Enter:

man ls

 

2. ls [option(s)] [file(s)]

ls command can be used in many ways and for many purposes. Some of them are:

A. ls command without any parameters lists the contents of the directory in short form.

Example: if your present working directory(pwd) is user use the ls command and hit enter. It would display all the files and directories present there.

ls

B. ls –l [file] displays the detailed list of the contents of the directory.

C. ls –a [file] displays the hidden files.

 

3. cd [directory name]

Change directory to [directory name]

Example:

cd /usr/dir1

 

4. pwd

print the name of the current working directory

 

5. mkdir [directory name]

make directories

Example: To create a directory named sonam:

mkdir sonam

 

6. cp [option(s)] sourcefile targetfile

cp copies file from a source to a destination.

cp –i sourcefile targetfile waits for confirmation, if necessary before an existing target file is overwritten.

cp –r sourcefile targetfile copies recursively (includes subdirectories).

 

7. mv [option(s)] sourcefile targetfile

mv copies soucefile to targetfile then deletes the original sourcefile.

mv -b sourcefile targetfile creates a backup copy of the sourcefile before moving.

mv -i  sourcefile targetfile waits for confirmation, if necessary before an existing target file is overwritten.

 

8. rm [option(s)] files(s)

rm removes the specified files from the file system.

rm -r file deletes any existing subdirectories.

rm -i file waits for confirmation before deleting each file.

Example:

rm –r sonam

 

9. ln [option(s)] sourcefile targetfile

ln creates an internal link from the sourcefile to the targetfile, under a different name.

ln -s sourcefile targetfile creates a symbolic link.

Example:

ln a.txt c.txt

 

10. ps [option(s)] [process ID]

if run without any options displays a table of all of the processes. (Options for this command are not preceded by hyphen).

ps aux [process ID] displays a detailed list of all processes, independent of the owner.

Example:

ps

 

11. kill [option(s)] [process ID]

kill command terminates the processes in during abnormal conditions.

kill -9 [process ID] brings the specific processes to an end in almost all the cases.

Example: To kill the process with process id (PID) 3499 forcefully

kill -9 3499

 

12. history

prints recently used commands,

Example:

history

 

Commands to Create Files

Sometimes it can be very important to know the file system commands. Though I will be sharing a post completely about files, I find it important to know the following commands at this stage itself. So, let us look in these commands.

 

13. touch [filename(s)]

Create multiple files at a time.

Example: To create files d.txt e.txt and f.txt at the same time:

touch d.txt e.txt f.txt

 

14. cat [OPTION] [FILE]

Concatenate files and print on the standard output

Example:

cat file1.txt file2.txt

 

15. vi filename

A programming text editor

Example: To create a file named hello with extension c using vi editors:

vi hello.c

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top