SlideShare a Scribd company logo
BASIC LINUX COMMANDS
ls – lists a directory’s content.
pwd – shows the current working directory’s path.
cd – changes the working directory.
mkdir – creates a new directory.
rmdir – removes a folder or path.
rm – deletes a file.
cp – copies files and directories, including their content.
mv – moves or renames files and directories.
touch – creates a new empty file.
file – checks a file’s type.
BASIC LINUX COMMANDS
zip and unzip – creates and extracts a ZIP archive.
tar – archives files without compression in a TAR format.
nano, vi, and jed – edits a file with a text editor.
cat – lists, combines, and writes a file’s content as a standard output.
grep – searches a string within a file.
sed – finds, replaces, or deletes patterns in a file.
head – displays a file’s first ten lines.
tail – prints a file’s last ten lines.
awk – finds and manipulates patterns in a file.
sort – reorders a file’s content.
BASIC LINUX COMMANDS
cut – sections and prints lines from a file.
diff – compares two files’ content and their differences.
tee – prints command outputs in Terminal and a file.
locate – finds files in a system’s database.
find – outputs a file or folder’s location.
sudo – runs a command as a superuser.
su – runs programs in the current shell as another user.
chmod – modifies a file’s read, write, and execute permissions.
chown – changes a file, directory, or symbolic link’s ownership.
useradd and userdel – creates and removes a user account.
BASIC LINUX COMMANDS
useradd and userdel – creates and removes a user account.
df – displays the system’s overall disk space usage.
du – checks a file or directory’s storage consumption.
top – displays running processes and the system’s resource usage.
htop – works like top but with an interactive user interface.
ps – creates a snapshot of all running processes.
uname – prints information about your machine’s kernel, name, and hardware.
hostname – shows your system’s hostname.
time – calculates commands’ execution time.
systemctl – manages system services.
watch – runs another command continuously.
BASIC LINUX COMMANDS
jobs – displays a shell’s running processes with their statuses.
kill – terminates a running process.
shutdown – turns off or restarts the system.
ping – checks the system’s network connectivity.
wget – downloads files from a URL.
curl – transmits data between servers using URLs.
scp – securely copies files or directories to another system.
rsync – synchronizes content between directories or machines.
Ifconfig – displays the system’s network interfaces and their configurations.
netstat – shows the system’s network information, like routing and sockets.
BASIC LINUX COMMANDS
traceroute – tracks a packet’s hops to its destination.
nslookup – queries a domain’s IP address and vice versa.
dig – displays DNS information, including record types.
history – lists previously run commands.
man – shows a command’s manual.
echo – prints a message as a standard output.
ln – links files or directories.
alias and unalias – sets and removes an alias for a file or command.
cal – displays a calendar in Terminal.
apt-get – manages Debian-based distros package libraries.
BASIC LINUX COMMANDS EXAMPLES
Each command has option in following mask
[command] [option]
COMMAND
OPTION
Some of them use special
options.
BASIC LINUX COMMANDS EXAMPLES
The ls command lists files and directories in your system. Here’s the syntax:
If you remove the path, the ls command will show the current working
directory’s content. You can modify the command using these options:
-R – lists all the files in the subdirectories.
-a – shows all files, including hidden ones.
-lh – converts sizes to readable formats, such as MB, GB, and TB.
BASIC LINUX COMMANDS EXAMPLES
The pwd command prints your current working directory’s path, like
/home/directory/path. Here’s the command syntax:
It supports two options. The -L or –-logical option prints environment
variable content, including symbolic links. Meanwhile, -P or –physical
outputs the current directory’s actual path.
BASIC LINUX COMMANDS EXAMPLES
Use the cd command to navigate the Linux files and directories. To use it, run this
syntax with sudo privileges:
Depending on your current location, it requires either the full path or the directory
name. For example, omit /username from /username/directory/folder if you are
already within it.
Omitting the arguments will take you to the home folder. Here are some navigation
shortcuts:
•cd ~[username] – goes to another user’s home directory.
•cd.. – moves one directory up.
•cd- – switches to the previous directory.
BASIC LINUX COMMANDS EXAMPLES
Use the mkdir command to create one or multiple directories and set their
permissions. Ensure you are authorized to make a new folder in the parent
directory. Here’s the basic syntax:
To create a folder within a directory, use the path as the command parameter. For
example, mkdir music/songs will create a songs folder inside music. Here are
several common mkdir command options:
-p – creates a directory between two existing folders. For example, mkdir -p
Music/2023/Songs creates a new 2023 directory.
-m – sets the folder permissions. For instance, enter mkdir -m777 directory to
create a directory with read, write, and execute permissions for all users.
-v – prints a message for each created directory.
BASIC LINUX COMMANDS EXAMPLES
Use the rmdir command to delete an empty directory in Linux. The user must have
sudo privileges in the parent directory. Here’s the syntax:
If the folder contains a subdirectory, the command will return an error. To force
delete a non-empty directory, use the -p option.
BASIC LINUX COMMANDS EXAMPLES
Use the rm command to permanently delete files within a directory. Here’s the
general syntax:
rm [filename1] [filename2] [filename3]
Adjust the number of files in the command according to your needs. If you
encounter an error, ensure you have the write permission in the directory.
To modify the command, add the following options:
-i – prompts a confirmation before deletion.
-f – allows file removal without a confirmation.
-r – deletes files and directories recursively.
BASIC LINUX COMMANDS EXAMPLES
Use the cp command to copy files or directories, including their content, from your
current location to another. It has various use cases, such as:
Copying one file from the current directory to another folder. Specify the file name
and target path:
Copying one file from the current directory to
another folder. Specify the file name and target path:
Duplicating multiple files to a directory. Enter the file
names and the destination path:
Copying a file’s content to another within the same
directory. Enter the source and the destination file:
Duplicating an entire directory. Pass the -R flag
followed by the source and destination directory:
BASIC LINUX COMMANDS EXAMPLES
Use the mv command to move or rename files and directories. To move items,
enter the file name followed by the destination directory:
The touch command lets you create an empty file in a specific directory path.
Here’s the syntax:
The file command lets you check a file type – whether it is a text, image, or
binary. Here’s the syntax:
To bulk-check multiple files, list them individually or use their path if they are in
the same directory. Add the -k option to display more detailed information and -i
to show the file’s MIME type.
Meanwhile, use the following syntax to rename
a file in Linux with the mv command:
BASIC LINUX COMMANDS EXAMPLES
The zip command lets you compress items into a ZIP file with the optimal
compression ratio. For example, this command compresses note.txt into archive.zip
in the current working directory:
Use the unzip command to extract the compressed file. Here’s the syntax:
unzip [option] file_name.zip
The tar command archives multiple items into a TAR file – a format similar to ZIP
with optional compression. Here’s the syntax:
For instance, enter the following to create a new newarchive.tar archive in
the /home/user/Documents directory:
BASIC LINUX COMMANDS EXAMPLES
Linux lets users edit files using a text editor like nano, vi, or jed. While most
distributions include nano and vi, users must install jed manually. All these tools
have the same command syntax:
If the target file doesn’t exist, these editors will create one. We recommend
nano if you want to quickly edit text files. Meanwhile, use vi or jed for scripting
and programming.
BASIC LINUX COMMANDS EXAMPLES
Concatenate or cat is one of the most used Linux commands. It lists, combines, and
writes file content to the standard output. Here’s the syntax:
There are various ways to use the cat command:
cat > filen.txt – creates a new file.
cat file1.txt file2.txt > file3.txt – merges file1.txt with file2.txt and stores the
output in filename3.txt.
tac file.txt – displays content in reverse order.
The global regular expression or grep command lets you find a word by searching the
content of a file. This Linux command prints all lines containing the matching strings, which
is useful for filtering large log files.
For example, to display lines containing blue in the notepad.txt file, enter:
BASIC LINUX COMMANDS EXAMPLES
The sed command lets you find, replace, and delete patterns in a file without using
a text editor. Here’s the general syntax:
The script contains the searched regular expression pattern, the replacement
string, and subcommands. Use the s subcommand to replace matching patterns or
d to delete them.
At the end, specify the file containing the pattern to modify. Here’s an example of a
command that replaces red in colors.txt and hue.txt with blue:
BASIC LINUX COMMANDS EXAMPLES
The head command prints the first ten lines of a text file or piped data in your
command-line interface. Here’s the general syntax:
The head command accepts several options, such
as:
-n – changes the number of lines printed. For
example, head -n 5 shows the first five lines.
-c – prints the file’s first customized number of
bytes.
-q – disables headers specifying the file name.
For instance, to view the first ten lines of note.txt in the current directory, enter:
BASIC LINUX COMMANDS EXAMPLES
The tail command displays the last ten lines of a file, which is useful for checking
new data and errors. Here’s the syntax:
For example, enter the following to show the last ten lines of the colors.txt file:
The awk command scans regular expression patterns in a file to retrieve or manipulate
matching data. Here’s the basic syntax:
The action can be mathematical operations, conditional statements like if, output
expressions such as print, and a delete command. It also contains the $n notation, which
refers to a field in the current line.
To add multiple actions, list them based on the execution order, separated using
semicolons.
BASIC LINUX COMMANDS EXAMPLES
The sort command rearranges lines in a file in a specific order. It doesn’t modify the
actual file and only prints the result as Terminal outputs. Here’s the syntax:
By default, this command will sort the lines in alphabetical order, from A to Z. To modify the
sorting, use these options:
-o – redirects the command outputs to another file.
-r – reverses the sorting order to descending.
-n – sorts the file numerically.
-k – reorders data in a specific field.
BASIC LINUX COMMANDS EXAMPLES
The cut command retrieves sections from a file and prints the result as Terminal
outputs. Here’s the syntax:
Instead of a file, you can use data from standard input.
To determine how the command sections the line, use
the following options:
-f – selects a specific field.
-b – cuts the line by a specified byte size.
-c – sections the line using a specified character.
-d – separates lines based on delimiters.
You can combine these options, use a range, and specify
multiple values. For example, this command extracts the
third to fifth field from a comma-separated list:
BASIC LINUX COMMANDS EXAMPLES
The cut command retrieves sections from a file and prints the result as Terminal
outputs. Here’s the syntax:
Instead of a file, you can use data from standard input.
To determine how the command sections the line, use
the following options:
-f – selects a specific field.
-b – cuts the line by a specified byte size.
-c – sections the line using a specified character.
-d – separates lines based on delimiters.
You can combine these options, use a range, and specify
multiple values. For example, this command extracts the
third to fifth field from a comma-separated list:
BASIC LINUX COMMANDS TASK1
1. Create directory /home/[username]/system administration/student/ (Hint 1
p11.)(to use space in name use backslash ex: mkdir name surname make
folder ‘name surname’)
2. Create text file with your name ex: /home/[username]/system
administration/student/Takhirov Abdulaziz.txt (Hint 2 p17.)
3. Fill up content of a file with 5 lines where provide information n following
format 1st
line: City where you live, 2nd
line: date of birth (year only), 3rd
line:
your hobby, 4th
line: favorite color, 5th
line: favorite book.
4. Move file with your name to home folder (/home) (Hint 3 p15.) (in case of
permission denied use command sudo su-)
5. Make copy of file with name student.txt (Hint 4 p14. cp)
6. List all files and directories inside of home folder (Hint 5 p11.)
7. Sort lines of file student.txt in descending format show in terminal (Hint 6 p22.)
BASIC LINUX COMMANDS EXAMPLES
The diff command compares two files’ content and outputs the differences. It is
used to alter a program without modifying the code. Here’s the general format:
Below are some acceptable
options:
-c – displays the difference
between two files in a context
form.
-u – shows the output
without redundant
information.
-i – makes the diff command
case insensitive.
BASIC LINUX COMMANDS EXAMPLES
The tee command writes the
user’s input to Terminal’s
output and files. Here’s the
basic syntax:
For example, the following
pings Google and prints the
output in Terminal,
ping_result.txt, and the
19092023.txt file:
The locate command lets you
find a file in the database
system. Add the -i option to
turn off case sensitivity and an
asterisk (*) to find content with
multiple keywords. For
example:
The command searches for files
containing school and note,
regardless of their letter case.
BASIC LINUX COMMANDS EXAMPLES
Use the find command to search for files within a specific directory. Here’s the
syntax:
For example, to find a file called file1.txt within the directory folder and its
subdirectories, use this command:
If you omit the path, the command will search the current working directory. You can
also find directories using the following:
BASIC LINUX COMMANDS EXAMPLES
Superuser do or sudo is one of the most basic commands in Linux. It runs your
command with administrative or root permissions. Here’s the general syntax:
When you run a sudo command, Terminal will request the root password. For example,
this snippet runs useradd with the superuser privilege:
You can also add an option, such as:
-k – invalidates the timestamp file.
-g – executes commands as a specified
group name or ID.
-h – runs commands on the host.
Warning! Running a command with sudo
privileges can modify all aspects of your
system. Since misusing it may break your
system, run the command with caution and
only if you understand its possible
repercussions.
BASIC LINUX COMMANDS EXAMPLES
The su command lets you run a program in the Linux shell as a different user. It is
useful to connect via SSH while the root user is disabled. Here’s the syntax:
Without any option or argument, this command runs through root and prompts you to
use the sudo privileges temporarily. Some options are:
-p – keeps the same shell environment, consisting of HOME, SHELL, USER, and
LOGNAME.
-s – lets you specify another shell environment to run.
-l – runs a login script to switch users. It requires you to enter the user’s password.
To check the current shell’s user account, run the whoami command:
BASIC LINUX COMMANDS EXAMPLES
The chmod command modifies directory or file permissions in Linux. Here’s the
basic syntax:
In Linux, each file is associated with three user classes – owner, group member, and
others. It also has three permissions – read, write, and execute. If an owner wants to
grant all permissions to every user, the command looks like this:
The number determines the file permissions. Read, write, and execute are represented
by a numerical value:
•r (read) – 4
•w (write) – 2
•x (execute) – 1
If you don’t want to give any permission to a
user, enter 0 into the corresponding spot.
BASIC LINUX COMMANDS EXAMPLES
If you don’t want to give any permission to a
user, enter 0 into the corresponding spot.
Common permissions for directories:
BASIC LINUX COMMANDS EXAMPLES
The chown command lets you change a file, directory, or symbolic link’s ownership
to the specified username. Here’s the syntax:
For example, to make linuxuser2 the owner of filename.txt, use:
One of the most popular options that you can combine with chmod and chown is -R
(Recursive). This Linux option allows you to edit permissions or owners of all files and
subdirectories inside a specific directory.
-f or force. The command line will ignore any errors and apply the chmod and chown
commands.
-v (verbose) option gives you diagnostics of all files that are processed by the
command.
-c (changes) is similar to the -v option. However, it will only provide information when
changes were successfully made.
BASIC LINUX COMMANDS EXAMPLES
Use useradd to create a new Linux user account and change its password with the
passwd command. Here are the syntaxes:
Both the useradd and passwd commands require sudo privileges. To delete a user, use
the userdel command:
BASIC LINUX COMMANDS EXAMPLES
Use the df command to check a Linux system’s disk space usage in percentage and
kilobyte (KB). Here’s the syntax:
Add an option to the df command for detailed disk
space checking in Linux. Popular options include:
df -h – shows the result in a human-readable format.
df -m – displays file system usage information in MB.
df -k – tells users the file system usage in KB.
df -T – specifies the file system type in a new column.
df /home – allows you to view information about a
specific file system in a readable format. In this
example, it’s the /home file system.
df – help – lists other options to use and their
descriptions.
BASIC LINUX COMMANDS EXAMPLES
Use du to check a file or directory’s storage consumption. Remember to specify the
directory path when using this command, for example:
The du command has several options, such as:
-s – shows the specified folder’s total size.
-m – provides folder and file information in MB.
-k – displays information in KB.
-h – informs the displayed folders and files’ last
modification date.
BASIC LINUX COMMANDS EXAMPLES
The top command displays running processes and the system’s real-time condition,
including resource utilization. It helps identify resource-intensive processes,
enabling you to disable them easily.
The htop command is an interactive program for monitoring system resources and
server processes. Unlike top, it offers additional features like mouse operation and
visual indicators. Here’s the command syntax:
It supports options such as:
-d – shows the delay between updates in tenths of seconds.
-C – enables monochrome mode.
-h – displays the help message and exits.
BASIC LINUX COMMANDS EXAMPLES
The uname or unix name command prints information about your machine,
including its hardware, system name, and Linux kernel. Here’s the basic syntax:
While you can use it without an option, add the following to modify the command:
-a – prints all the system information.
-s – outputs the kernel name.
-n – shows the system’s node hostname.
BASIC LINUX COMMANDS EXAMPLES
Run the hostname command to display the system’s hostname. Here’s the syntax:
You can run it without an option or use the following:
-a – displays the hostname’s alias.
-A – shows the machine’s Fully Qualified Domain Name (FQDN).
-i – outputs the machine’s IP address.
BASIC LINUX COMMANDS EXAMPLES
Use time to measure commands’ execution time. Here’s the syntax:
To measure a series of commands, separate them using semicolons or double
ampersands (&&). For example, we will measure cd, touch, and chmod commands’
overall execution time:
BASIC LINUX COMMANDS EXAMPLES
The systemctl command lets you manage installed services in your Linux system.
Here’s the basic syntax:
To use the command, the user must have root privilege. It has several use cases,
including starting, restarting, and terminating a service. You can also check a
service’s status and dependencies.
BASIC LINUX COMMANDS EXAMPLES
The watch command lets the user continuously run another utility at a specific
interval and print the results as a standard output. Here’s the syntax:
It is useful for monitoring command output changes. To modify its behavior, use the
following options:
-d – displays the differences between command executions.
-n – changes the default two-second interval.
-t – disables the header containing the time interval, command, timestamp, and
hostname.
BASIC LINUX COMMANDS EXAMPLES
The jobs command displays a shell’s running processes with their statuses. It is only
available in csh, bash, tcsh, and ksh shells. Here’s the basic syntax:
To check the status of jobs in the current shell, enter jobs without any arguments in
Terminal. The command will return an empty output if your system doesn’t have
running jobs. You can also add the following options:
-l – lists process IDs and their information.
-n – shows jobs whose statuses have changed since the last notification.
-p – displays process IDs only.
BASIC LINUX COMMANDS EXAMPLES
Use the kill command to terminate an unresponsive program using its identification
number (PID). To check the PID, run the following command:
To stop the program, enter the syntax below:
There are 64 signals for terminating a program, but
SIGTERM and SIGKILL are the most common.
SIGTERM is the default signal that lets the program
save its progress before stopping. Meanwhile, SIGKILL
forces programs to stop and discard unsaved
progress.
BASIC LINUX COMMANDS EXAMPLES
The Linux shutdown command lets you turn off or restart your system at a specific
time. Here’s the syntax:
You can use an absolute time in a 24-hour format or a relative one like +5 to
schedule it in five minutes. The message is a notification sent to logged-in users
about the system shutdown.
Instead of shutting down, restart the system using the -r option. To cancel a
scheduled reboot, run the command with the -c option.
BASIC LINUX COMMANDS EXAMPLES
The ping command is one of the most used
commands in Linux. It lets you check whether
a network or server is reachable, which is
useful for troubleshooting connectivity issues.
Here’s the syntax:
For example, run the following to check
the connection and response time to
Google:
BASIC LINUX COMMANDS EXAMPLES
Use the wget command to download
files from the internet using HTTP,
HTTPS, or FTP protocols. Here’s the
syntax:
For example, enter the following to
download the latest version of
WordPress:
BASIC LINUX COMMANDS EXAMPLES
The curl command transfers data between servers. Its common usage is for retrieving
a web page’s content to your system using its URL. Here’s the syntax:
However, you can add various options to modify the curl command behavior
for other tasks. Some of the most popular ones include:
-o or -O – downloads files from a URL.
-X – changes the default HTTP GET method.
-H – sends a custom header to the URL.
-F – uploads a file to the specified destination.
BASIC LINUX COMMANDS EXAMPLES
The scp command securely copies files or directories between systems over a
network. Here’s the syntax:
For a local machine, omit the hostname and IP address. Use the following
options to modify the copying behavior:
-P – changes the port for copying. The default is 22.
-l – limits the scp command’s bandwidth.
-C – compresses transferred data to make it smaller.
BASIC LINUX COMMANDS EXAMPLES
The scp command securely copies files or directories between systems over a
network. Here’s the syntax:
For a local machine, omit the hostname and IP address. Use the following
options to modify the copying behavior:
-P – changes the port for copying. The default is 22.
-l – limits the scp command’s bandwidth.
-C – compresses transferred data to make it smaller.
BASIC LINUX COMMANDS EXAMPLES
The rsync command lets you sync files or folders between two destinations to ensure
they have the same content. Here’s the syntax:
If your destination or source is a folder, enter the directory path like
/home/directory/path. To sync a remote server, use its hostname and IP
address, like host@185.185.185.185.
-a – enables archive mode to preserve file permissions, dates, and other
attributes.
-v – shows visual information about the transferred file.
-z – compresses the transferred file data to reduce their size.
BASIC LINUX COMMANDS EXAMPLES
The ifconfig command lets you list and configure your system’s network interface. In
newer Linux distros, it is equivalent to the ip command. Here’s the basic syntax:
Running it without arguments displays information about all network
interfaces in your system. To check a specific interface, add its name as an
argument without an option. For a more specific task, use the following
options:
•–s – summarizes the network interfaces and their configuration. This option
goes before the interface name.
•up and down – enables and disables a network interface.
•inet and inet6 – assigns an IPv4 and IPv6 address to a network interface.
•netmask – specifies the subnet mask to use with an IPv4 address.
BASIC LINUX COMMANDS EXAMPLES
The ifconfig command lets you list and configure your system’s network interface. In
newer Linux distros, it is equivalent to the ip command. Here’s the basic syntax:
Running it without arguments displays information about all network
interfaces in your system. To check a specific interface, add its name as an
argument without an option. For a more specific task, use the following
options:
–s – summarizes the network interfaces and their configuration. This option
goes before the interface name.
up and down – enables and disables a network interface.
inet and inet6 – assigns an IPv4 and IPv6 address to a network interface.
netmask – specifies the subnet mask to use with an IPv4 address.
BASIC LINUX COMMANDS EXAMPLES
The netstat command is used to display your system’s network information, like
sockets and routing. Here’s the command syntax:
Running it without arguments displays information about all network
interfaces in your system. To check a specific interface, add its name as an
argument without an option. For a more specific task, use the following
options:
–s – summarizes the network interfaces and their configuration. This option
goes before the interface name.
up and down – enables and disables a network interface.
inet and inet6 – assigns an IPv4 and IPv6 address to a network interface.
netmask – specifies the subnet mask to use with an IPv4 address.
BASIC LINUX COMMANDS EXAMPLES
The traceroute command tracks a packet’s path when it moves to another host over a
network. It gives you information about the involved routers and travel time. Here’s
the syntax:
You can use a domain, hostname, or IP address as the
destination. Add the following options for more
detailed packet monitoring:
•-m – sets each packet’s maximum hops.
•-n – prevents the command from resolving IP
addresses to hostnames for quicker tracing.
•-I – changes the default UDP packets to UCMP.
•-w – adds a timeout in seconds.
BASIC LINUX COMMANDS EXAMPLES
The nslookup command queries a DNS server to find out the domain associated with
an IP address and vice versa. Here’s the syntax:
If you don’t specify the DNS server to use, nslookup will use the default resolver from
your system or internet service provider. This command supports various options, with
some commonly used ones being:
-type= – queries specific information, like the
IP address type or MX record.
-port= – sets the DNS server’s port number
for the query.
-retry= – repeats the query a specific number
of times upon failure.
-debug – enables the debug mode to provide
more information about the query.
BASIC LINUX COMMANDS TASK2
1. Restart system and login by root, Delete user created while installing system from system except root
2. Create user cambridge1 with password at least 6 minimum length
3. Create user cambridge2 with password at least 6 minimum length
4. Create user cambridge3 with password
5. Create file file[x].txt in [username]/documents/ for each user with text ‘This text file owned by
[username]’ cambridge1documentsfile1.txt
cambridge2documentsfile2.txt
cambridge3documentsfile3.txt
6. Set permission for file1.txt read for [cambridge2]
7. Set permission for file3.txt read write for [cambridge2]
8. Set permission for file2.txt read write execute for [cambridge1]
9. Set ownership for file3.txt [cambridge2] with changing text ‘This text file owned by [username]’.
10. Set permission for file3.txt [cambridge1] read permission and [cambridge3] read write execute
11. Move file1.txt, file2.txt, file3.txt to [cambridge1]/documents/ file1.txt file1.txt file2.txt folder and change
ownership [cambridge1]
12. Show memory consumption of folder [cambridge1]/documents/
BASIC LINUX COMMANDS EXAMPLES
The dig or domain information groper command gathers DNS data from a domain.
Unlike nslookup, it is more detailed and versatile. Here’s the syntax:
Replace target with a domain name. By default, this command only shows A record
type. Change query_type to check a specific type or use ANY to query all of them. To
run a reverse DNS lookup, add the -x option and use the IP address as the target.
[name] – the name of the resource record that is
to be looked up.
[type] – the type of query requested by dig.
For example, it can be an A record, MX record,
SOA record or any other types. By default dig
performs a lookup for an A record if no type argument is specified.
BASIC LINUX COMMANDS EXAMPLES
Enter history to list previously executed commands. It lets you reuse the commands
without rewriting them. To use it, enter this syntax with sudo privileges:
To rerun a specific utility, enter an exclamation mark (!) followed by the command’s list
number. For example, use the following to rerun the 24th command:
his command supports many options, such as:
-c – clears the history list.
-d offset – deletes the history entry at the
OFFSET position.
-a – appends history lines.
BASIC LINUX COMMANDS EXAMPLES
The man command provides a user manual of any Linux Terminal utilities, including
their names, descriptions, and options. It consists of nine sections:
If you only use the command name as the parameter, Terminal displays the full user
manual. Here’s an example command to query section 1 of the ls command manual:
BASIC LINUX COMMANDS EXAMPLES
The echo command displays a line of text as a standard output. Here’s the basic
command syntax:
For example, you can display System administration by entering:
This command supports many options, such as:
-n – displays the output without the trailing newline.
-e – enables the interpretation of the following backslash escapes:
b – removes spaces in between a text.
c – produces no further output.
BASIC LINUX COMMANDS EXAMPLES
The ln command lets you create links between files or directories to simplify system
management. Here’s the syntax:
For example, to link the /user/local/downloads/logo
directory to /devisers folder, use the following command:
This command supports many options, such as:
You can remove existing links attached to files or
directories by the unlink or rm command.
This is how you can do it with the unlink command:
BASIC LINUX COMMANDS EXAMPLES
The alias command instructs the shell to replace a string with another, allowing you to
create a shortcut for a program, file name, or text. Here’s the syntax:
For example, enter the following to make k the alias for the kill command:
This command doesn’t give any output. To check the alias associated with a command,
run the following:
To delete an existing alias, use the unalias command with the following syntax:
BASIC LINUX COMMANDS EXAMPLES
The cal command outputs a calendar in the Linux Terminal. It will show the current
date if you don’t specify the month and year. Here’s the syntax:
The month is in the numerical representation from 1–12. To modify the command
output, add the following options:
The month is in the numerical representation from 1–12.
To modify the command output, add the following options:
-1 – outputs the calendar in a single line.
-3 – shows the previous, current, and next month.
-A and -B – displays the specified number of months after
and before the current one.
-m – starts the calendar with Monday instead of Sunday.
BASIC LINUX COMMANDS EXAMPLES
apt-get is a command line tool for handling Advanced Package Tool (APT) libraries in
Debian-based Linux, like Ubuntu. It requires sudo or root privileges.
This Linux command lets you manage, update, remove, and install software, including
its dependencies. Here’s the main syntax:
These are the most common commands to use with apt-get:
update – synchronizes the package files from their sources.
upgrade – installs the latest version of all installed packages.
check – updates the package cache and checks broken dependencies.

