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

22BCE7182 BasicLinuxCommand

asdf

Uploaded by

rahul.22bce7182
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

22BCE7182 BasicLinuxCommand

asdf

Uploaded by

rahul.22bce7182
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

VIT-AP UNIVERSITY, ANDHRA PRADESH

Lab Sheet 1: Basic Linux commands

Branch/ Class: B.Tech Date: 10 Aug 2024

Faculty Name: Prof. Lalitha Kumari Pappala School: SCOPE

Student name: RAHUL KUMAR Reg. no.: 22BCE7182

1.) who:

• Description: Displays a list of all users currently logged into the system. It provides
information about each user's login name, terminal, login time, and potentially the
originating IP address or hostname.
• Usage: Simply run who in the terminal to see the list of logged-in users.

Example Output:

2.) whoami:

• Description: Displays the username of the current user who is executing the
command. It provides a simple way to confirm the identity of the user account
currently in use.
• Usage: Run whoami in the terminal to display your current username.

Example Output:
3.) pwd:

• Description: Displays the absolute path of the current working directory. It shows
the full path from the root directory to the directory you are currently in.
• Usage: Simply run pwd in the terminal to see the path of your current directory.

Example Output:

4.) echo:

• Description: Prints text or variables to the standard output (typically the terminal).
It is often used to display messages or the values of environment variables.
• Usage: You can use echo followed by the text or variables you want to display. For
example, echo "Hello, Rahul" will print Hello, Rahul to the terminal.

Example Output:

5.) cat:
• Description: Displays the contents of one or more files sequentially. It
concatenates the files and prints their content to the standard output (the terminal).
• Usage: Use cat followed by the file names to view their contents.

Example Output:

6.) sort:

• Description: Sorts the lines of text in a file or input stream in alphabetical or


numerical order. The sorted output is displayed to the standard output.
• Usage: Use sort followed by the file name to sort its contents.

Example Output:

By default, sort arranges lines in ascending alphabetical order. Use options like -n for
numerical sorting.
7.) grep:

• Description: Searches for lines in one or more files that match a specified pattern.
It prints the lines that contain the matching text.
• Usage: Use grep followed by the pattern and the file names.
• Basic Syntax:
grep [options] pattern [file...]

Common Options:

1. -i: Ignore case (case-insensitive search).

This will match "pattern", "Pattern", "PATTERN", etc.

2. -v: Invert match (show lines that do not match the pattern).

This will show lines in file.txt that do not contain "pattern".

3. -r or -R: Recursively search directories.

This will search for "pattern" in all files under the specified directory.

4. -n: Show line numbers along with matching lines.

This will display the line numbers where "pattern" is found.


5. -l: Print only the names of files containing the pattern.

This will list filenames of text files containing "pattern".

6. -w: Match whole words only.

This ensures that only whole words are matched, not substrings.

7. -o: Print only the matched parts of a line.

This will only print the portion of the line that matches "pattern".

8. -e: Specify multiple patterns to match. This allows searching for multiple patterns.

8.) clear:
• Description: Clears the terminal screen, removing all previous commands and
output from view.
• Usage: Simply run clear in the terminal.

Effect: The terminal screen will be cleared, leaving you with a clean prompt.

9.) ls:
o Description: Lists files and directories in the specified directory. By default,
it lists the contents of the current directory.
o Usage: Run ls to view the files and directories.
Options:

o -I: Lists files excluding files that match a pattern (typically -I is used with a
pattern, not I alone).
o -r: Reverses the order of the sort.
o -F: Appends a character to each entry to indicate its type (e.g., / for
directories).
o

10.) date:

• Description: Displays the current date and time.


• Usage: Simply run date to see the current date and time.

Example Output:

11.) mkdir:
• Description: Creates a new directory with the specified name.
• Usage: Use mkdir followed by the directory name to create it.

Example: Creates a directory name new_directory.

12.) mv:
• Description: Moves or renames files or directories. It can also be used to move files
between directories.
• Usage: Use mv followed by the source file(s) and the destination.

Example:

13.) rm:

• Description: Removes (deletes) files or directories. It can delete multiple files at


once or recursively delete directories with the -r option.
• Usage: Use rm followed by the file names or directories to remove them.

Example: Deletes file.txt or removes the directory directory and its contents.

14.) cd:

• Description: Changes the current working directory to a specified directory.


