0% found this document useful (0 votes)
90 views

Basic Unix Commands

The document provides an overview of basic Unix commands, including commands for viewing system information, manipulating files and directories, and managing processes. It describes the purpose, syntax, and examples of many common Unix commands like ls, cat, mkdir, rm, cp, mv, pwd and more.

Uploaded by

Poornima Eg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Basic Unix Commands

The document provides an overview of basic Unix commands, including commands for viewing system information, manipulating files and directories, and managing processes. It describes the purpose, syntax, and examples of many common Unix commands like ls, cat, mkdir, rm, cp, mv, pwd and more.

Uploaded by

Poornima Eg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Basic Unix Commands

What is Unix Command?


The below article gives an overview of Unix commands. An OS providing both command line
interface (CLI) and graphical user interface (GUI) based interaction integrated by Dennis
Ritchie, Douglas Mcllroy, Joe Ossanna Brian Kernighan, and Ken Thompson at Bell laboratory
in 1970 called a multi-tasking operating system permitting two or more users to simultaneously
operate on the operating system and offers commands for the users for interacting with the
application from command line interface, such as sudo command, chmod command, su
command, mv command, rm command, vi command, cat command, rmdir command, mkdir
command, clear command, and ls command, which can be used to implement complex tasks.

Introduction to Unix
Unix is an OS that provides both CLI and GUI-based interaction. It was developed by Dennis
Ritchie in the C language. Unix operating system is multitasking, which also gives an
opportunity for two or more users to use its benefits. In other words, it is a multi-user OS.
Ubuntu OS is a Unix version that enables us to do every work that Unix is supposed to do.

Hence, it's recommended by professionals who operate with servers; it's also recommended to
learn how the command-line-based operating system works. Many large and complex
applications that utilize Unix to execute because of its aspect to handle the processes easily. It's a
bit faster and provides a nice user experience when compared with the Windows operating
system.

Several testing activities, such as performance and installation testing, depending on OS


knowledge. Almost every web server is Unix based nowadays. So, knowledge of Unix is
essential for testers. If we are unfamiliar with Unix, then learning Unix commands can be a great
start. One of the best ways to understand these commands is to practice and read them
simultaneously on Unix OS.

Basic Commands in Unix


cal: This command is used to show the calendar.
Syntax:

cal [[month] year]


Examples: If we need to show the calendar for March 2018, we can use the following Unix
command:

$ cal 3 2018
date: It is used to show the system time and date.
Syntax:
date [+format]
Examples: If we need to show the date in dd/mm/yy format, we can use the following Unix
command:

$ date +%d/%m/%y
banner: It is used to show a large banner on a standard output.
Syntax:

banner message
Example: We can use the below command to print "Example" as a banner:

$ banner Example
who: This command is used to show the user's list logged in currently.
Syntax:

who [option] ... [file][arg1]


Example: We can use the following command to list every user logged in currently:

$ who
whoami: This command is used to show the user id logged in currently.
Syntax:

whoami [option]
Example: We can use the following command to list the users logged in currently:

$ whoami
touch: It creates a new file or upgrades its timestamp.
Syntax:

touch [OPTION]...[FILE]
Example: We can use the following command to make empty files:

$ touch file1 file2


cat: This command is used to concatenate files and display them on stdout.
Syntax:

cat [OPTION]...[FILE]
Example: We can use the following command to make a file along with entered content:

$ cat > file1


Hello
^D
copy: This command is used to copy files.
Syntax:

cp [OPTION]source destination
Examples: We can use the following command to copy the contents of text1 and text2, and the
contents of text1 are retained:

$ cp text1 text2
mv: This command is used to rename files or move files.
Syntax:

mv [OPTION]source destination
Examples: We can use the following command to make empty files known as text1 and text2:

$ mv text1 text2
rm: This command is used to remove directories and files.
Syntax:

rm [OPTION]...[FILE]
Example: We can use the following command to delete text1:

$ rm file1
mkdir: It creates a directory.
Syntax:

mkdir [OPTION] directory


Example: We can use the following command to make a directory:

$ mkdir direct1
mkdir: It removes a directory.
Syntax:

