itsmeit.bizitsmeit.biz
  • Home
  • Windows
    • Windows Software
  • Ubuntu & Linux
    Ubuntu & Linux
    The top blog articles on Ubuntu and Linux, featuring valuable tips and tricks, empower you to master these operating systems and enhance your experience.
    Show More
    Top News
    How to install phpMyadmin with Nginx on Ubuntu 22.04 | 20.04
    How to install phpMyadmin with Nginx on Ubuntu 22.04 | 20.04
    November 11, 2023
    How to clean up junk files on Ubuntu 22.04 | 20.04 LTS
    How to clean up junk files on Ubuntu 22.04 | 20.04 LTS
    November 10, 2023
    How to use chmod command in Linux or Ubuntu with examples
    How to use chmod command in Linux or Ubuntu with examples
    November 11, 2023
    Latest News
    How to install Composer on Ubuntu 20.04 | 22.04 & Linux
    November 13, 2023
    How to Configure Redis Cache to Speed ​​Up WordPress Site
    November 15, 2023
    Install Ibus-bamboo or Ibus-unikey for Accented Letters on Ubuntu 22.04
    November 11, 2023
    How to install MariaDB on Ubuntu 22.04, 20.04 and Debian
    November 11, 2023
  • Web developer
    • Wordpress Theme
      • Blog News
      • Fashion Theme
      • Theme Elementor
      • WooCommerce Theme
    • Wordpress Plugin
    • Magento Developer
Reading: 14 Examples of Terminal command for Ubuntu and Linux/Unix
Share
Font ResizerAa
itsmeit.bizitsmeit.biz
Font ResizerAa
  • Linux & Ubuntu
  • Windows Tips & Trick
  • Windows Software
  • Log Out
Have an existing account? Sign In
Follow US
Copyright © 2022. All Rights Reserved.
Ubuntu & Linux

14 Examples of Terminal command for Ubuntu and Linux/Unix

duyanh
Last updated: November 10, 2023
By duyanh Published May 6, 2023
Share
SHARE

Table of contents

  1. 14 Examples of Terminal command for Ubuntu and Linux/Unix
    1. du;
    2. find;
    3. which;
    4. clear;
    5. locate;
    6. grep;
    7. sed;
    8. reset;
    9. echo;
    10. chmod;
    11. chown;
    12. whatis;
    13. top;
    14. sl;

Ubuntu is a popular open source operating system used on many computers. To effectively use Ubuntu or Linux, you need to master the terminal command for Ubuntu or Linux/Unix to perform various tasks. In this article, ItsmeIT will summarize some of the most important and useful commands, along with illustrative examples to help you get used to them. From there, you can easily perform tasks like file management, software installation, etc.

14 Examples of Terminal command in Linux or Ubuntu (illustration)
14 Examples of Terminal command in Linux or Ubuntu (illustration)

14 Examples of Terminal command for Ubuntu and Linux/Unix

du;

The (Disk Usage) command du is a terminal command for Ubuntu or Ubuntu operating systems that is used to display the disk space used by files and folders in a specific directory or in the entire file system of the machine. count. du stands for “disk usage” and is used to check the space usage of files and folders on disk.

14 Examples of Terminal command for Ubuntu and Linux/Unix

The options used with du enable disk space information to be displayed in various ways, such as displaying capacity in different units (KB, MB, GB), sorting results by size size or modification time, and more.

Here are examples of how to use the command du in Ubuntu or Linux debian to show disk space used by subdirectories of a particular directory, but excluding that directory:

du -h --max-depth=1 /path/to/directory
Terminal command for Ubuntu and Linux/Unix with echo

As you can see in the screenshot, 2.8G is all my MYSQL space used.

In there:

  • -s: is to display only the results of the root directory /var/lib/mysql, instead of displaying the results of the files and subdirectories inside.
  • -h: option to show used disk space in units (KB, MB, GB) instead of bytes.

Another example that combines the option -ah to check the file size in a specific directory:

sudo du -ah ~/Downloads
Terminal command for Ubuntu and Linux/Unix with du
The terminal command in Ubuntu or Linux/Unix is “du”(illustration)

In there:

  • -a: option to show all files and folders, including hidden files.
  • -h: option to show used disk space in units (KB, MB, GB) instead of bytes.

There are some other options like: –time, -c, –total, -X, –exclude=Pattern, you also do the same as the above examples to see how the results are.

  • --time: option to show modification times of files and folders.
  • -c: option to show total size of files and folders.
  • --total: option to show total size of all browsed files and folders.
  • -X: option to exclude files and directories listed in EXCLUDE.
  • --exclude=Pattern: option to exclude files and folders whose names match the pattern Pattern.

find;

Command find is one of the very popular terminal command for ubuntu and linux/unix, it is used to search and display files and folders in a directory tree based on many criteria such as filename, creation date, size, etc. , access rights and many other criteria.

find command in ubuntu find command linux

The command find also supports many options for searching files and directories with various custom configurations, allowing users to define complex search conditions, including recursive searching in directories. con, regular file search, hidden files, etc.

which;