• Usage:
o cd : Moves to the root directory.
o cd .. : Moves up one directory level to the parent directory.
o cd directory_name: Moves to the specified directory within the current
directory.

Examples:
15.) cp:

• Description: Copies files or directories from a source to a destination. It creates an


exact copy of the source file(s) or directory.
• Usage: Use cp followed by the source file(s) and the destination.

Examples:

16.) touch:

• Description: Updates the access and modification times of files. If the file does not
exist, touch creates an empty file with the specified name.
• Usage: Use touch followed by the file names.

Example: Creates file1.txt and file2.txt if they do not exist, or updates their timestamps if
they do.
17.) man:

• Description: Displays the manual (help) page for a specified command. It provides
detailed information about how to use the command and its options.
• Usage: Use man followed by the command name.

Example: Shows the manual page for the mv command.

18.) banner:

• Description: Displays text in a large, banner-style format. This command is useful


for creating visually prominent text.
• Usage: Use banner followed by the text you want to display.

Example: Shows "r" in large text on the screen.


19.) cal:

• Description: Displays a calendar for a specified month and year. If no arguments


are provided, it shows the current month's calendar.
• Usage:
o cal: Shows the current month's calendar.
o cal month year: Shows the calendar for a specific month and year.

Example:

Output:
20.) lock:

• Description: The lock command is used to lock the terminal session to prevent
unauthorized access. This command is not as commonly used as vlock, but it is
available on some systems for locking the terminal.
• Options:
o -t: May specify a timeout or other locking behavior, but the exact usage can
vary depending on the system and implementation.
• Usage: Typically used in systems where you want to temporarily lock the terminal to
secure it from unauthorized access.

Example: This command locks the terminal session. You will need to unlock it by providing
your user credentials.

21.) logname:

• Description: Displays the login name of the user currently logged into the system.
This is the username associated with the current login session.
• Usage: Simply run logname to display the login name.

Example Output:

This output shows the login name of the user.


22.) script:

• Description: Records a terminal session, including all keystrokes and the resulting
output, to a file. This can be useful for creating a record of a session or debugging
purposes.
• Usage: Use script followed by the name of the file where the session will be
recorded. By default, the file is named typescript.

Example:

script my_session.log

o To stop recording, simply type exit or press Ctrl+D.

23.) df:
• Description: Displays the disk space usage of file systems. It provides
information on the total space, used space, and available space on all mounted
file systems. This is useful for monitoring disk usage and ensuring that your
system doesn't run out of space.
• Usage: Simply run df to see the disk space usage. For a more human-readable
format (e.g., showing sizes in MB or GB), use the -h option:

24.) du:

• Description: Estimates the disk space usage of files and directories. This command
shows the space used by each file and directory within a specified directory,
allowing you to identify which files or directories are consuming the most space.
• Usage: Use du to check disk usage for a specific directory. To get a summary in a
human-readable format, use the -sh option:

25.) uname:

Description: Displays system information, such as the operating system name, version,
and other details about the system architecture. This command is useful for quickly
identifying the type of system you are working on.

Usage: Simply run uname to display the operating system name. For more detailed
information, use the -a option:
This will provide a complete overview, including the kernel version, system architecture,
and more.

Here are the commands with their one-line summaries:

1. who: Lists all users currently logged in with details about their login.

2. whoami: Shows the username of the current user.

3. pwd: Displays the absolute path of the current directory.

4. echo: Prints text or variables to the terminal.

5. cat: Displays the contents of one or more files.

6. sort: Sorts lines in a file or input stream in alphabetical or numerical order.

7. grep: Searches for lines matching a pattern in files.

8. clear: Clears the terminal screen.

9. ls: Lists files and directories in the specified directory.

10. date: Displays the current date and time.

11. mkdir: Creates a new directory.

12. mv: Moves or renames files or directories.

13. rm: Removes files or directories.

14. cd: Changes the current working directory.

15. cp: Copies files or directories from a source to a destination.


16. touch: Updates file timestamps or creates new files.

17. man: Displays the manual page for a command.

18. banner: Displays text in a large, banner-style format.

19. cal: Shows a calendar for a specific month and year.

20. lock: Locks the terminal session to prevent unauthorized access.

21. logname: Displays the login name of the current user.

22. script: Records a terminal session to a file.

23. df: Displays the disk space usage of file systems.

24. du: Estimates the disk space usage of files and directories.

25. uname: Displays system information, including OS name and version.

You might also like