Basic Linux Command

mqzerr
7 min readFeb 5, 2021

--

If you are Ubuntu newbie, then this post about basic Ubuntu commands is going to help you to get familiar with the Ubuntu. As we all know, Ubuntu is one of the most customization Linux distribution available today. In fact, when we heard Linux, the first thing came to our would-be Ubuntu.

Here we are going to list some important basic Ubuntu commands every beginner must know.I think Ubuntu’s incredible flexibility is due mainly to its powerful shell, which is at the core of all Linux variants. Through the user-friendly “Terminal” interface, you can easily interact with this shell using a wide variety of commands.

Basic Ubuntu Commands

Below is the basic important and necessary command in ubuntu

  1. Sudo

sudo (Super User DO) Linux command allows you to run programs or other commands with administrative privileges, just like “Run as administrator” in Windows. This is useful when, for example, you need to modify files in a directory that your user wouldn’t normally have access to.

Example :

$ sudo rm -rf laravel-project
$ sudo su kimly
$ sudo apt-get update

2. Apt-Get

apt-get is the one of the most important Ubuntu commands every beginner must know. It is used to install, update, upgrade and remove any package. apt-get basically works on a database of available packages. Here is the list of different apt-get commands.

  • sudo apt-get update
    apt-get update with super user privileges is the first command you need to run in any Linux system after a fresh install. This command updates the database and let your system know if there are newer packages available or not.
  • sudo apt-get upgrade

After updating the package database, next step is to to upgrade the installed packages. For upgrading all the packages with available updates you can use this command

sudo apt-get upgrade <package-name>

  • sudo apt-get install

If you know the name of the package, then you can easily install a program using this command.

sudo apt-get install <package-name>

  • sudo apt-get remove

When it comes to removing the installed program apt-get remove command suits your need. You only have to know the exact package name of the software you want to uninstall

If you don’t know the package name, use below ubuntu basic command to list all the packages installed on your system and then copy the package name from the list.

dpkg — list

Now run the apt-get remove command as sudo in order to remove the software

sudo apt-get remove <package-name>

  • sudo apt-get purge

apt-get purge command is used when you want to remove a software completely from your system with its configuration or data files so that no longer personalized settings will be available during re-installation.

Run the apt-get purge command as sudo in order to remove the software completely

sudo apt-get purge <package-name>

  • sudo apt-get autoremove

apt-get autoremove command is used to remove any unnecessary packages. Unnecessary means, whenever you install an application, the system will also install the software that this application depends on. It is common in Ubuntu that applications share the same libraries. When you remove the application the dependency will stay on your system.

So run apt-get autoremove as sudo after uninstalling a package to remove unwanted software dependencies. So apt-get autoremove will remove those dependencies that were installed with applications and that are no longer used by anything else on the system.

3. List Directory (ls) and (ll)

command lists all files and folders in your current working directory. You can also specify paths to other directories if you want to view their contents.

ll (ls -la): will list directory in detail that ls. It is the equal ls -la

4. Change Directory (cd)

cd (change director”) Linux command also known as chdir used to change the current working directory. It’s one of the most used basic Ubuntu commands. Using this command is easy, just type cd followed by the the folder name. You can use full paths to folders or simply the name of a folder within the directory you are currently working.

Some common uses are:
- cd / — Takes you to the root directory.
- cd .. — Takes you up one directory level.
- cd — — Takes you to the previous directory.

Example :

$ cd /home
$ cd ..
$ cd -
$ cd ~/Document
$ cd /var/www/html

5. Print Working Directory (pwd)

Ubuntu command displays the full pathname of the current working directory

Example:

➜ laravelapp git:(dev) pwd
/home/kimly/Documents/flexible/laravelapp
➜ laravelapp git:(dev)

6. Copy (cp)

cp (copy) Linux command allows you to copy a file. You should specify both the file you want to be copied and the location you want it copied to — for example, cp xyz /home/myfiles would copy the file “xyz” to the directory “/home/myfiles”.

Syntax: cp [what-to-copy] [path-copy-to]

$ cp my-document.docx /Document/mydoc/

7. Move (mv)

This command is used to move or rename file or directory to another directory.

mv (move) command allows you to move files. You can also rename files by moving them to the directory they are currently in, but under a new name. The usage is the same as cp — for example mv xyz /home/myfiles would move the file “xyz” to the directory “/home/myfiles”.

$ mv test.txt test-rename.txt (rename)
$ mv test.txt /Document/kimly/

8. Remove (rm)

rm (remove) command removes the specified file

  • rmdir (“remove directory”) — Removes an empty directory
  • rm -r (“remove recursively”) — Removes a directory along with its content.

