Loading...

Linux 60 Comands | Part-2 | Forum

Topic location: Forum home » General » General Chat
Admin
Admin Yesterday, 14:20

33. top command

The top command displays real-time information about running processes and system resource usage.


Syntax:


top [options]

Common options:

• -p → monitors a specific process by its ID (PID)

• -d → sets the delay between screen updates

• -u → shows processes for a specific user


Example:


top -u root

Displays real-time resource usage for processes owned by the root user, helping you monitor system performance and identify resource-heavy tasks.


34. htop command

The htop command displays and manages running processes in an interactive interface.


Syntax:


htop [options]

Common options:

• -d → sets the update interval

• -u → shows processes for a specific user

• --tree → displays processes in a hierarchical tree view


Example:


htop

Opens an interactive process viewer that shows CPU and memory usage, allowing you to navigate, filter, and manage processes in real time.


35. ps command

The ps command displays a snapshot of currently running processes.


Syntax:


ps [options]

Common options:

• -A → shows all running processes

• -u → displays processes for a specific user

• -r → lists only running processes


Example:


ps -A

Displays all active processes on the system at a specific moment, allowing you to inspect process IDs, statuses, and resource usage.


36. uname command

The uname command displays system information such as the kernel, architecture, and operating system.


Syntax:


uname [options]

Common options:

• -a → displays all available system information

• -r → shows the kernel release version

• -m → displays the machine hardware architecture


Example:


uname -a

Displays complete system information, including kernel version and architecture, helping you identify your Linux environment.


37. hostname command

The hostname command displays or sets the system’s hostname.


Syntax:


hostname [options]

Common options:

• -i → displays the IP address of the host

• -a → shows the hostname alias

• -A → displays the fully qualified domain name (FQDN)


Example:


hostname -A

Displays the system’s fully qualified domain name, helping identify the server within a network or domain.


38. time command

The time command measures how long a command or script takes to execute.


Syntax:


time command

Common options: (no commonly used options required for basic usage)


Example:


time ls -la

Measures how long the ls -la command takes to run, providing execution time details such as real, user, and system time.


39. systemctl command

The systemctl command manages services in your Linux system.


Syntax:


systemctl subcommand [service_name][options]

The subcommands represent your task, like listing, restarting, terminating, or enabling the services. For example, we will list Linux services using this:


sudo systemctl list-unit-files --type service --all

Note that this command might not work with older distributions since they use another service manager.


40. watch command

The watch command runs a command repeatedly at specified intervals and displays the updated output.


Syntax:


watch [options] command

Common options:

• -n → sets the interval in seconds between executions

• -d → highlights changes between updates


Example:


watch -n 5 netstat

Runs the netstat command every five seconds and updates the output, allowing you to monitor changes in network activity over time.


41. jobs command

The jobs command lists background and suspended jobs in the current shell session.


Syntax:


jobs [options] [job_id]

Common options:

• -l → displays job IDs along with process IDs

• -n → shows only jobs that have changed status

• -p → lists only process IDs


Example:


jobs -l

Displays all jobs in the current shell with their process IDs, allowing you to monitor and manage background tasks.


42. kill command

The kill command sends a signal to terminate or control a process by its process ID (PID).


Syntax:


kill [signal] process_id

Common options:

• -15 → sends the default SIGTERM signal for graceful termination

• -9 → sends SIGKILL to forcefully terminate a process

• -l → lists all available signals


Example:


kill -9 1234

Forcefully terminates the process with ID 1234, which is useful when a program becomes unresponsive.


43. shutdown command

The shutdown command powers off or restarts the system at a specified time.


Syntax:


shutdown [options] [time] [message]

Common options:

• -r → restarts the system instead of shutting it down

• -h → halts or powers off the system

• -c → cancels a scheduled shutdown


Example:


shutdown -r +5

Schedules a system restart in five minutes, allowing users to prepare before the system goes offline.


44. ping command

The ping command sends network packets to a target host and measures the response time.


Syntax:


ping [options] [hostname_or_ip]

Common options:

• -c → specifies the number of packets to send

• -i → sets the interval between packets

• -s → defines the packet size


Example:


ping -c 15 -i 2 google.com

Sends 15 packets to google.com at two-second intervals, allowing you to test connectivity and measure network latency.


45. wget command

The wget command downloads files from the internet using HTTP, HTTPS, or FTP protocols.


Syntax:


wget [options] [url]

Common options:

• -O → saves the file with a custom name

• -c → resumes a partially downloaded file

• -q → runs in quiet mode without output


