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

Linux Command

Uploaded by

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

Linux Command

Uploaded by

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

Linux

Command
Lecture CheckList
1. Introduction.

2. Linux commands.
Introduction
Linux is a powerful open-source operating system that has gained widespread
popularity over the years. It was created in 1991 by Finnish programmer Linus
Torvalds, who originally developed it as a hobby project. Today, Linux powers
various devices, from smartphones and laptops to servers and supercomputers.
One thing that makes Linux stand out is its extensive command-line interface, which
allows users to perform a wide range of tasks quickly and efficiently.

Linux commands are a set of powerful tools that allow users to interact with the
operating system and perform various tasks. Whether you are a system
administrator or a casual user, Linux commands can help you perform tasks
ranging from basic file operations to complex system administration tasks. Some
Linux commands are simple, such as changing directories or creating files, while
others are more complex, such as configuring network settings or managing user
accounts. With the right knowledge of Linux commands, users can gain a deeper
understanding of the operating system and unlock its full potential.

In this lecture, let’s look at some of the Linux commands.


man
The "man" command in Linux is short for "manual," and it is used to display the
documentation for a particular command or utility in the terminal. The man pages
typically provide detailed information on the usage, options, and syntax of a
command, as well as examples and other helpful tips. One of the great things about
the man pages is that they are built into the operating system, so you don't need an
internet connection or special software to access them.

Additionally, because the man pages are maintained by the community and the
developers themselves, they are usually very accurate and up-to-date. Learning
how to use the "man" command is an essential skill for any Linux user, and it can
save you a lot of time and frustration when trying to figure out how to use a
particular command or utility.
ls
The "ls" command in Linux is one of the most commonly used commands, and it is
used to list the contents of a directory. When you run the "ls" command without any
arguments, it will display the files and directories in the current working directory.
However, there are many options and arguments that can be used with the "ls"
command to customize the output.

For example, the "-l" option will display the contents of the directory in long format,
showing details such as the file permissions, owner, group, size, and modification
time. The "-a" option will show all files and directories, including hidden ones that
start with a dot. The "-h" option will display the file sizes in human-readable format,
making it easier to read and understand. The "ls" command is a versatile tool that
can be used in many different ways, and it is essential for navigating and managing
files and directories in Linux.
cd
The "cd" command in Linux is used to change the current working directory. When
you open a terminal window, your current working directory is typically your home
directory. By using the "cd" command followed by a directory path, you can change
the working directory to that directory. For example, "cd /var/log" will change the
current working directory to the "/var/log" directory. The "cd" command is a
fundamental tool for navigating the Linux file system and is often used in
conjunction with other commands to create, move, and manage files and
directories.

It is important to note that the "cd" command only changes the working directory for
the current terminal session. If you open a new terminal window or log out and log
back in, you will be back in your home directory.
pwd
The "pwd" command in Linux is used to print the current working directory to the
terminal. When you open a terminal window, your current working directory is
typically your home directory. By running the "pwd" command, you can see the full
path to your current working directory, which can be useful when you need to
reference a file or directory in that location.

The "pwd" command is a simple yet essential tool for navigating the Linux file
system, and it is often used in conjunction with other commands like "cd" and "ls" to
move and manage files and directories. Additionally, the "pwd" command can be
helpful when writing scripts or configuring settings that require specific file paths.
mkdir
The "mkdir" command in Linux is used to create a new directory or folder. When you
run the "mkdir" command followed by a directory name, it will create a new
directory in the current working directory. For example, "mkdir my_folder" will create
a new directory called "my_folder" in the current working directory. The "mkdir"
command can also be used with multiple directory names to create multiple
directories at once.

