Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
82 views

Basic Unix Commands

The document discusses basic Unix commands like cal, date, banner, who, and whoami. It provides the syntax and examples of using each command. It also covers logging into and out of Unix, and manipulating processes through commands like ps, top, bg, fg, clear, and history.

Uploaded by

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

Basic Unix Commands

The document discusses basic Unix commands like cal, date, banner, who, and whoami. It provides the syntax and examples of using each command. It also covers logging into and out of Unix, and manipulating processes through commands like ps, top, bg, fg, clear, and history.

Uploaded by

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

Basic Unix Commands (Part A)

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.

#1) cal: Displays the calendar.


 Syntax: cal [[month] year]
 Example: display the calendar for April 2018
 $ cal 4 2018
#2) date: Displays the system date and time.
 Syntax: date [+format]
 Example: Display the date in dd/mm/yy format
 $ date +%d/%m/%y
#3) banner: Prints a large banner on the standard output.
 Syntax: banner message
 Example: Print “Unix” as the banner
 $ banner Unix
#4) who: Displays the list of users currently logged in
 Syntax: who [option] … [file][arg1]
 Example: List all currently logged in users
 $ who
#5) whoami: Displays the user id of the currently logged in user.
 Syntax: whoami [option]
 Example: List currently logged in user
 $ whoami

#1) touch: Create a new file or update its timestamp.


 Syntax: touch [OPTION]…[FILE]
 Example: Create empty files called ‘file1’ and ‘file2’
 $ touch file1 file2
#2) cat: Concatenate files and print to stdout.
 Syntax: cat [OPTION]…[FILE]
 Example: Create file1 with entered cotent
 $ cat > file1
 Hello
 ^D
#3) cp: Copy files
 Syntax: cp [OPTION]source destination
 Example: Copies the contents from file1 to file2 and contents of file1 is retained
 $ cp file1 file2
#4) mv: Move files or rename files
 Syntax: mv [OPTION]source destination
 Example: Create empty files called ‘file1’ and ‘file2’
 $ mv file1 file2
#5) rm: Remove files and directories
 Syntax: rm [OPTION]…[FILE]
 Example: Delete file1
 $ rm file1
#6) mkdir: Make directory
 Syntax: mkdir [OPTION] directory
 Example: Create directory called dir1
 $ mkdir dir1
#7) rmdir: Remove a directory
 Syntax: rmdir [OPTION] directory
 Example: Create empty files called ‘file1’ and ‘file2’
 $ rmdir dir1
#8) cd: Change directory
 Syntax: cd [OPTION] directory
 Example: Change working directory to dir1
 $ cd dir1
#9) pwd: Print the present working directory
 Syntax: pwd [OPTION]
 Example: Print ‘dir1’ if a current working directory is dir1
 $ pwd

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.

#1) Foreground Process


A process that is launched from a terminal and disallows further commands until it
completes. In such a process, the stdin and stdout are attached to the terminal by
default.

#2) Background Process


It is a process that was launched from a terminal, but is run in the background, thus
allowing further commands while it runs. In such a process, the stdin and stdout should
typically be redirected so they don’t interfere with other foreground processes.

#3) Daemon Process


It is a process that is not associated with a terminal session. Such processes are usually
launched for system services such as networking and printing.
In this tutorial, we will cover control commands, as well as the other commands
that are used to manipulate the processes.
Control Commands
These commands are a two-key combination where a letter is pressed simultaneously
with the ‘Ctrl’ key.

 Control-C: This command terminates the currently running foreground process.


 Control-D: This command terminates the currently running login or terminal
session.
 Control-Z: This command suspends the currently running foreground process to
the background.
Other Commands:
Command ps - displays a snapshot of all current processes

Common Syntax $ ps [options]

Example $ ps -ef

Show every process running, formatted as a table

Command top - displays a live status of current processes

Common Syntax $ top [options]

Example $ top

Show a live view of all current processes

Command bg - resume a background suspended a job

Common Syntax $ bg [job_spec …]

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

Common Syntax $ fg [job_spec]

Example $ xterm
Ctrl-Z
$ bg
$ fg

Bring a previous background job to the foreground

Command clear – clear a terminal screen

Common Syntax $ clear

Example $ clear

Clear all prior text from the terminal screen

Command history – print history of commands in the current session

Common Syntax $ history [options]

Example $ history

Show list of previous commands that were entered

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

You might also like