Commands which use environment variables PATH to search for commands or programs. PATH is an environment variable that stores the paths where the system will look for programs to be executed. When you enter a command on the command line, the system searches for that command in the directories listed in the environment variable PATH.

The command which is one of the terminal command for Ubuntu or Linux debian that is very useful for developers and system administrators in determining the location of programs installed on their system.

Example test mysql working path:

which mysql
terminal command for ubuntu and linux unix 7

The returned result will be the absolute path of mysql the system. If mysql installed in the directory /usr/bin/, the result will be /usr/bin/mysql.

clear;

The terminal command clear in Ubuntu and other Linux operating systems is used to wipe the display, remove any information, command lines, results or any displayed data on the terminal, and return to the original position. top of the first line of the screen.

clear

The command clearis often used when you want to clean the terminal to easily observe and perform other tasks on the terminal more conveniently.

locate;

Command locate is one of the commands in ubuntu, linux used to find the location of a particular file. This is one of the simplest commands you can take advantage of when you are unsure about the location of a particular file on your Linux computer.

sudo apt install mlocate

Syntax to use:

locate [options] pattern

The locate and find command are both used for searching files and directories in a computer file system. However, the locate command operates faster and is suitable for name-based searches, whereas the find command is more powerful with various features that allow users to search based on different criteria such as size, creation time, and ownership.

The terminal command in Ubuntu or Linux/Unix is "locate"(illustration)
The terminal command in Ubuntu or Linux/Unix is “locate”(illustration)
  1. Speed: locate usually faster find because it uses a pre-created database to store information about files and folders on the system. When using locate, the system only needs to search this database instead of scanning the entire file system. Meanwhile, find will search the entire file system, so will be slower.
  2. Update the database: Since locate it uses a pre-created database, if there are changes in the file system (such as adding, editing or deleting files), you must update the database again data by running the command sudo update db to make sure locate the latest files can be found. Meanwhile, find will perform a search directly on the filesystem, so will always give the latest results.
  3. Search options: find provides various search options, allows you to search by file name, file type, size, changed date, etc. Meanwhile, only locate supports searching by file name .

So, when you need to search for a specific file or perform searches based on various criteria using terminal command for Ubuntu or Linux/Unix, you should use the find command. When you need a quick search and searching by file name is sufficient, you can use locate.

For example, to search for files name .bashrc with locate, you can use the command:

locate .bashrc

grep;

terminal command for ubuntu and linux unix 8

The grep command in linux helps you find strings and characters in the specified file. This is considered one of the most frequently used terminal command for Ubuntu & Linux. You can see detailed usage here.

sed;

The command sed (short for Stream Editor) is one of the basic commands in Linux/Unix, used to edit and process text in files and data streams. It allows users to perform operations such as find and replace, delete, insert and modify lines of text in a file or data stream on the command line.

The terminal command in Ubuntu or Linux/Unix is "sed"(illustration)
The terminal command in Linux or Ubuntu is “sed”(illustration)

Such files and data streams can be entered using input from the keyboard or various files. The sed command is widely used in word processing and is often combined with other commands to perform more complex tasks.

Syntax to use:

sed [option] commands [file]

Example: Suppose you have a text file named “test.txt”, the content of the file is:

Hello world!
This is a test file.

You want to replace the word “world” with the word “universe”. You can use the command sed as follows:

sed 's/world/universe/' test.txt

The result you get will be:

Hello universe!
This is a test file.

This command uses the option s to replace the first string ‘world’ with the second string universe and prints the result to the screen.

reset;

The reset command is used to erase the entire contents of the terminal and reset the default settings. This command can be useful in case an error is displayed on the terminal or to clear the previous command history.

reset

echo;

Command echo is a very powerful command line utility that allows you to output a specific text to the terminal console. Type echo then some text in parentheses to find out for yourself. What’s more interesting about this command is that you can pipe the output on terminal.

echo "Creating a new file." > sample.txt
Example of terminal command for Ubuntu 22.04 with echo (illustration)
Example of terminal command for Ubuntu 22.04 with echo (illustration)

If we use > redirection operator, file is created if it doesn’t exist. If the file exists, the output from echo is appended to the top of the file, overwriting any previous content.

echo "Adding to the file." >> sample.txt

If we use >> redirection operator, file is created if it doesn’t exist. The output from echo is appended to the end of the file and does not overwrite any existing contents of the file.

You can open the sample.txt file to view the content or use the cat command.

cat sample.txt
Creating a new file.
Adding to the file.

Another example to use echothat command is that you can use it to test sending emails on Linux:

echo \
"Content: Test gmail" | mail -s \
"Subject: Test sendemail" -a \
"From: buivanloi.2010@gmail.com" -a \
"To: To <itsmeit.biz@gmail.com>" itsmeit.biz@gmail.com

chmod;

How to use chmod command in Linux or Ubuntu with examples
How to use chmod command in Linux or Ubuntu with examples (illustration)

The command chmod in the terminal of the Ubuntu or Linux operating system allows you to change the permissions of a file or directory. This is one of the most powerful command in Linux and Ubuntu that you can use to adjust or modify the permissions of files or objects on the system. However, to use this command, you may need sudo or root privileges. You can see details here.