The "mkdir" command supports several options, such as "-p" to create parent
directories as needed and "-m" to set the permissions of the newly created
directory. The "mkdir" command is a simple yet essential tool for managing files and
directories in Linux, and it is often used in conjunction with other commands like "cd"
and "ls" to navigate and organize the file system.
rmdir
The "rmdir" command in Linux is used to remove an empty directory or folder. When
you run the "rmdir" command followed by the name of an empty directory, it will
delete that directory from the file system. The "rmdir" command is similar to the "rm"
command, which is used to delete files and directories, but the "rmdir" command
can only remove empty directories. If you try to use the "rmdir" command on a
directory that contains files or other directories, you will get an error message.
Additionally, the "rmdir" command supports several options, such as "-p" to remove
parent directories if they are empty and "-v" to display the name of each directory
as it is removed.
mv
The "mv" command in Linux is used to move or rename files and directories. When
you run the "mv" command followed by a source file or directory and a destination
file or directory, it will move the source to the destination. For example, "mv file1.txt
/home/user/Documents" will move the file "file1.txt" to the "Documents" directory in
the user's home directory.

The "mv" command can be used to rename files or directories by specifying the new
name as the destination. For example, "mv file1.txt file2.txt" will rename the file
"file1.txt" to "file2.txt". The "mv" command supports several options, such as "-i" to
prompt before overwriting an existing file and "-u" to only move files that are newer
than the destination file.
cp
The "cp" command in Linux is used to copy files and directories from one location to
another. When you run the "cp" command followed by a source file or directory and
a destination file or directory, it will create a copy of the source at the destination.
For example, "cp file1.txt /home/user/Documents" will create a copy of the file
"file1.txt" in the "Documents" directory in the user's home directory. The "cp"
command can also be used with multiple source files or directories to copy multiple
files at once. Additionally, the "cp" command supports several options, such as "-r"
to copy directories recursively and "-i" to prompt before overwriting an existing file.
open
The "open" command in Linux is not a standard command, but it is commonly used
in some Linux distributions, such as Ubuntu. The "open" command is used to open
files or directories with their default application or program. When you run the
"open" command followed by a file or directory name, it will open the file or directory
using the default application or program associated with that file type. For example,
"open my_file.txt" will open the file "my_file.txt" using the default text editor. The
"open" command is a convenient way to quickly open files and directories without
having to specify the application or program to use.

However, it is important to note that the "open" command may not be available or
behave differently depending on the Linux distribution and desktop environment
being used.
touch
The "touch" command in Linux is used to create an empty file or update the
modification time of an existing file. When you run the "touch" command followed by
a file name, it will create an empty file with that name if it does not already exist. If
the file already exists, the "touch" command will update the modification time of the
file to the current time. The "touch" command is often used to create placeholder
files or update file timestamps for scripts and automation tasks.

The "touch" command supports several options, such as "-m" to only update the
modification time and not create a new file and "-t" to specify a specific timestamp
for the file. Additionally, the "touch" command can be used with multiple files to
create or update multiple files at once.
find
The "find" command in Linux is a powerful utility for searching for files and directories
based on various criteria. When you run the "find" command followed by a starting
directory and a set of search criteria, it will search through the directory and all its
subdirectories to find files and directories that match the criteria. The search criteria
can include file or directory names, modification times, file types, sizes, and
ownership.

For example, "find /home/user/Documents -name '*.txt'" will search the


"Documents" directory in the user's home directory and all its subdirectories for files
with the extension ".txt". The "find" command can also be used to perform actions on
the files and directories it finds, such as deleting, copying, or moving them. The "find"
command supports several options, such as "-type" to specify the type of file to
search for and "-mtime" to search for files modified within a specific time range.
ln
The "ln" command in Linux is used to create links between files and directories. There
are two types of links that can be created using the "ln" command: hard links and
symbolic links. Hard links are essentially multiple names for the same file, meaning
that changes made to one file will be reflected in all other linked files. Symbolic links,
on the other hand, are pointers to another file or directory, meaning that changes
made to the original file or directory will not affect the linked file or directory.

To create a hard link using the "ln" command, you can run "ln [source file]
[destination file]". For example, "ln file1.txt file2.txt" will create a hard link between
"file1.txt" and "file2.txt", so changes made to either file will be reflected in the other.

To create a symbolic link using the "ln" command, you can run "ln -s [source file or
directory] [destination file or directory]". For example, "ln -s
/home/user/Documents/my_folder /home/user/Desktop/my_link" will create a
symbolic link called "my_link" on the desktop that points to the "my_folder"
directory in the user's "Documents" folder.
gzip
The "gzip" command in Linux is a utility used for file compression and
decompression. When you run the "gzip" command followed by a file name, it will
compress the file and replace the original file with the compressed version, which
has the ".gz" extension. The "gzip" command uses a compression algorithm to
reduce the size of the file, making it more efficient to store and transfer. The
compressed file can be easily decompressed using the "gunzip" command, which
restores the original file.

