Examples

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

A.

LINUX INSTALLATION

B. MANAGING CLI COMMANDS

Welcome to our quick guide on Managing CLI Commands! In this brief tutorial, we'll navigate
the essentials of Command Line Interface (CLI) management. Let's dive in!

Command Line Interface (CLI) is a powerful and efficient tool for interacting with a computer
system through text commands.

Working with Ubuntu on a Virtual Box, terminal, as the command-line interface, becomes your
gateway to efficiently manage your Ubuntu environment.

1. cd

The cd command, which stands for "change directory," is a command-line command


used to change the current working directory in a command-line interface or shell. It allows
you to navigate through the file system by moving from one directory to another.

The basic syntax of the cd command is:

cd [directory]

Examples:

1. Change directory to "/home/user/Documents"


Command: cd /home/user/Documents
2. Move up one level in the directory structure
Command: cd ..
3. Change to the root directory
Command: cd /

2. ls

The ls command is used in Unix and Unix-like operating systems (including Linux) to list the
files and directories in the current directory. It provides a simple way to view the contents of a
directory.

The basic syntax of the ls command is:

ls [options] [files or directories]

Examples:

1. List files and directories in the current directory


Command: ls
2. List files in long format with detailed information
Command: ls -l
3. List all files, including hidden ones
Command: ls -a

3. whoami
The whoami command is a Unix and Unix-like operating system command that prints
the username associated with the current effective user ID. When you run the whoami
command, it simply outputs the username of the user who is currently logged in or executing
the command.

Here's the basic usage:

Whoami

Examples:

1. Display the username of the current user


Command: whoami
2. Display the username with superuser privileges
Command: sudo whoami
3. Display both the username and user ID.
Command: whoami && id

4. who

The who command is used in Unix and Unix-like operating systems to display
information about users who are currently logged into the system. It provides details such as
usernames, terminal names, login times, and originating IP addresses (if applicable).

The basic syntax of the who command is:

who

Examples:

1. Display information about users currently logged in


Command: who
2. Display only the number of logged-in users
Command: who -q
3. Display information about all users, including system processes
Command: who -a

5. w

The w command is used in Unix and Unix-like operating systems to display information about
the users who are currently logged in and their activities. The w command provides details such as
the username, terminal, remote host (if applicable), login time, idle time, JCPU (total CPU time used
by all processes attached to the terminal), and more.

Here is the basic usage of the w command:

Examples:

1. Display information about currently logged-in users and their activities


Command: w
2. Display a shorter format without header information
Command: w -h
3. Display information for a specific user
Command: w -u username

6. pwd

The pwd command stands for "print working directory." It is used in Unix and Unix-like
operating systems to display the current working directory, which is the directory that the user is
currently in within the file system.

Here's the basic usage:

Pwd

Examples:

1. Print the current working directory


Command: pwd
2. Print the physical current working directory (resolved symlink)
Command: pwd -P
3. Print the logical current working directory (unresolved symlink)
Command: pwd -L

7. ip addr

The ip addr command is used in Unix-like operating systems, including Linux, to display
information about network interfaces and their associated IP addresses. It provides detailed
information about the current network configuration of a system.

Here's the basic usage of the ip addr command:

ip addr

Examples:

1. Show information about network interfaces


Command: ip addr show
2. Add an IP address to the eth0 interface
Command: ip addr add 192.168.1.2/24 dev eth0
3. Remove an IP address from the eth0 interface
Command: ip addr del 192.168.1.2/24 dev eth0

8. nmcli

The nmcli command is a command-line client for NetworkManager, a Linux utility for
managing network connections. The nmcli device status command is used to

Here's the basic usage of the command:


nmcli

Examples:

1. Display the status of network devices managed by NetworkManager


Command: nmcli device status
2. Display the general overview of the NetworkManager status, including the overall
connectivity, the state of the NetworkManager service, and whether it is actively
managing devices
Command: nmcli general status
3. Lists all available network connections, including both active and inactive ones. It
displays information such as connection name, UUID, type, and status
Command: nmcli connection show

9. last

The last command is used in Unix and Unix-like operating systems to display information
about previously logged-in users and system reboots. It shows a list of login sessions, including the
username, terminal, IP address (if available), login and logout times, and other relevant information.

Here's the basic usage of the last command:

Last

Examples:

1. Show a list of last logged in users


Command: last
2. Display the last 5 logins
Command: last -n 5
3. Display IP addresses along with login information
Command: last -i

10. lastb

11. top

The top command is used in Unix and Unix-like operating systems to display real-time
information about system performance, processes, and resource utilization.

Here's the basic usage:

top

Examples:

