Basic Unix Commands
Basic Unix Commands
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.
$ 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
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:
cat [OPTION]...[FILE]
Example: We can use the following command to make a file along with entered content:
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 direct1
mkdir: It removes a directory.
Syntax:
$ 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.
$ ps [options]
Example,
$ ps -ef
The above command will display all running processes formatted as a table.
$ top [options]
Example,
$ top
The above command will display a live view of every current process.
$ bg [job_spec...]
Example,
$ xterm
Ctrl-Z
$ bg
The above command will continue executing a job that was suspended in the background
previously.
$ fg [job_spec...]
Example,
$ xterm
Ctrl-Z
$ bg
$ fg
The above command will bring a previous job to the foreground from the background.
$ clear
Example,
$ clear
The above command will clear every prior text through the terminal window.
$ top [options]
Example,
$ clear
The above command will display the list of old commands that were enrolled.
$ ls [options] [FILE]
Example,
$ ls -alt
The above command will list every content of a directory in a long way sorted by time.
$ man cat
The above command will display the manual page for 'cat'.
$ su [options] [username]
Example,
$ su user1
The above command will modify the specified user-id.
$ sudo ls /usr/local/protected
The above command will get the file listing of the unlisted directory.
$ 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.