The "gzip" command supports several options, such as "-c" to send the compressed
output to the standard output instead of replacing the original file and "-r" to
compress all files in a directory and its subdirectories recursively.

The "gzip" command is a useful tool for managing disk space and transferring files,
especially when dealing with large files. It is widely used in Linux and other Unix-like
systems, and many software packages and libraries are distributed in compressed
".gz" format to reduce their size.
tar
The tar command in Linux is a utility used to create and manipulate tar archives,
which are commonly used for file compression, archiving, and backup purposes. Tar
stands for "tape archive", which reflects its origins as a tool for creating archives on
tape drives.

One of the key advantages of using the tar command is that it can be used to
archive entire directory structures, preserving their hierarchical structure and file
permissions. This can be very useful when creating backups or transferring files
between systems.

In addition to creating archives, the tar command can also be used to extract files
from existing archives or to add new files to an existing archive. It can also be used
to compress archives using various compression algorithms, such as gzip or bzip2,
which can significantly reduce the size of the archive.

Another useful feature of the tar command is its ability to handle special files and
devices, such as symbolic links and block devices. This makes it a versatile tool for
working with a wide range of file types and formats.
gunzip
The gunzip command in Linux is a tool used to decompress files that have been
compressed using the gzip compression algorithm. It is part of the gzip package,
which is widely used for file compression and decompression on Unix-based
systems. The gunzip command is very easy to use, and can quickly decompress
files without requiring any additional options or parameters.

Another advantage of gunzip is that it can be used in conjunction with other Linux
commands to process compressed files. For example, you can use the tar
command to create a tar archive of a directory, and then pipe it to gunzip to
compress the archive. This can be done in a single command, which can be very
convenient when working with large files.
alias
The alias command in Linux is a tool that allows you to create shortcuts or alternate
names for other commands or command sequences. With the alias command, you
can define your own custom commands or shortcuts that can be used in place of
longer, more complex commands.

One of the key advantages of using the alias command is that it can help you save
time and improve your workflow by reducing the amount of typing required for
frequently used commands. For example, you can create an alias for a long
command with many options, and then simply use the alias to execute the
command with all its options without having to type them out each time.
cat
The cat command in Linux is a utility that is used to concatenate and display files on
the terminal. The name "cat" stands for "concatenate", reflecting its primary purpose
of combining multiple files into a single output stream.

The cat command is that it is very simple and easy to use. You can use it to display
the contents of a single file on the terminal or to combine the contents of multiple
files into a single output stream. This can be useful for a variety of tasks, such as
viewing the contents of log files or combining multiple text files into a single
document.

The cat command can also be used to create new files by redirecting its output to a
file. This can be done using the ">" symbol to redirect the output to a new file, or the
">>" symbol to append the output to an existing file.
grep
The grep command in Linux is a utility that is used to search for specific patterns or
regular expressions within text files. The name "grep" stands for "global regular
expression print", reflecting its primary purpose of finding and displaying lines of text
that match a given pattern.

It can be used to search for a wide range of patterns, including simple text strings,
regular expressions, and even complex patterns that include logical operators such
as "and" or "or". This makes it a powerful tool for searching and filtering text files
based on specific criteria.
sort
A sort command is a powerful tool in Linux that allows users to sort lines of text in a
file or standard input based on specific criteria. By default, sort sorts text in
ascending order and removes duplicate lines. However, users can customize the
sort behavior by specifying options like -r to sort in descending order, -n to sort
numerically, or -k to sort by a specific column. The sort command can also be used
in combination with other commands like grep and cut to manipulate data and
extract relevant information.

