22BCE7182 BasicLinuxCommand
22BCE7182 BasicLinuxCommand
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:
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:
2. -v: Invert match (show lines that do not match the pattern).
This will search for "pattern" in all files under the specified directory.
This ensures that only whole words are matched, not substrings.
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:
Example Output:
11.) mkdir:
• Description: Creates a new directory with the specified name.
• Usage: Use mkdir followed by the directory name to create it.
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:
Example: Deletes file.txt or removes the directory directory and its contents.
14.) cd:
Examples:
15.) cp:
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.
18.) banner:
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:
• 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
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.
1. who: Lists all users currently logged in with details about their login.
24. du: Estimates the disk space usage of files and directories.