0% found this document useful (0 votes)
12 views22 pages

Operating-System Lab 4

The document provides an overview of basic command-line commands in Linux, including how to display the date, calendar, disk space, and memory. It also explains the hierarchical filesystem structure and the use of wildcards for file matching. Additionally, it covers commands for creating aliases, viewing manual pages, and searching for keywords in manual pages.

Uploaded by

mr3370628
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views22 pages

Operating-System Lab 4

The document provides an overview of basic command-line commands in Linux, including how to display the date, calendar, disk space, and memory. It also explains the hierarchical filesystem structure and the use of wildcards for file matching. Additionally, it covers commands for creating aliases, viewing manual pages, and searching for keywords in manual pages.

Uploaded by

mr3370628
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Operating System:

Lab 4
Basic Command-Line Commands

Displaying Date and Time Displaying the Calendar

Command: date Command: cal

Description: This command displays the current date and Description: This command displays the calendar of the
time of the system. current month by default.

Example: [me@linuxbox ~]$ date Example: [me@linuxbox ~]$ cal

Output: Thu Oct 25 [Link] EDT 2012 Output: October 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9


10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Explanation: The output shows the day of the week (Thu),
31
month (Oct), day of the month (25), time ([Link]), time
zone (EDT), and year (2012). Explanation: The output shows the calendar for October 2012.
Basic Command-Line Commands

Displaying Free Disk Space Displaying Free Memory

Command: df Command: free

Description: This command displays information about free and used Description: This command displays information about free and used
disk space on the system's drives. memory in the system.

Example: [me@linuxbox ~]$ df Example: [me@linuxbox ~]$ free

Output: Filesystem 1K-blocks Used Available Use% Mounted on Output: total used free shared buffers cached Mem: 513712 503976
/dev/sda2 15115452 5012392 9949716 34% / /dev/sda5 59631908 9736 0 137964 947536 -/+ buffers/cache: 375748 137964 Swap:
26545424 30008432 47% /home /dev/sda1 147764 17370 122765 13% 1052248 104712 947536
/boot tmpfs 256856 0 256856 0% /dev/shm
Explanation: The output provides information about physical memory
Explanation: The output provides information about the file system, (Mem) and swap space (Swap), including total, used, and free memory.
total space (1K-blocks), used space (Used), available space
(Available), usage percentage (Use%), and mount point (Mounted on).
Basic Command-Line Commands

Ending a Terminal Session Viewing File Contents with less

Command: exit Command: less /etc/passwd

Description: This command ends the current terminal Description: This command displays the contents of the
session. /etc/passwd file, which contains user information.

Example: [me@linuxbox ~]$ exit Example: [me@linuxbox ~]$ less /etc/passwd

Explanation: After executing this command, the terminal


window will close. Explanation: This command opens the /etc/passwd file in
the less program, allowing for navigation within the file.
Task
1) Check today's date
2) Look at this month's calendar
3) See how much disk space you have
4) Check your computer's memory
5) Create a folder for your work
6) Move into your new folder
7) Create a simple text file
8) Look at your file
9) When finished, exit the terminal
The Hierarchical Filesystem

1 The root directory (/) is the starting 2 Subdirectories branch out from the
point of the filesystem. root, organizing files and folders.

3 Each directory contains files and 4 PAGE UP or b: Scroll back one page.
subdirectories, forming a hierarchical
structure.

5 PAGE DOWN or Spacebar: Scroll forward 6 Up Arrow: Scroll up one line.


one page.

7 Down Arrow: Scroll down one line. 8 G: Move to the end of the file.

9 1G or g: Move to the beginning of the 10 /characters: Search for text.


file.

11 n: Search for the next occurrence.


The Hierarchical Filesystem

1 /bin (Binaries): Contains essential programs 2 /boot (Boot Files): Stores the Linux kernel and
required for booting and running the system. boot loader configuration files.

3 • /dev (Device Files): Represents hardware devices as files. 4 /etc (Configuration Files): Contains system-wide
configuration settings.

5 /home (User Home Directories): Each user has a 6 /mnt & /media (Mount Points): Used for
directory to store personal files. mounting removable storage devices.

7 /lib (Libraries): Stores essential shared libraries. 8 /opt (Optional Software): Used for installing
additional software packages.

9 /proc (Process Information): A virtual filesystem 10 /sbin (System Binaries): Stores essential system
providing process and system information. administration commands.

11 /tmp (Temporary Files): Used for temporary file 12 /usr (User Programs): Contains user utilities,
storage. libraries, and documentation.

13 /var (Variable Data): Stores log files, databases, and spool files.
Using Wildcards in Linux
Wildcards (also known as globbing) are special characters used to match file names or patterns.

1 * 2 ?

Matches any number of characters (e.g. file* matches Matches a single character (e.g. file?.txt matches [Link]
file1, file2, fileABC). but not [Link]).

3 [abc] 4 [!abc]

Matches any one of the characters inside the brackets Matches any character not inside the brackets (e.g.
(e.g. file[12].txt matches [Link] and [Link]). file[!12].txt matches [Link] but not [Link]).

5 [[:digit:]]

Matches any numeric digit.


Command :less
Wildcard Examples:
Pattern Matches

*.txt All .txt files

data* Files starting with data

b*.log Files starting with b and ending in .log

backup.[0-9][0-9][0-9] Files like backup.001, backup.123

[[:upper:]]* Files starting with an uppercase letter

*[[:lower:]123] Files ending with a lowercase letter or 1, 2, 3


Linux file system concepts

Command: type Command: which

Description: Displays how a command name is Description: Locates the executable file associated
interpreted by the shell. with a command.

Example: [me@linuxbox ~]$ type ls Example: [me@linuxbox ~]$ which ls

Output: ls is aliased to 'ls -- Output: /usr/bin/ls


color=auto' (or ls is /usr/bin/ls)
Explanation: The output shows the full path to the
Explanation: The output shows that ls is an alias ls executable.
or the path to the executable.
Linux file system concepts

Command: man Command: apropos

Description: Displays the manual page for a command. Description: Searches manual pages for keywords.

Example: [me@linuxbox ~]$ man ls Example: [me@linuxbox ~]$ apropos file

Output: (Displays the manual page for the ls Output: (Displays a list of manual pages containing the
command) word "file")

Explanation: This command opens the manual page in Explanation: The output lists commands related to
the terminal, providing detailed information about the "file" based on their manual page descriptions.
ls command.
Command :man ls
Command :apropos
Command :apropos password
Linux file system concepts

1. Command: alias 2. Command: grep

Description: Creates a shortcut for a command. Description: Prints lines matching a pattern.

Example: [me@linuxbox ~]$ alias ll='ls -l' Example: [me@linuxbox ~]$ grep "pattern" [Link]

Explanation: This command creates an alias named Output: (Displays a list of manual pages containing
ll that executes ls -l. the word "file")

3. Command: echo Explanation: The output lists commands related to


"file" based on their manual page descriptions.
Description: the echo used to display a line of text
or variable to the standard output
Command :alias & grep

You might also like