Example:


wget https://wordpress.org/latest.zip

Downloads the file from the specified URL to the current directory, allowing you to retrieve remote resources directly from the terminal.


46. cURL command

The curl command transfers data to or from a server using a specified URL.


Syntax:


curl [options] url

Common options:

• -O → downloads a file and saves it with its original name

• -o → saves the file with a custom name

• -X → specifies the HTTP method (GET, POST, PUT, DELETE)


Example:


curl -X GET https://api.example.com/endpoint

Sends a GET request to the specified API endpoint and returns the response, allowing you to test APIs or retrieve remote data directly from the terminal.


47. scp command

The scp command securely copies files and directories between local and remote systems over SSH.


Syntax:


scp [options] source destination

Common options:

• -P → specifies a custom SSH port

• -r → copies directories recursively

• -C → enables compression during transfer


Example:


scp file1.txt root@185.185.185.185:/path/to/folder

Copies file1.txt from the local machine to the remote server at /path/to/folder, allowing secure file transfer between systems.


48. rsync command

The rsync command synchronizes files and directories between locations while minimizing data transfer.


Syntax:


rsync [options] source destination

Common options:

• -a → preserves file attributes (permissions, timestamps, symbolic links)

• -z → compresses data during transfer

• -v → displays detailed transfer output


Example:


rsync -avz /path/to/local/folder/ vps-user@185.185.185.185:/path/to/remote/folder/

Synchronizes the local folder with the remote directory while preserving attributes and compressing data, resulting in faster, more efficient transfers.


49. ip command

The ip command displays and manages network interfaces, addresses, and routing.


Syntax:


ip [options] object command

Common options:

• address → manages and displays IP addresses

• link → manages network interfaces

• route → displays or modifies routing tables


Example:


ip address show

Displays all network interfaces and their assigned IP addresses, helping you inspect and troubleshoot network configuration.


50. netstat command

The netstat command displays network connections, routing tables, and interface statistics.


Syntax:


netstat [options]

Common options:

• -a → shows all connections, including listening sockets

• -t → displays TCP connections

• -u → displays UDP connections

• -r → shows routing tables


Example:


netstat -tuln

Displays all listening TCP and UDP ports, helping you identify active network services and open ports.


51. traceroute command

The traceroute command tracks the path packets take to reach a destination host.


Syntax:


traceroute [options] destination

Common options:

• -m → sets the maximum number of hops

• -n → disables DNS resolution for faster output

• -w → sets the timeout in seconds for each response


Example:


traceroute google.com

Displays each hop between your system and google.com, helping you identify network delays or routing issues.


52. nslookup command

The nslookup command queries DNS servers to retrieve domain or IP address information.


Syntax:


nslookup [options] domain_or_ip [dns_server]

Common options:

• -type= → specifies the DNS record type (e.g., A, MX, TXT)

• -retry= → sets the number of query retries

• -port= → uses a specific DNS server port


Example:


nslookup -type=MX example.com

Retrieves the mail exchange (MX) records for example.com, helping you inspect DNS configuration and troubleshoot domain-related issues.


53. dig command

The dig command queries DNS records and provides detailed information about a domain or IP address.


Syntax:


dig [options] [server] [type] name_or_ip

Common options:

• -x → performs a reverse DNS lookup

• +short → displays a concise output

• @server → queries a specific DNS server


Example:


dig MX domain.com

Retrieves the mail exchange (MX) records for domain.com, helping you analyze DNS configuration and troubleshoot domain resolution issues.


54. history command

The history command displays a list of previously executed commands in the current shell session.


Syntax:


history [options]

Common options:

• -c → clears the command history

• -r → reads the history file and appends it to the current session

• -d → deletes a specific entry by its ID


Example:


!145

Re-executes the command with ID 145 from the history list, allowing you to quickly repeat previously used commands.


55. man command

The man command displays the manual page for a specified command.


Syntax:


man [options] [section_number] command_name

Common options:

• -k → searches manuals for keywords

• -f → displays a short description of a command

• -a → shows all available manual pages for a command


Example:


man 3 ls

Displays the section 3 manual page for ls, allowing you to access detailed documentation for specific command categories.


56. echo command

The echo command outputs text or variables to the terminal or a file.


Syntax:


echo [options] [text]

Common options:

• -n → removes the trailing newline from output

• -e → enables interpretation of escape sequences (e.g., n, t)


Example:


echo "Hello World" > file.txt

Writes Hello World to file.txt, allowing you to create or overwrite files with custom text output.