chown;

The command chown is very similar to the chmod command. But instead of changing the permissions, it allows the user to change the ownership of the file or folder. chmod and chown both require root privileges to run.

For example to change the username and group for the sample.txt file, first run the command ls -lah to see what the file permissions are:

ls -lah
terminal command for ubuntu and linux unix 10

As you can see in the screenshot the ownership of the file is itsmeit and the group is itsmeit. Now try to assign root permissions to the file as follows:

sudo chown root:root newfile.txt

Now run the command again ls -lah and see if the permissions of the newfile.txt file have been changed.

whatis;

Commands whatis in the terminal on Linux/Unix operating systems are used to display brief descriptive information about a particular command. More specifically, the whatis command returns a brief description of a command stored in the whatis database. The purpose of the whatis command is to help users quickly learn about a command they are unfamiliar with, or simply review the description of a command they have forgotten.

Example how to use whatis command on terminal in Ubuntu:

whatis nginx

top;

The top is one of the important terminal command in Linux, allowing you to display information about the processes running on the system and using the computer resources such as CPU, RAM, swap, and more. It provides an interactive command line interface to monitor and manage processes and system resources in detail.

terminal command for ubuntu and linux unix 6

When running the terminal command for Ubuntu with the command top, it will display a list of processes running on the system in order of CPU and RAM priority. Each process is listed with detailed information such as process ID (PID), runtime, resource usage, and resource usage percentage.

You can also install htop, which is a command-line process management tool on Linux systems, similar to the top command but with a graphical interface and provides more detailed information about the processes running and system resources are used.

sudo apt install htop

Syntax to use htop on terminal:

htop
The terminal command in Ubuntu or Linux/Unix is "htop".
The terminal command in Ubuntu or Linux/Unix is “htop” (illustration)

sl;

Command sl, short for Stream Locomotive, is a simple terminal command on Linux used to display an ASCII train screen moving on the terminal. It is often confused with the ls command. Although it has no practical effect, it is a fun entertaining command for Linux/Unix users. When you run this command, the screen will show a steam locomotive running across the terminal.

Syntax to install and use the command sl:

sudo apt install sl
sl

Above ItsmeIT has compiled useful and commonly used command in Ubuntu and Linux operating systems. To better understand each statement, you can use the man command with the syntax man <command> to help you see complete information about the function and syntax of that statement.

Reference link: useful tool for Linux/macOS

– Advertising –

Share this Article
Facebook Twitter Pinterest LinkedIn Reddit Telegram
Leave a comment Leave a comment
Subscribe
Connect with
Login
Notify of
guest
Connect with
guest
0 Comments
Inline Feedbacks
View all comments
Previous Article How to use grep command in Linux or Ubuntu and examples How to use grep command in Linux or Ubuntu and examples
Next Article Most Useful Basic Command in Linux: Examples and Syntax Most Useful Basic Command in Linux | Examples and Syntax

You Might Also Like

How to install Composer on Ubuntu 20.04 | 22.04 & Linux

How to Configure Redis Cache to Speed ​​Up WordPress Site

Install Ibus-bamboo or Ibus-unikey for Accented Letters on Ubuntu 22.04

How to install MariaDB on Ubuntu 22.04, 20.04 and Debian

How to Install Android Studio on Ubuntu 22.04 or 20.04

Stay Connected

Facebook Like
Twitter Follow
Pinterest Pin
Telegram Follow

Popular Posts

Download Plugin Product Video Gallery for Woocommerce v1.5.0
Plugin Product Video Gallery for Woocommerce v1.5.0
November 17, 2023 8 Views
Download Prevent Spam Register Plugin - Block WordPress Spam Accounts
Prevent Spam Register Plugin – Block WordPress Spam Accounts
November 17, 2023 4 Views
Elementor PRO v3.17.0 Plugin (Full Templates Pack + Demo)
Download Plugin Elementor PRO 3.17.0 (+Full Templates Pack)
November 17, 2023 18 Views
Download Newspaper v12.6.1 - WordPress theme News Magazine
Download Newspaper v12.6.1 – WordPress theme News Magazine
November 17, 2023 10 Views
JNews v11.1.3 - WordPress newspaper magazine blog AMP
JNews v11.1.3 – WordPress newspaper magazine blog AMP
November 17, 2023 8 Views
Download Keyword Tool v2.3.3: SEO WordPress Keyword Research Plugin
Keyword Tool v2.3.3: SEO WordPress Keyword Research Plugin
November 17, 2023 9 Views
We provide tips and tricks on Internet technology, computers, servers as well as share experiences for developers and website designers.

DMCA.com Protection Status

Quick Link

  • Ubuntu & Linux
  • Windows

General Policy

  • About US
  • Contact US
  • Disclaimer
  • Privacy Policy
  • Terms of Service

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

itsmeit.bizitsmeit.biz
Follow US
Copyright © 2023. All Rights Reserved.
  • Windows Software
  • Ubuntu & Linux
Welcome Back!

Sign in to your account

Continue with Google
Continue with TikTok
Continue with GitHub
Register Lost your password?