9. Make Directory (mkdir)

mkdir (make directory) command allows you to create a new directory. You can specify where you want the directory created — if you do not do so, it will be created in your current working directory.

Example:

➜ ~ cd Desktop
➜ Desktop mkdir test-mk-dir
➜ Desktop ll
total 20K
drwxrwxr-x 3 kimly kimly 4.0K ២ 4 09:48 ansible
drwxrwxr-x 2 kimly kimly 4.0K ១ 20 18:25 backup
drwxrwxr-x 6 kimly kimly 4.0K ១ 30 12:19 photoshopCClinux
drwxrwxr-x 3 kimly kimly 4.0K ២ 3 19:38 test
drwxrwxr-x 2 kimly kimly 4.0K ២ 4 14:36 test-mk-dir

10. History

Show all history command that you have type before

Example:

➜ Desktop history
1. cd ..
2. cd git-server
3. vagrant up
4. vagrant ssh
5. cd
6. cat .ssh/id_rsa.pub
7. ssh root@192.168.2.1

11. Display File System (df)

command displays information about the disk space usage of all mounted file system.

➜ Desktop df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 3987116 0 3987116 0% /dev
tmpfs 803260 2136 801124 1% /run
/dev/nvme0n1p3 98430596 17387828 76042784 19% /
tmpfs 4016284 181828 3834456 5% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 4016284 0 4016284 0% /sys/fs/cgroup
/dev/loop2 56704 56704 0 100% /snap/core18/1932
/dev/loop3 63104 63104 0 100% /snap/core20/875
/dev/loop4 66432 66432 0 100% /snap/gtk-common-themes/1514

12. Display Usage (du)
command displays the size of a directory and all of its sub-directories.

13. Free
Displays the amount of free space available on the system

Example :

➜ flexible free
total used free shared buff/cache available
Mem: 8032568 7182648 135372 229464 714548 339372
Swap: 8000508 3916452 4084056

14. Uname -A

Provides a wide range of basic information about the system

➜ flexible uname -a
Linux DELL-E7470 5.8.0–41-generic #46~20.04.1-Ubuntu SMP Mon Jan 18 17:52:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

15. Top

Displays the processes using the most system resources at any given time. “q” can be used to exit.

16. Man

command displays a “manual page”. Manual pages are usually very detailed, and it’s recommended that you read the man pages for any command you are unfamiliar with.

Some uses are :

  • man man — Provides information about the manual itself.
  • man intro — Displays a brief introduction to Linux commands.

17. Info

Similar to man, but often provides more detailed or precise information.

18. Help (<Command Name> -H Or <Command Name> –Help)

This command is a third alternative to get help. While not as detailed as the info or man pages, this will provide a quick overview of the command and its uses.

For example: man -h or man -help

➜ flexible man -help
Usage: man [OPTION…] [SECTION] PAGE…

-C, — config-file=FILE use this user configuration file
-d, — debug emit debugging messages
-D, — default reset all options to their default values
— warnings[=WARNINGS] enable warnings from groff

Main modes of operation:
-f, — whatis equivalent to whatis
-k, — apropos equivalent to apropos
-K, — global-apropos search for text in all pages
-l, — local-file interpret PAGE argument(s) as local filename(s)
-w, — where, — path, — location
print physical location of man page(s)

19. Passwd

passwd Ubuntu basic command is used to change user password using Terminal. What you have to do is run the below command, where is the username whose password has to change:

passwd <user>

20. Whatis

whatis command shows a brief description of what is the functionality of specific built-in Linux command.

whatis <command>

Some examples are:

  • whatis cd
  • whatis man
  • whatis help

21. Cat (cat)

Used to print all text in one file out

cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDC2G2UdJ0PweAWQ6xz+3bK2KznheqMnrzxI

22. Nano (nano)

Used to edit file or create new file while it is not yet has that file in the directory

$ nano test.txt

23. Head (head)

The command “head” prints the top N rows of data of the given input or file. By default, it prints the first 10 lines of the specified files.
Syntax:

head -n File_name

24. Tail (tail)

The command “tail” prints the last N rows of data of the given input or file. By default, it prints the last 10 lines of the specified files.
Syntax:

tail -n File_name

25. Echo (echo)

The command “echo” used to display any expression that is passed as an argument.
Syntax:

echo expression_to_be_displayed

26. Grep (grep)

The command “grep” is used to search for a text in the specified file/folder.
Syntax:

Example

grep “Are” B

Thank you, have a nice day !!! :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

mqzerr
mqzerr

Written by mqzerr

DevOps engineer at ABA Bank Cambodia — Be your own unique :)

No responses yet

Write a response