Must know Linux Terminal commands

Murali mahadeva B S
4 min readSep 12, 2020

Discussion of most used Linux Terminal commands in a simple and easy way

Linux is amazingly powerful. To use the complete extent of Linux, knowledge of terminal is essential. There are tons of Terminal commands but we will go through the most essential ones now. If you know these commands, you can comfortably live with Linux and these will be the building blocks for your entry into Linux world.

If you don’t have a Linux or mac system running and you want to practice the commands you have 2 ways. On windows you can install Gitbash or you can even practice it online.

1. Creating directories and files

1. mkdir dir1
2. mkdir dir1/dir2
3. mkdir -p dir1/dir2
4. mkdir dir1 dir2 dir3
  1. Creates a directory.
  2. Creates directory within existing directory.
  3. Creates directory and sub-directories.
  4. Creates dir1, dir2, dir3 directories in the current directory.

You can create as many sub directories as possible using -p flag.

touch myfile.txt

Touch command creates files in the current directory. By specifying file extension you can create different file types.

2. Listing files and directories

This command lists all the contents of the current directory.

1. ls
2. ls -l
3. ls myfile.txt -l
4. ls -a
5. ls dir1/dir2
  1. Lists all the files and directories in the current directory.
  2. Lists all the contents with file properties except hidden files.
  3. Gives just the properties of the file myfile.txt.
  4. Lists all content including hidden files with file properties (such as read and write permissions, ownership of the file and file size).
  5. Lists all the contents of the directory dir2

3. Navigation

1. cd dir1/dir2
2. cd ../../
3. cd ~
4. cd /
  1. Moves into sub-directory dir2 from current directory.
  2. Moves back into the directory chain 2 steps. Use just “..” to get back one step back.
  3. Moves to home directory from current directory.
  4. Moves to root directory from current directory.

Note: After typing few letters of the desired directory name press Tab to auto-completion. Tab auto completion works with all terminal commands.

3. Moving and renaming files and directories

1. mv dir1 dir2
2. mv myfile.txt yourfile.txt
3. mv dir1 dir2/dir3/
4. mv dir1 ../
5. mv file1.txt file2.txt dir1/
  1. Moves dir1 as dir2 into the same directory. That is dir1 is renamed as dir2.
  2. Renames myfile.txt into yourfile.txt
  3. Moves dir1 into dir3
  4. Moves dir1 one step back in the directory chain.
  5. Moves file1.txt and file2.txt into dir1

4. Displaying file content

1. cat myfile.txt
2. cat dir1/myfile.txt
  1. Displays the contents of myfile.txt.
  2. Displays the contents of myfile.txt which is within dir1 directory from the current directory.

5. Copying files and directories

1. cp file1 file2
2. cp file1 dir1/dir2/
3. cp file1 dir1/dir2/file3
4. cp dir1 dir2 -r
5. cp dir1 dir2/dir3/ -r
6. cp file1 file2 /dir1
7. cp dir1 dir2 dir3/ -r
  1. Copies file1 with the name file2 in the current directory
  2. Copies file1 into dir2 with the same name
  3. Copies file1 into dir2 with the name file3
  4. Copies dir1 as dir2 in the current directory
  5. Copies dir1 into dir3 with the same directory name
  6. Copies file1 and file2 into dir1
  7. Copies dir1 and dir2 into dir3

Note: To copy directories you have to use -r flag.

6. Installing, updating and removing packages

1. sudo apt-get install vlc
2. sudo apt-get upgrade
3. sudo apt-get remove vlc
4. sudo apt-get --only-upgrade install vlc
5. sudo apt-get list --upgradable

apt-get is command line package manager tool for installing, updating and uninstalling packages.

  1. Installs the vlc media player. It will update the package if it is already installed.
  2. Updates all the packages installed
  3. Removes the vlc media player
  4. Updates a particular installed package, here updates vlc media player.
  5. Lists all the packages that can be updated

Note: sudo command gives super user permissions. To execute system modifiable commands super user permission is required.

7. Handling packages on terminal

1. google-chrome --version
2. google-chrome --help
3. google-chrome
4. google-chrome &
5. google-chrome .
  1. Gives the version of the package, here, Google chrome.
  2. Gives all the helper commands related to the package.
  3. Runs the package with a session in the terminal. i.e application will be terminated if you close the terminal.
  4. Runs the package and application doesn’t close even if the terminal is terminal is terminated.
  5. Opens all the files and directories in the browser. You can even open media files.

8. File, Directory and Partition sizes

1. df
2. df -h
3. du file.txt -h
4. du -h dir1/
5. du -sh dir1/
  1. Gives free and occupied space of all the partitions in kilo bytes.
  2. Gives free and occupied space of all the partitions in Mega bytes.
  3. Gives files size of file.txt
  4. Gives the size of the directory dir1. It will list all its contents and give sizes individually(Not human readable).
  5. Gives the total size of the directory without listing all its contents.

Few side notes

  1. Ctrl+Alt+T is the shortcut for opening terminal.
  2. Ctrl+D closes the terminal.
  3. Right click on the terminal, go to preferences to make customisation.
  4. Ctrl + C terminates any ongoing terminal process.
  5. To copy and paste from and to terminal, use Ctrl + C for copying from terminal and use Ctrl + V for pasting into the terminal.
  6. Up arrow and down arrow brings the previously used command. You don’t have to type every time.
  7. Type starting letters of a file or a directory and hit Tab to auto complete or give suggestions.

Linux is a huge thing. Keep learning and go ask the community if you don’t get thing.

Stay Curious… Stay Creative…

--

--