More Related Content

PDF
LinuxCommands (1).pdf
PPTX
Linux Command.pptx
PPTX
Linux commands
PPTX
various shell commands in unix operating system.pptx
PDF
Linux_Commands.pdf
PPTX
Linux week 2
PPTX
Using linux in schools
PDF
linux commands.pdf
LinuxCommands (1).pdf
Linux Command.pptx
Linux commands
various shell commands in unix operating system.pptx
Linux_Commands.pdf
Linux week 2
Using linux in schools
linux commands.pdf

Similar to Basic Linux Commands with syntax and functions (20)

PDF
3.1.a linux commands reference
PPTX
Introduction to linux day1
PPT
Linux presentation
PPT
Linux commands
PPT
Examples -partII
PPTX
Linux Fundamentals
PPT
Linux ppt
DOCX
Linux basic commands tutorial
PDF
basic-unix.pdf
PPTX
Linux commands presentation topic discrete structure.ppt
PPT
Common linux ubuntu commands overview
PPTX
Linux System commands Essentialsand Basics.pptx
PPTX
TERMINAL COMMANDS IN LINUX TERMINAL USED TO INTERACT WITH SYSTEM
PPT
3. intro
PPT
Basiccommandppt 130415133716-phpapp02
PPT
Basic command ppt
DOCX
40 important command for linux
PPTX
Basic Linux Administration - 3.pptxon server
PPTX
PPTX
linuxcommands-140828081047-phpapp01.pptx
3.1.a linux commands reference
Introduction to linux day1
Linux presentation
Linux commands
Examples -partII
Linux Fundamentals
Linux ppt
Linux basic commands tutorial
basic-unix.pdf
Linux commands presentation topic discrete structure.ppt
Common linux ubuntu commands overview
Linux System commands Essentialsand Basics.pptx
TERMINAL COMMANDS IN LINUX TERMINAL USED TO INTERACT WITH SYSTEM
3. intro
Basiccommandppt 130415133716-phpapp02
Basic command ppt
40 important command for linux
Basic Linux Administration - 3.pptxon server
linuxcommands-140828081047-phpapp01.pptx
Ad