One of the most useful features of the sort command is its ability to sort large files
efficiently. The sort command uses a technique called external sorting, which breaks
the file into smaller chunks that can fit into memory, sorts those chunks, and then
merges them back together into a single sorted file. This makes sorting very efficient
and able to handle large files that might not fit into memory.
uniq
The uniq command is another powerful tool in Linux that allows users to filter out
duplicate lines in a file or standard input. By default, uniq removes consecutive
duplicate lines, leaving only the first occurrence of each unique line. However, users
can customize the behavior of uniq by specifying options like -c to count the
number of occurrences of each unique line, or -u to remove only non-unique lines.
The uniq command is often used in combination with other commands like sort and
grep to manipulate and analyze data.

If the file contains non-consecutive duplicate lines, uniq will not remove them. In
these cases, users can first use sort to sort the file and then use uniq to remove the
duplicate lines. Additionally, users can specify the number of consecutive duplicate
lines to remove using the -f option, which skips a specified number of fields before
checking for duplicates. Overall, the uniq command is a useful tool for filtering out
duplicate lines in text data, especially when used in combination with other
commands.
echo
The echo command is a simple but versatile tool in Linux that allows users to print
text to the terminal or to a file. By default, echo simply prints its arguments to the
terminal, separated by spaces and followed by a newline. However, users can
customize the behavior of echo by specifying options like -n to suppress the newline
character or -e to enable interpretation of escape sequences like \t for tab or \n for
newline. The echo command can be used to display messages to the user, print the
values of variables, or generate output for use in scripts.

One important thing to note about the echo command is that it is not always safe to
use with arbitrary input. If the input contains special characters like quotes or
backslashes, they can cause unexpected behavior or even introduce security
vulnerabilities. In these cases, users should use more robust tools like printf to
ensure that the input is printed correctly.
printf
The printf command is a powerful tool in Linux that allows users to format and print
text to the terminal or to a file. Unlike the echo command, printf allows users to
specify a format string that controls the layout and appearance of the output. The
format string can include placeholders for variables, control characters like newline
or tab, and formatting options like width, precision, and alignment. The printf
command is often used in shell scripts to generate formatted output for use in
reports or logs.

One of the most useful features of the printf command is its ability to format
numbers and dates. The format string can include special placeholders for integers,
floating-point numbers, and dates, and users can specify options like the number of
decimal places or the date format. This makes printf a powerful tool for generating
human-readable output from raw data. Additionally, printf can be used in
combination with other commands like awk and sed to manipulate and format
data in complex ways.
chown
The chown command in Linux is used to change the owner and group ownership of
files and directories. It is commonly used by system administrators to manage file
permissions and control access to files. The command syntax takes the form chown
[options] owner[:group] file, where the owner is the new owner of the file or
directory, the group is the new group ownership (optional), and the file is the file or
directory to modify ownership on. The chown command can be used to change
ownership for a single file or directory, or recursively for an entire directory tree.

It requires root privileges to modify ownership of files and directories owned by other
users. Without root privileges, users can only change ownership of files and
directories that they own. The chown command can also be used in combination
with other commands like find to modify ownership for multiple files or directories at
once.
chmod
The chmod command in Linux is used to change the permissions of files and
directories. It is commonly used by system administrators to control access to files
and directories by users and groups. The command syntax takes the form chmod
[options] mode file, where mode is the new permission mode, specified as a
combination of letters and numbers, and the file is the file or directory to modify
permissions on. The chmod command can be used to grant or revoke read, write,
and execute permissions for the owner, group, and other users.

One of the most powerful features of the chmod command is its ability to use
symbolic mode expressions to modify permissions. These expressions allow users to
specify changes to the existing permissions by adding or subtracting permissions
for the owner, group, and other users. For example, the expression chmod g+rx file
adds read and execute permissions for the group, while chmod o-rwx file removes
all permissions for other users.
vim
Vim is a popular command-line text editor in Linux and other Unix-like systems. It is
a highly configurable and powerful editor that can be customized to meet the needs
of individual users. The vim command is used to launch the editor and to open and
edit files. In vim, users can navigate and edit the text using a combination of
keyboard shortcuts, commands, and modes. The editor supports syntax
highlighting for a wide variety of programming languages, as well as many
advanced features like macro recording, plugin support, and integration with
external tools like Git.

