Basic Unix Commands
Basic Unix Commands
In this tutorial, we will see how to log into and log out of Unix. We will also cover some
basic Unix commands like cal, date, and banner.
Unix Processes
A process is a context in which a program executes. Every time when a command or
program is run, a new process is created. The process is active for as long as the
program is in an active state.
For Example, if we are executing the cat command then a process named “cat” is
generated.
Each time a new process is created, the Kernel assigns a unique identification number
called the PID i.e. process identification number) which lies in between 0 to 32,767.
Other properties of processes include their PPID (Parent PID), TTY (the controlling
terminal from where they were launched), UID (the user id that owns this process) and
GID (the group that is associated with the process).
In Unix, the processes have a hierarchical relationship, where a parent process spawns
the child processes. The ‘init’ process is the grandfather process of all the other
processes. In some cases, where the parent process is killed before the child process,
the child is called an orphan process.
Example $ ps -ef
Example $ top
Example $ xterm
Ctrl-Z
$ bg
Continue running a job that was previously suspended (using Ctrl-Z) in the backgro
Command fg - bring a background job to the foreground
Example $ xterm
Ctrl-Z
$ bg
$ fg
Example $ clear
Example $ history
Unix Commands
#1) ls: List directory contents
Syntax: ls [OPTION] [FILE]
Example: list all (including hidden files) directory contents, in long format, sorted
by time,
$ ls -alt
#2) which: Locate a command
Syntax: which [-a] filename
Example: List all paths from where ‘cat’ can run
$ which -a cat
#3) man: Interface for working with the online reference manuals.
Syntax: man [-s section] item
Example: Show manual page for the ‘cat’ command
$ man cat
#4) su: Change user-id or become super-user.
Syntax: su [options] [username]
Example: Change user-id to ‘user1’ (if it exists)
$ su user1
#5) sudo: Execute a command as some other user or super-user
Syntax: sudo [options] [command]
Example: Get a file listing of an unlisted directory
$ sudo ls /usr/local/protected
#6) find: Used to search for files and directories as mentioned in the ‘expression’
Syntax: find [starting-point] [expression]
Example: In ‘/usr’ folder, find character device files, of name ‘backup’
$ find /usr -type c -name backup
#7) du: Estimate disk usage is blocks
Syntax: du [options] [file]
Example: Show number of blocks occupied by files in the current directory
$ du
#8) df: Show number of free blocks for mounted file system
Syntax: df [options] [file]
Example: Show number of free blocks in local file systems
$ df -l