rmdir [OPTION] directory


Example: We can use the following command to make empty files:

$ rmdir direct1
cd: It changes the directory.
Syntax:

cd [OPTION] directory
Example: We can use the following command to change our working directory:

$ cd direct1
pwd: It prints the current working directory.
Syntax:

pwd [OPTION]
Example: We can use the following command to print "direct1" if our current working directory
is "direct1":

$ pwd
What is the Unix process?
A program runs in a process. Each time when a program or command is run, a fresh process is
established. The process is running for as long as the command is in an active state. For instance,
if we are running the command, i.e., cat, the cat process is generated.

The kernel assigns a special identification number known as the PID or process identification
number, which ranges between 0 to 32,767 every time a fresh process is established. Other
process properties include their GID (group related to the process), UIS (user id owns the
process), TTY (controlling terminal through where they're launched), and PPID (the parent PID).

A process has a hierarchical relationship in Unix, where a parent process generates the child
process. The process, i.e., init, is the grandfathering process of every other process. In a few
cases, the child is known as an orphan process.

Process Types in Unix


Foreground Process: A foreground process is launched through a terminal and denies further
commands until it ends. By default, the stdout and stdin are associated with the terminal in such
a process.
Background Process: This process is launched through a terminal but is executed in the
background. Hence, permitting further commands while it executes. The stdout and stdin should
be typically redirected, so they do not interfere with another foreground process.
Daemon Process: It's a process that's not related to the terminal session. Usually, such processes
are released for system services like printing and networking.
Control Commands
The control commands are a two-key combination in which a letter is simultaneously pressed
using the 'Ctrl' key.

Control-Z: It suspends the currently active foreground process to the background.


Control-D: It removes the currently active terminal or login session.
Control-C: It removes the currently active foreground process.
Other commands:

ps: It shows a snapshot of every current process.


Syntax:

$ ps [options]
Example,

$ ps -ef
The above command will display all running processes formatted as a table.

top: It shows a live current process status.


Syntax:

$ top [options]
Example,

$ top
The above command will display a live view of every current process.

bg: It regains a background suspended a job.


Syntax:

$ bg [job_spec...]
Example,

$ xterm
Ctrl-Z
$ bg
The above command will continue executing a job that was suspended in the background
previously.

fg: It brings a job to the foreground from the background.


Syntax:

$ fg [job_spec...]
Example,

$ xterm
Ctrl-Z
$ bg
$ fg
The above command will bring a previous job to the foreground from the background.

clear: It clears the terminal screen.


Syntax:

$ clear
Example,

$ clear
The above command will clear every prior text through the terminal window.

history: It prints the command history in the current active session.


Syntax:

$ top [options]
Example,

$ clear
The above command will display the list of old commands that were enrolled.

ls: It lists the contents of the directories.


Syntax:

$ ls [options] [FILE]
Example,

$ ls -alt
The above command will list every content of a directory in a long way sorted by time.

which: It locates the commands.


Syntax:

$ which [-a] filename


Example,

$ which [-a] cat


The above command will list every path from where 'cat' can execute.

man: It is an interface to work with online reference manuals.


Syntax:
$ man [-s section] item
Example,

$ man cat
The above command will display the manual page for 'cat'.

su: It modifies user-id and becomes a super or root user.


Syntax:

$ su [options] [username]
Example,

$ su user1
The above command will modify the specified user-id.

sudo: It runs the command as other super-users or users.


Syntax:

$ sudo [options] [command]


Example,

$ sudo ls /usr/local/protected
The above command will get the file listing of the unlisted directory.

find: This command is used to find directories and files.


Syntax:

$ find [starting-point] [expression]


Example,

$ find /usr -type c -name text


The above command will search for character device files of the 'text' name in the '/usr' folder.

du: It estimates the disk usage blockage.


Syntax:

$ du [options] [file]
Example,

$ du
The above command will display the total blocks utilized by files within the current directory.

df: This command displays the total free blocks for a mounted file system.
Syntax:

$ df [options] [file]
Example,

$ df -l
The above command will show the total free blocks inside the local file systems.

You might also like