One of the most important features of vim is its modal editing system. In vim, users
switch between different modes to perform different tasks. The most commonly
used modes are "normal" mode, which is used for navigation and issuing
commands, and "insert" mode, which is used for typing and editing text. vim also
includes many other modes for more advanced tasks, like a visual mode for
selecting blocks of text, a command-line mode for entering commands, and
replace mode for overwriting text. This modal system can be challenging to learn at
first, but it allows users to work with text much more efficiently once they are familiar
with it.
nano
Nano is a popular command-line text editor in Linux and other Unix-like systems,
known for its simplicity and ease of use. It is designed to be an easy-to-learn
alternative to more powerful editors like vim and emacs. The nano command is
used to launch the editor and to open and edit files. In nano, users can navigate and
edit the text using familiar keyboard shortcuts and commands. The editor includes
features like syntax highlighting for many programming languages, search and
replace, and multiple undo/redo.
whoami
The whoami command in Linux is a simple yet useful command that is used to
display the current user's username. When executed, the whoami command prints
the username of the user who is currently logged in to the terminal session. The
command syntax is straightforward, and simply consists of typing whoami and
pressing Enter.

The whoami command can be particularly useful when used in scripts or


command-line tools that need to perform different actions based on the user's
identity. For example, a script that needs to access files or directories that are only
accessible by the current user could use the whoami command to determine the
user's identity before attempting to access the files.
who
When executed, the who command displays a list of all users who are currently
logged in to the system, along with additional information such as the date and
time they logged in, the terminal or display they are using, and the IP address they
are connected from. The command syntax is straightforward and simply consists of
typing who and pressing Enter.

The who command can be particularly useful for system administrators who need
to keep track of user activity on a system. By running the who command, an
administrator can quickly see who is currently logged in, where they are logged in
from, and how long they have been logged in for. This information can be useful for
monitoring system usage and identifying potential security issues, such as
unauthorized access or suspicious activity.
sudo
The name "sudo" stands for "superuser do," which reflects its primary use case of
executing commands as the system superuser, also known as the root user. By
default, most Linux systems are configured to only allow the root user to perform
certain administrative tasks, such as installing system packages or modifying
system configuration files. However, the sudo command allows authorized users to
perform these tasks without having to log in as the root user.

The sudo command is particularly useful in environments where multiple users


need to share administrative tasks, as it allows for fine-grained control over which
users are authorized to perform which tasks. System administrators can configure
the sudo command to grant specific users or groups the ability to execute certain
commands with elevated privileges while restricting their ability to perform other
tasks. Additionally, the sudo command can be used to execute commands as
another user, which can be useful for tasks that require specific permissions or
access to specific resources.
passwd
The passwd command in Linux is a powerful tool that is used to change the
password for a user account. When executed, the passwd command prompts the
user to enter their current password and then enter a new password twice to
confirm. The new password must meet certain requirements, such as a minimum
length and complexity, depending on the system's configuration. The passwd
command is an important tool for managing user account security in Linux systems,
as it allows users to change their passwords regularly to prevent unauthorized
access. Additionally, system administrators can use the passwd command to force
users to change their passwords or reset forgotten passwords.
ping
The ping command in Linux is a network troubleshooting tool that is used to test the
connectivity between two networked devices. When executed, the ping command
sends a series of small packets, called "echo requests," to the specified device or IP
address and waits for a response. If the device or IP address responds, the ping
command displays information about the round-trip time, or latency, between the
two devices, as well as the number of packets sent and received. The ping
command is a useful tool for diagnosing network connectivity issues, as it can help
identify problems with network hardware, software, or configuration. Additionally,
the ping command can be used to measure the performance and reliability of a
network connection over time, which can be useful for monitoring network
performance and identifying potential issues before they become critical.
clear
The clear command in Linux is a simple but useful tool that is used to clear the
terminal window of any previous commands or output. When executed, the clear
command clears the screen and returns the command prompt to the top of the
window, making it easier to read and enter new commands. The clear command is
particularly useful for situations where the terminal window becomes cluttered with
too much output or too many commands, as it provides a quick and easy way to
reset the screen and start fresh. Additionally, the clear command can be used in
scripts or command pipelines to ensure that output is clean and easy to read, which
can be useful for automating repetitive tasks or processing large amounts of data.
THANK YOU

You might also like