1. Display a dynamic view of system processes


Command: top
2. Display processes for a specific user
Command: top -u username
3. Display the processes sorted by CPU usage, with the process consuming the highest CPU
at the top.
Command: top -o %CPU

12. dmidecode

The dmidecode command is a Linux and Unix command-line tool that provides detailed
information about a computer's hardware components, as retrieved from the system's DMI (Desktop
Management Interface) table. The DMI table contains information about the system's BIOS,
motherboard, memory, CPU, and other hardware components.

Here's the basic usage of the dmidecode command:

sudo dmidecode

Examples:

1. Display information about the system's hardware components


Command: dmidecode
2. Show details about the system memory
Command: dmidecode -t memory
3. Display information about the processor
Command: dmidecode -t processor

13. netstat

The netstat command is used to display various network-related information in Unix and
Unix-like operating systems, including Linux. It provides details about network connections, routing
tables, interface statistics, masquerade connections, and multicast memberships. netstat can be a
powerful tool for network troubleshooting and monitoring.

Here is the basic usage of the netstat command:

netstat [options]

Examples:

1. Display network connections, routing tables, interface statistics


Command: netstat
2. Show listening sockets for TCP and UDP
Command: netstat -tuln
3. Display the routing table
Command: netstat -r

14. df

The df command is used in Unix and Unix-like operating systems, including Linux, to display
information about disk space usage on file systems. It shows the amount of disk space used,
available, and total size for each mounted file system.

Here's the basic usage of the command:


df

Examples:

1. Display information about disk space usage


Command: df
2. Show disk space in human-readable format
Command: df -h
3. Display the filesystem type along with usage
Command: df -T

15. du

The du command, which stands for disk usage, is used in Unix and Unix-like operating
systems to estimate the space used by a directory and its subdirectories. It's a useful tool for
analyzing disk space usage on a file system.

Here's the basic usage of the du command:

du [options] [directory or file]

Examples:

1. Display disk usage of files and directories in the current directory


Command: du
2. Show disk usage in a human-readable format
Command: du -h
3. Display total disk usage for a specific directory
Command: du -s /path/to/directory

16. shutdown -r

The shutdown command is used to shut down or reboot a Unix or Unix-like system. It allows
you to initiate a system shutdown, bringing the system to a state where it can be safely powered off
or restarted.

Here's the basic usage of the shutdown command:

shutdown [options] [time] [message]

Examples:

1. Shut down and restart the system immediately


Command: shutdown -r now
2. Schedule a system restart in 1 minute
Command: shutdown -r +1
3. Cancel a scheduled system shutdown
Command: shutdown -c

17. hostname
The hostname command is used to show or set the system's hostname on Unix and Unix-like
operating systems, including Linux. The hostname is the label assigned to a device connected to a
computer network. It is often used to identify the system on a local network.

Here's the basic usage of the hostname command:

hostname

Examples:

1. Display the system's hostname


Command: hostname
2. Change the system's hostname
Here are the general steps to change the hostname on a Linux system:
1. Check the Current Hostname
Before changing the hostname, it's a good idea to check the current hostname
hostname
2. Edit the Hostname File
Edit the /etc/hostname file and replace the current hostname with the new one
sudo nano /etc/hostname
3. Edit the Hosts File
Edit the /etc/hosts file to associate the new hostname with the loopback address
(127.0.0.1) and your system's IP address. Open the file with a text editor
sudo nano /etc/hosts
You should see a line like:
127.0.0.1 localhost

Add the new hostname at the end of this line:

127.0.0.1 localhost new_hostname

Save the file and exit.

4. Apply the Changes


To apply the changes immediately, you can use the hostnamectl command
sudo hostnamectl set-hostname new_hostname
5. Restart the System or Reboot
For the changes to take effect, you may need to restart your system or reboot
sudo reboot
3. Display the system's IP address
Command: hostname -I

18. history

The history command in Linux is used to display the command history of the current user in
a terminal session. It shows a list of previously executed commands along with their respective
command numbers.

Here are some common ways to use the command:


History

Examples:

1. Display the command history of the current user


Command: history
2. Show the last 10 commands in the history
Command: history 10
3. Execute the last command that starts with "ls" from the history
Command: !ls

19. uptime

The uptime command in Linux is used to display how long the system has been running, as
well as various other system-related information. When you run the uptime command, it provides a
summary that includes the current time, the length of time the system has been running, the number
of users currently logged in, and the system load averages for the last 1, 5, and 15 minutes.

Here's an example of the uptime command output:

Uptime

Examples:

1. Display how long the system has been running


Command: uptime
2. Show the uptime in a more human-readable format
Command: uptime -p
3. Display the system's last boot time
Command: uptime -s