More from SasiBhushan22 (20)

PPTX
RTOS _Timer , Event, Memory, Device, File & IO Systems Management
PPTX
Real TIme Operating Systems - Programming with Micro_C
PPTX
Interrupt_Latency_Response_Time_Presentation.pptx
PPT
INTRODUCTION TO PIC MICROCONTROLLERS 16C6X
PPTX
RTOS OS Security Issues Security Challenges, Threats & Mitigation
PDF
RTOS Keywords with Definitions and explanation
PPTX
Basic Linux Commands and implementation with Examples
PPTX
RTOS _Timer , Event, Memory, Device, File & IO Systems Management_10-07-25.pptx
PPT
Operating Systems Storage & Process Management
PPTX
ARM-7 ADDRESSING MODES INSTRUCTION SET
PPTX
ARM-7 ADDRESSING MODES INSTRUCTION SET
PPTX
Microprocessors & Microcontrollers Architecture and Description
PPTX
8051- Microcontrollers Architecture & Addressing modes
PPT
Operating Systems _ Process & Storage Management
PPTX
RTOS_Keywords_with basic Definitions.pptx
PPT
Operating Systems with Storage and Process Management
PPTX
Real Time Operating Systems Basic Definitions
PPT
Introduction to 8086 Microprocessors.ppt
PPT
Interrupts.ppt
PPT
Programs using Microcontrollers.ppt
RTOS _Timer , Event, Memory, Device, File & IO Systems Management
Real TIme Operating Systems - Programming with Micro_C
Interrupt_Latency_Response_Time_Presentation.pptx
INTRODUCTION TO PIC MICROCONTROLLERS 16C6X
RTOS OS Security Issues Security Challenges, Threats & Mitigation
RTOS Keywords with Definitions and explanation
Basic Linux Commands and implementation with Examples
RTOS _Timer , Event, Memory, Device, File & IO Systems Management_10-07-25.pptx
Operating Systems Storage & Process Management
ARM-7 ADDRESSING MODES INSTRUCTION SET
ARM-7 ADDRESSING MODES INSTRUCTION SET
Microprocessors & Microcontrollers Architecture and Description
8051- Microcontrollers Architecture & Addressing modes
Operating Systems _ Process & Storage Management
RTOS_Keywords_with basic Definitions.pptx
Operating Systems with Storage and Process Management
Real Time Operating Systems Basic Definitions
Introduction to 8086 Microprocessors.ppt
Interrupts.ppt
Programs using Microcontrollers.ppt
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
Cell Types and Its function , kingdom of life
PPTX
Institutional Correction lecture only . . .
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Complications of Minimal Access Surgery at WLH
Cell Types and Its function , kingdom of life
Institutional Correction lecture only . . .
Microbial disease of the cardiovascular and lymphatic systems
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
102 student loan defaulters named and shamed – Is someone you know on the list?
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
RMMM.pdf make it easy to upload and study
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Pre independence Education in Inndia.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