20. last reboot

The last reboot command in Linux provides information about the last time the system was
rebooted. It shows a historical log of system reboots, including the timestamp and information about
who initiated the reboot.

Here's an example of the command output:

last reboot

Examples:

1. Show the system's reboot history


Command: last reboot
2. Display the reboot history with full date and time
Command: last reboot -F
3. Show the last 5 system reboots
Command: last reboot -n 5

21. nslookup
The nslookup command is used for querying Domain Name System (DNS) servers to obtain
domain name or IP address mapping, or other DNS records. It's a useful tool for troubleshooting
DNS-related issues and obtaining information about domain names.

Examples:

1. Perform a DNS lookup for the domain "example.com"


Command: nslookup example.com
2. Perform a reverse DNS lookup for the IP address
Command: nslookup 192.168.1.1
3. Display mail server information for a domain
Command: nslookup -query=mx example.com
C. SEARCHING GRAPHICAL TOOLS

1. Find files in linux


a. -type
The -type option in the find command is used to filter files based on their type.
Common values for -type include:
f: Regular file
d: Directory
l: Symbolic link
b: Block special file
c: Character special file
p: Named pipe (FIFO)
s: Socket

Examples:

1. Find all directories in the current directory


Command: find . -type d
2. Locate all regular files with a .txt extension
Command: find . -type f -name "*.txt"
3. Search for symbolic links in the home directory.
Command: find ~/ -type l
b. -perm
The -perm option is used to search for files with specific permissions

Examples:

1. Find files with exact permissions 755 in the /var directory


Command: find /var -type f -perm 755
2. Locate files with read and write permissions for the owner in the /etc
directory
Command: find /etc -type f -perm -600
3. Search for files with group execute permission in the /usr directory
Command: find /usr -type f -perm -g=x

c. -size
The -size option allows you to search for files based on their size. You can specify
the size in kilobytes (k), megabytes (M), gigabytes (G), etc.

Examples:

1. Find files larger than 1GB in the home directory


Command: find ~/ -type f -size +1G
2. Locate files smaller than 100 kilobytes in the /tmp directory
Command: find /tmp -type f -size -100k
3. Search for empty files in the current directory
Command: find . -type f -empty
d. -ctime
The -ctime option searches for files based on their change time (ctime), which
includes modifications to the file's metadata

Examples:

1. Find files created within the last 24 hours in the /var/log directory
Command: find /var/log -type f -ctime -1
2. Locate files created between 3 and 7 days ago in the /home directory
Command: find /home -type f -ctime +3 -ctime -7
3. Search for files created exactly 30 days ago in the /opt directory
Command: find /opt -type f -ctime 30
e. -exec
The -exec option is used to execute a command on the files found by find. It allows
you to perform actions on the files, such as running a specific command.

Examples:

1. Find all text files in the current directory and print their contents
Command: find . -type f -name "*.txt" -exec cat {} \;
2. Move all text files to a different directory
Command: find /path/to/search -type f -name "*.txt" -exec mv {}
/path/to/destination/ \;
3. Delete all text files older than 1 day
Command: find /path/to/search -type f -name "*.txt" -ctime +1 -exec rm {}
\;

2. Locate command
The locate command in Linux is used to quickly search for the location of files and
directories on the system. It relies on a pre-built index of the file system, which makes it
faster than other file-searching methods like find. However, keep in mind that the locate
command may not always have the most up-to-date information since its database is
usually updated periodically.

Examples:

1. Locate files with "config" in their names


Command: locate config
2. Locate all Python files in the system (files with .py extension)
Command: locate *.py
3. Locate all PDF files in the system (files with .pdf extension)
Command: locate *.pdf

3. Whereis command
The whereis command is used to locate the binary, source code, and manual page
files for a command. It searches standard binary directories, manual page directories,
and source code directories.
Examples:

1. Locate information about the gcc compiler


Command: whereis gcc
2. Locate information about the ls command
Command: whereis ls
3. Locate information about the python3 interpreter
Command: whereis python3

4.Which command

The which command is used to locate the executable file associated with a given
command in the user's PATH.

Examples:

1. Identify the location of the ls command


Command: which ls
2. Identify the location of the grep command
Command: which grep
3. Identify the location of the nano text editor
Command: which nano

5.Type command

The type command is used to display information about a command, including its
location and whether it is an alias, keyword, function, or a built-in shell command.

Examples:

1. Check the type of the cd command


Command: type cd
2. Check the type of the ls command
Command type ls
3. Define an alias and check its type
Command: alias yssa='echo Hello, World!'
type yssa

You might also like