Basic Linux Commands with syntax and functions

  • 1. BASIC LINUX COMMANDS ls – lists a directory’s content. pwd – shows the current working directory’s path. cd – changes the working directory. mkdir – creates a new directory. rmdir – removes a folder or path. rm – deletes a file. cp – copies files and directories, including their content. mv – moves or renames files and directories. touch – creates a new empty file. file – checks a file’s type.
  • 2. BASIC LINUX COMMANDS zip and unzip – creates and extracts a ZIP archive. tar – archives files without compression in a TAR format. nano, vi, and jed – edits a file with a text editor. cat – lists, combines, and writes a file’s content as a standard output. grep – searches a string within a file. sed – finds, replaces, or deletes patterns in a file. head – displays a file’s first ten lines. tail – prints a file’s last ten lines. awk – finds and manipulates patterns in a file. sort – reorders a file’s content.
  • 3. BASIC LINUX COMMANDS cut – sections and prints lines from a file. diff – compares two files’ content and their differences. tee – prints command outputs in Terminal and a file. locate – finds files in a system’s database. find – outputs a file or folder’s location. sudo – runs a command as a superuser. su – runs programs in the current shell as another user. chmod – modifies a file’s read, write, and execute permissions. chown – changes a file, directory, or symbolic link’s ownership. useradd and userdel – creates and removes a user account.
  • 4. BASIC LINUX COMMANDS useradd and userdel – creates and removes a user account. df – displays the system’s overall disk space usage. du – checks a file or directory’s storage consumption. top – displays running processes and the system’s resource usage. htop – works like top but with an interactive user interface. ps – creates a snapshot of all running processes. uname – prints information about your machine’s kernel, name, and hardware. hostname – shows your system’s hostname. time – calculates commands’ execution time. systemctl – manages system services. watch – runs another command continuously.
  • 5. BASIC LINUX COMMANDS jobs – displays a shell’s running processes with their statuses. kill – terminates a running process. shutdown – turns off or restarts the system. ping – checks the system’s network connectivity. wget – downloads files from a URL. curl – transmits data between servers using URLs. scp – securely copies files or directories to another system. rsync – synchronizes content between directories or machines. Ifconfig – displays the system’s network interfaces and their configurations. netstat – shows the system’s network information, like routing and sockets.
  • 6. BASIC LINUX COMMANDS traceroute – tracks a packet’s hops to its destination. nslookup – queries a domain’s IP address and vice versa. dig – displays DNS information, including record types. history – lists previously run commands. man – shows a command’s manual. echo – prints a message as a standard output. ln – links files or directories. alias and unalias – sets and removes an alias for a file or command. cal – displays a calendar in Terminal. apt-get – manages Debian-based distros package libraries.
  • 7. BASIC LINUX COMMANDS EXAMPLES Each command has option in following mask [command] [option] COMMAND OPTION Some of them use special options.
  • 8. BASIC LINUX COMMANDS EXAMPLES The ls command lists files and directories in your system. Here’s the syntax: If you remove the path, the ls command will show the current working directory’s content. You can modify the command using these options: -R – lists all the files in the subdirectories. -a – shows all files, including hidden ones. -lh – converts sizes to readable formats, such as MB, GB, and TB.
  • 9. BASIC LINUX COMMANDS EXAMPLES The pwd command prints your current working directory’s path, like /home/directory/path. Here’s the command syntax: It supports two options. The -L or –-logical option prints environment variable content, including symbolic links. Meanwhile, -P or –physical outputs the current directory’s actual path.
  • 10. BASIC LINUX COMMANDS EXAMPLES Use the cd command to navigate the Linux files and directories. To use it, run this syntax with sudo privileges: Depending on your current location, it requires either the full path or the directory name. For example, omit /username from /username/directory/folder if you are already within it. Omitting the arguments will take you to the home folder. Here are some navigation shortcuts: •cd ~[username] – goes to another user’s home directory. •cd.. – moves one directory up. •cd- – switches to the previous directory.
  • 11. BASIC LINUX COMMANDS EXAMPLES Use the mkdir command to create one or multiple directories and set their permissions. Ensure you are authorized to make a new folder in the parent directory. Here’s the basic syntax: To create a folder within a directory, use the path as the command parameter. For example, mkdir music/songs will create a songs folder inside music. Here are several common mkdir command options: -p – creates a directory between two existing folders. For example, mkdir -p Music/2023/Songs creates a new 2023 directory. -m – sets the folder permissions. For instance, enter mkdir -m777 directory to create a directory with read, write, and execute permissions for all users. -v – prints a message for each created directory.
  • 12. BASIC LINUX COMMANDS EXAMPLES Use the rmdir command to delete an empty directory in Linux. The user must have sudo privileges in the parent directory. Here’s the syntax: If the folder contains a subdirectory, the command will return an error. To force delete a non-empty directory, use the -p option.
  • 13. BASIC LINUX COMMANDS EXAMPLES Use the rm command to permanently delete files within a directory. Here’s the general syntax: rm [filename1] [filename2] [filename3] Adjust the number of files in the command according to your needs. If you encounter an error, ensure you have the write permission in the directory. To modify the command, add the following options: -i – prompts a confirmation before deletion. -f – allows file removal without a confirmation. -r – deletes files and directories recursively.
  • 14. BASIC LINUX COMMANDS EXAMPLES Use the cp command to copy files or directories, including their content, from your current location to another. It has various use cases, such as: Copying one file from the current directory to another folder. Specify the file name and target path: Copying one file from the current directory to another folder. Specify the file name and target path: Duplicating multiple files to a directory. Enter the file names and the destination path: Copying a file’s content to another within the same directory. Enter the source and the destination file: Duplicating an entire directory. Pass the -R flag followed by the source and destination directory:
  • 15. BASIC LINUX COMMANDS EXAMPLES Use the mv command to move or rename files and directories. To move items, enter the file name followed by the destination directory: The touch command lets you create an empty file in a specific directory path. Here’s the syntax: The file command lets you check a file type – whether it is a text, image, or binary. Here’s the syntax: To bulk-check multiple files, list them individually or use their path if they are in the same directory. Add the -k option to display more detailed information and -i to show the file’s MIME type. Meanwhile, use the following syntax to rename a file in Linux with the mv command:
  • 16. BASIC LINUX COMMANDS EXAMPLES The zip command lets you compress items into a ZIP file with the optimal compression ratio. For example, this command compresses note.txt into archive.zip in the current working directory: Use the unzip command to extract the compressed file. Here’s the syntax: unzip [option] file_name.zip The tar command archives multiple items into a TAR file – a format similar to ZIP with optional compression. Here’s the syntax: For instance, enter the following to create a new newarchive.tar archive in the /home/user/Documents directory:
  • 17. BASIC LINUX COMMANDS EXAMPLES Linux lets users edit files using a text editor like nano, vi, or jed. While most distributions include nano and vi, users must install jed manually. All these tools have the same command syntax: If the target file doesn’t exist, these editors will create one. We recommend nano if you want to quickly edit text files. Meanwhile, use vi or jed for scripting and programming.
  • 18. BASIC LINUX COMMANDS EXAMPLES Concatenate or cat is one of the most used Linux commands. It lists, combines, and writes file content to the standard output. Here’s the syntax: There are various ways to use the cat command: cat > filen.txt – creates a new file. cat file1.txt file2.txt > file3.txt – merges file1.txt with file2.txt and stores the output in filename3.txt. tac file.txt – displays content in reverse order. The global regular expression or grep command lets you find a word by searching the content of a file. This Linux command prints all lines containing the matching strings, which is useful for filtering large log files. For example, to display lines containing blue in the notepad.txt file, enter:
  • 19. BASIC LINUX COMMANDS EXAMPLES The sed command lets you find, replace, and delete patterns in a file without using a text editor. Here’s the general syntax: The script contains the searched regular expression pattern, the replacement string, and subcommands. Use the s subcommand to replace matching patterns or d to delete them. At the end, specify the file containing the pattern to modify. Here’s an example of a command that replaces red in colors.txt and hue.txt with blue:
  • 20. BASIC LINUX COMMANDS EXAMPLES The head command prints the first ten lines of a text file or piped data in your command-line interface. Here’s the general syntax: The head command accepts several options, such as: -n – changes the number of lines printed. For example, head -n 5 shows the first five lines. -c – prints the file’s first customized number of bytes. -q – disables headers specifying the file name. For instance, to view the first ten lines of note.txt in the current directory, enter:
  • 21. BASIC LINUX COMMANDS EXAMPLES The tail command displays the last ten lines of a file, which is useful for checking new data and errors. Here’s the syntax: For example, enter the following to show the last ten lines of the colors.txt file: The awk command scans regular expression patterns in a file to retrieve or manipulate matching data. Here’s the basic syntax: The action can be mathematical operations, conditional statements like if, output expressions such as print, and a delete command. It also contains the $n notation, which refers to a field in the current line. To add multiple actions, list them based on the execution order, separated using semicolons.
  • 22. BASIC LINUX COMMANDS EXAMPLES The sort command rearranges lines in a file in a specific order. It doesn’t modify the actual file and only prints the result as Terminal outputs. Here’s the syntax: By default, this command will sort the lines in alphabetical order, from A to Z. To modify the sorting, use these options: -o – redirects the command outputs to another file. -r – reverses the sorting order to descending. -n – sorts the file numerically. -k – reorders data in a specific field.
  • 23. BASIC LINUX COMMANDS EXAMPLES The cut command retrieves sections from a file and prints the result as Terminal outputs. Here’s the syntax: Instead of a file, you can use data from standard input. To determine how the command sections the line, use the following options: -f – selects a specific field. -b – cuts the line by a specified byte size. -c – sections the line using a specified character. -d – separates lines based on delimiters. You can combine these options, use a range, and specify multiple values. For example, this command extracts the third to fifth field from a comma-separated list:
  • 24. BASIC LINUX COMMANDS EXAMPLES The cut command retrieves sections from a file and prints the result as Terminal outputs. Here’s the syntax: Instead of a file, you can use data from standard input. To determine how the command sections the line, use the following options: -f – selects a specific field. -b – cuts the line by a specified byte size. -c – sections the line using a specified character. -d – separates lines based on delimiters. You can combine these options, use a range, and specify multiple values. For example, this command extracts the third to fifth field from a comma-separated list:
  • 25. BASIC LINUX COMMANDS TASK1 1. Create directory /home/[username]/system administration/student/ (Hint 1 p11.)(to use space in name use backslash ex: mkdir name surname make folder ‘name surname’) 2. Create text file with your name ex: /home/[username]/system administration/student/Takhirov Abdulaziz.txt (Hint 2 p17.) 3. Fill up content of a file with 5 lines where provide information n following format 1st line: City where you live, 2nd line: date of birth (year only), 3rd line: your hobby, 4th line: favorite color, 5th line: favorite book. 4. Move file with your name to home folder (/home) (Hint 3 p15.) (in case of permission denied use command sudo su-) 5. Make copy of file with name student.txt (Hint 4 p14. cp) 6. List all files and directories inside of home folder (Hint 5 p11.) 7. Sort lines of file student.txt in descending format show in terminal (Hint 6 p22.)
  • 26. BASIC LINUX COMMANDS EXAMPLES The diff command compares two files’ content and outputs the differences. It is used to alter a program without modifying the code. Here’s the general format: Below are some acceptable options: -c – displays the difference between two files in a context form. -u – shows the output without redundant information. -i – makes the diff command case insensitive.
  • 27. BASIC LINUX COMMANDS EXAMPLES The tee command writes the user’s input to Terminal’s output and files. Here’s the basic syntax: For example, the following pings Google and prints the output in Terminal, ping_result.txt, and the 19092023.txt file: The locate command lets you find a file in the database system. Add the -i option to turn off case sensitivity and an asterisk (*) to find content with multiple keywords. For example: The command searches for files containing school and note, regardless of their letter case.
  • 28. BASIC LINUX COMMANDS EXAMPLES Use the find command to search for files within a specific directory. Here’s the syntax: For example, to find a file called file1.txt within the directory folder and its subdirectories, use this command: If you omit the path, the command will search the current working directory. You can also find directories using the following:
  • 29. BASIC LINUX COMMANDS EXAMPLES Superuser do or sudo is one of the most basic commands in Linux. It runs your command with administrative or root permissions. Here’s the general syntax: When you run a sudo command, Terminal will request the root password. For example, this snippet runs useradd with the superuser privilege: You can also add an option, such as: -k – invalidates the timestamp file. -g – executes commands as a specified group name or ID. -h – runs commands on the host. Warning! Running a command with sudo privileges can modify all aspects of your system. Since misusing it may break your system, run the command with caution and only if you understand its possible repercussions.
  • 30. BASIC LINUX COMMANDS EXAMPLES The su command lets you run a program in the Linux shell as a different user. It is useful to connect via SSH while the root user is disabled. Here’s the syntax: Without any option or argument, this command runs through root and prompts you to use the sudo privileges temporarily. Some options are: -p – keeps the same shell environment, consisting of HOME, SHELL, USER, and LOGNAME. -s – lets you specify another shell environment to run. -l – runs a login script to switch users. It requires you to enter the user’s password. To check the current shell’s user account, run the whoami command:
  • 31. BASIC LINUX COMMANDS EXAMPLES The chmod command modifies directory or file permissions in Linux. Here’s the basic syntax: In Linux, each file is associated with three user classes – owner, group member, and others. It also has three permissions – read, write, and execute. If an owner wants to grant all permissions to every user, the command looks like this: The number determines the file permissions. Read, write, and execute are represented by a numerical value: •r (read) – 4 •w (write) – 2 •x (execute) – 1 If you don’t want to give any permission to a user, enter 0 into the corresponding spot.
  • 32. BASIC LINUX COMMANDS EXAMPLES If you don’t want to give any permission to a user, enter 0 into the corresponding spot. Common permissions for directories:
  • 33. BASIC LINUX COMMANDS EXAMPLES The chown command lets you change a file, directory, or symbolic link’s ownership to the specified username. Here’s the syntax: For example, to make linuxuser2 the owner of filename.txt, use: One of the most popular options that you can combine with chmod and chown is -R (Recursive). This Linux option allows you to edit permissions or owners of all files and subdirectories inside a specific directory. -f or force. The command line will ignore any errors and apply the chmod and chown commands. -v (verbose) option gives you diagnostics of all files that are processed by the command. -c (changes) is similar to the -v option. However, it will only provide information when changes were successfully made.
  • 34. BASIC LINUX COMMANDS EXAMPLES Use useradd to create a new Linux user account and change its password with the passwd command. Here are the syntaxes: Both the useradd and passwd commands require sudo privileges. To delete a user, use the userdel command:
  • 35. BASIC LINUX COMMANDS EXAMPLES Use the df command to check a Linux system’s disk space usage in percentage and kilobyte (KB). Here’s the syntax: Add an option to the df command for detailed disk space checking in Linux. Popular options include: df -h – shows the result in a human-readable format. df -m – displays file system usage information in MB. df -k – tells users the file system usage in KB. df -T – specifies the file system type in a new column. df /home – allows you to view information about a specific file system in a readable format. In this example, it’s the /home file system. df – help – lists other options to use and their descriptions.
  • 36. BASIC LINUX COMMANDS EXAMPLES Use du to check a file or directory’s storage consumption. Remember to specify the directory path when using this command, for example: The du command has several options, such as: -s – shows the specified folder’s total size. -m – provides folder and file information in MB. -k – displays information in KB. -h – informs the displayed folders and files’ last modification date.
  • 37. BASIC LINUX COMMANDS EXAMPLES The top command displays running processes and the system’s real-time condition, including resource utilization. It helps identify resource-intensive processes, enabling you to disable them easily. The htop command is an interactive program for monitoring system resources and server processes. Unlike top, it offers additional features like mouse operation and visual indicators. Here’s the command syntax: It supports options such as: -d – shows the delay between updates in tenths of seconds. -C – enables monochrome mode. -h – displays the help message and exits.
  • 38. BASIC LINUX COMMANDS EXAMPLES The uname or unix name command prints information about your machine, including its hardware, system name, and Linux kernel. Here’s the basic syntax: While you can use it without an option, add the following to modify the command: -a – prints all the system information. -s – outputs the kernel name. -n – shows the system’s node hostname.
  • 39. BASIC LINUX COMMANDS EXAMPLES Run the hostname command to display the system’s hostname. Here’s the syntax: You can run it without an option or use the following: -a – displays the hostname’s alias. -A – shows the machine’s Fully Qualified Domain Name (FQDN). -i – outputs the machine’s IP address.
  • 40. BASIC LINUX COMMANDS EXAMPLES Use time to measure commands’ execution time. Here’s the syntax: To measure a series of commands, separate them using semicolons or double ampersands (&&). For example, we will measure cd, touch, and chmod commands’ overall execution time:
  • 41. BASIC LINUX COMMANDS EXAMPLES The systemctl command lets you manage installed services in your Linux system. Here’s the basic syntax: To use the command, the user must have root privilege. It has several use cases, including starting, restarting, and terminating a service. You can also check a service’s status and dependencies.
  • 42. BASIC LINUX COMMANDS EXAMPLES The watch command lets the user continuously run another utility at a specific interval and print the results as a standard output. Here’s the syntax: It is useful for monitoring command output changes. To modify its behavior, use the following options: -d – displays the differences between command executions. -n – changes the default two-second interval. -t – disables the header containing the time interval, command, timestamp, and hostname.
  • 43. BASIC LINUX COMMANDS EXAMPLES The jobs command displays a shell’s running processes with their statuses. It is only available in csh, bash, tcsh, and ksh shells. Here’s the basic syntax: To check the status of jobs in the current shell, enter jobs without any arguments in Terminal. The command will return an empty output if your system doesn’t have running jobs. You can also add the following options: -l – lists process IDs and their information. -n – shows jobs whose statuses have changed since the last notification. -p – displays process IDs only.
  • 44. BASIC LINUX COMMANDS EXAMPLES Use the kill command to terminate an unresponsive program using its identification number (PID). To check the PID, run the following command: To stop the program, enter the syntax below: There are 64 signals for terminating a program, but SIGTERM and SIGKILL are the most common. SIGTERM is the default signal that lets the program save its progress before stopping. Meanwhile, SIGKILL forces programs to stop and discard unsaved progress.
  • 45. BASIC LINUX COMMANDS EXAMPLES The Linux shutdown command lets you turn off or restart your system at a specific time. Here’s the syntax: You can use an absolute time in a 24-hour format or a relative one like +5 to schedule it in five minutes. The message is a notification sent to logged-in users about the system shutdown. Instead of shutting down, restart the system using the -r option. To cancel a scheduled reboot, run the command with the -c option.
  • 46. BASIC LINUX COMMANDS EXAMPLES The ping command is one of the most used commands in Linux. It lets you check whether a network or server is reachable, which is useful for troubleshooting connectivity issues. Here’s the syntax: For example, run the following to check the connection and response time to Google:
  • 47. BASIC LINUX COMMANDS EXAMPLES Use the wget command to download files from the internet using HTTP, HTTPS, or FTP protocols. Here’s the syntax: For example, enter the following to download the latest version of WordPress:
  • 48. BASIC LINUX COMMANDS EXAMPLES The curl command transfers data between servers. Its common usage is for retrieving a web page’s content to your system using its URL. Here’s the syntax: However, you can add various options to modify the curl command behavior for other tasks. Some of the most popular ones include: -o or -O – downloads files from a URL. -X – changes the default HTTP GET method. -H – sends a custom header to the URL. -F – uploads a file to the specified destination.
  • 49. BASIC LINUX COMMANDS EXAMPLES The scp command securely copies files or directories between systems over a network. Here’s the syntax: For a local machine, omit the hostname and IP address. Use the following options to modify the copying behavior: -P – changes the port for copying. The default is 22. -l – limits the scp command’s bandwidth. -C – compresses transferred data to make it smaller.
  • 50. BASIC LINUX COMMANDS EXAMPLES The scp command securely copies files or directories between systems over a network. Here’s the syntax: For a local machine, omit the hostname and IP address. Use the following options to modify the copying behavior: -P – changes the port for copying. The default is 22. -l – limits the scp command’s bandwidth. -C – compresses transferred data to make it smaller.
  • 51. BASIC LINUX COMMANDS EXAMPLES The rsync command lets you sync files or folders between two destinations to ensure they have the same content. Here’s the syntax: If your destination or source is a folder, enter the directory path like /home/directory/path. To sync a remote server, use its hostname and IP address, like host@185.185.185.185. -a – enables archive mode to preserve file permissions, dates, and other attributes. -v – shows visual information about the transferred file. -z – compresses the transferred file data to reduce their size.
  • 52. BASIC LINUX COMMANDS EXAMPLES The ifconfig command lets you list and configure your system’s network interface. In newer Linux distros, it is equivalent to the ip command. Here’s the basic syntax: Running it without arguments displays information about all network interfaces in your system. To check a specific interface, add its name as an argument without an option. For a more specific task, use the following options: •–s – summarizes the network interfaces and their configuration. This option goes before the interface name. •up and down – enables and disables a network interface. •inet and inet6 – assigns an IPv4 and IPv6 address to a network interface. •netmask – specifies the subnet mask to use with an IPv4 address.
  • 53. BASIC LINUX COMMANDS EXAMPLES The ifconfig command lets you list and configure your system’s network interface. In newer Linux distros, it is equivalent to the ip command. Here’s the basic syntax: Running it without arguments displays information about all network interfaces in your system. To check a specific interface, add its name as an argument without an option. For a more specific task, use the following options: –s – summarizes the network interfaces and their configuration. This option goes before the interface name. up and down – enables and disables a network interface. inet and inet6 – assigns an IPv4 and IPv6 address to a network interface. netmask – specifies the subnet mask to use with an IPv4 address.
  • 54. BASIC LINUX COMMANDS EXAMPLES The netstat command is used to display your system’s network information, like sockets and routing. Here’s the command syntax: Running it without arguments displays information about all network interfaces in your system. To check a specific interface, add its name as an argument without an option. For a more specific task, use the following options: –s – summarizes the network interfaces and their configuration. This option goes before the interface name. up and down – enables and disables a network interface. inet and inet6 – assigns an IPv4 and IPv6 address to a network interface. netmask – specifies the subnet mask to use with an IPv4 address.
  • 55. BASIC LINUX COMMANDS EXAMPLES The traceroute command tracks a packet’s path when it moves to another host over a network. It gives you information about the involved routers and travel time. Here’s the syntax: You can use a domain, hostname, or IP address as the destination. Add the following options for more detailed packet monitoring: •-m – sets each packet’s maximum hops. •-n – prevents the command from resolving IP addresses to hostnames for quicker tracing. •-I – changes the default UDP packets to UCMP. •-w – adds a timeout in seconds.
  • 56. BASIC LINUX COMMANDS EXAMPLES The nslookup command queries a DNS server to find out the domain associated with an IP address and vice versa. Here’s the syntax: If you don’t specify the DNS server to use, nslookup will use the default resolver from your system or internet service provider. This command supports various options, with some commonly used ones being: -type= – queries specific information, like the IP address type or MX record. -port= – sets the DNS server’s port number for the query. -retry= – repeats the query a specific number of times upon failure. -debug – enables the debug mode to provide more information about the query.
  • 57. BASIC LINUX COMMANDS TASK2 1. Restart system and login by root, Delete user created while installing system from system except root 2. Create user cambridge1 with password at least 6 minimum length 3. Create user cambridge2 with password at least 6 minimum length 4. Create user cambridge3 with password 5. Create file file[x].txt in [username]/documents/ for each user with text ‘This text file owned by [username]’ cambridge1documentsfile1.txt cambridge2documentsfile2.txt cambridge3documentsfile3.txt 6. Set permission for file1.txt read for [cambridge2] 7. Set permission for file3.txt read write for [cambridge2] 8. Set permission for file2.txt read write execute for [cambridge1] 9. Set ownership for file3.txt [cambridge2] with changing text ‘This text file owned by [username]’. 10. Set permission for file3.txt [cambridge1] read permission and [cambridge3] read write execute 11. Move file1.txt, file2.txt, file3.txt to [cambridge1]/documents/ file1.txt file1.txt file2.txt folder and change ownership [cambridge1] 12. Show memory consumption of folder [cambridge1]/documents/
  • 58. BASIC LINUX COMMANDS EXAMPLES The dig or domain information groper command gathers DNS data from a domain. Unlike nslookup, it is more detailed and versatile. Here’s the syntax: Replace target with a domain name. By default, this command only shows A record type. Change query_type to check a specific type or use ANY to query all of them. To run a reverse DNS lookup, add the -x option and use the IP address as the target. [name] – the name of the resource record that is to be looked up. [type] – the type of query requested by dig. For example, it can be an A record, MX record, SOA record or any other types. By default dig performs a lookup for an A record if no type argument is specified.
  • 59. BASIC LINUX COMMANDS EXAMPLES Enter history to list previously executed commands. It lets you reuse the commands without rewriting them. To use it, enter this syntax with sudo privileges: To rerun a specific utility, enter an exclamation mark (!) followed by the command’s list number. For example, use the following to rerun the 24th command: his command supports many options, such as: -c – clears the history list. -d offset – deletes the history entry at the OFFSET position. -a – appends history lines.
  • 60. BASIC LINUX COMMANDS EXAMPLES The man command provides a user manual of any Linux Terminal utilities, including their names, descriptions, and options. It consists of nine sections: If you only use the command name as the parameter, Terminal displays the full user manual. Here’s an example command to query section 1 of the ls command manual:
  • 61. BASIC LINUX COMMANDS EXAMPLES The echo command displays a line of text as a standard output. Here’s the basic command syntax: For example, you can display System administration by entering: This command supports many options, such as: -n – displays the output without the trailing newline. -e – enables the interpretation of the following backslash escapes: b – removes spaces in between a text. c – produces no further output.
  • 62. BASIC LINUX COMMANDS EXAMPLES The ln command lets you create links between files or directories to simplify system management. Here’s the syntax: For example, to link the /user/local/downloads/logo directory to /devisers folder, use the following command: This command supports many options, such as: You can remove existing links attached to files or directories by the unlink or rm command. This is how you can do it with the unlink command:
  • 63. BASIC LINUX COMMANDS EXAMPLES The alias command instructs the shell to replace a string with another, allowing you to create a shortcut for a program, file name, or text. Here’s the syntax: For example, enter the following to make k the alias for the kill command: This command doesn’t give any output. To check the alias associated with a command, run the following: To delete an existing alias, use the unalias command with the following syntax:
  • 64. BASIC LINUX COMMANDS EXAMPLES The cal command outputs a calendar in the Linux Terminal. It will show the current date if you don’t specify the month and year. Here’s the syntax: The month is in the numerical representation from 1–12. To modify the command output, add the following options: The month is in the numerical representation from 1–12. To modify the command output, add the following options: -1 – outputs the calendar in a single line. -3 – shows the previous, current, and next month. -A and -B – displays the specified number of months after and before the current one. -m – starts the calendar with Monday instead of Sunday.
  • 65. BASIC LINUX COMMANDS EXAMPLES apt-get is a command line tool for handling Advanced Package Tool (APT) libraries in Debian-based Linux, like Ubuntu. It requires sudo or root privileges. This Linux command lets you manage, update, remove, and install software, including its dependencies. Here’s the main syntax: These are the most common commands to use with apt-get: update – synchronizes the package files from their sources. upgrade – installs the latest version of all installed packages. check – updates the package cache and checks broken dependencies.