How to use the Ubuntu Linux Terminal on your Dell PC

Summary: This article is a reference article that takes you through the Terminal conventions you need to know in order to get the most out of the Linux Ubuntu Operating System on your Dell PC.

Article Content


Symptoms

The following article provides information about using the Terminal Shell in Ubuntu Linux. How to find out more about how to use the many commands available in Terminal.


Table of Contents:

  1. Using the Terminal Shell to find out what a command does and how
  2. Which Ubuntu Linux terminal commands can provide this information?
  3. A Terminal Shell Tutorial
  4. Useful Commands to know
  5. Useful rules to remember

 

Using the Terminal Shell to find out what a command does and how

 

In this article, I will explain how to use the inbuilt Terminal commands to provide information about some commands and what they do.

I will provide some examples to illustrate the process as well.

The command line is powerful. Tools exist that take a tedious job in a graphical User interface (GUI) and turn it into a task that takes a few seconds. Removing the last four lines in every row of a large file would be a lengthy process in a GUI application. However, it can become automated on the command line.

There are many commands that are associated with the Terminal Shell in Ubuntu Linux. The article below lists the majority under the groups they affect.


Back to Top


Resolution

 

Which Ubuntu Linux terminal commands can provide this information?

 

There are three main commands we will be using to provide all the information needed to use the various terminal commands.

 

The man command displays the manual for any command that is used in the Terminal.

Most shell commands will accept various options. To get some information about a command and a list of the available options, use the man - short for manual command. Give the name of the command you want to find more about as its argument. i.e. which command the man command will work on.

Example: If you enter the command man who, the following output is displayed.

 WHO(1)                     User Commands                     WHO(1)

 NAME
    who - show who is logged on

 SYNOPSIS
    who [OPTION}... [ FILE | ARG1 ARG2 ]

 DESCRIPTION
    -a, --all
       same as -b -d --login -p -r -t -T -u

    -b, --boot
       time of last system boot

    -d, --dead
       print dead processes

    -H, --heading
       print line of column headings

    -i, --idle
       add idle time as HOURS:MINUTES, . or old (deprecated, use -u)

    -l, --login
       print system login processes

    --lookup
       attempt to canonicalize hostnames via DNS

    -m, only hostname and user associated with stdin

 Manual page who(1) line 1

Many of the manuals are several screens long. Use the cursor/ARROW keys or the Page Up/Page Down keys to navigate through the text. The space bar key shows the next line of text. Pressing the q key quits the manual and returns to the shell.

We can see from the man page that we can use the -a option to display more information about the active users sessions.

      user@3[user]$ who -a
   

        Nov 14 13:47   10 id=si term=0 exit=0
      system boot Nov 14 13:47          
      run-level 5 Nov 14 13:47     Last=S    
        Nov 14 13:47   835 id=15 term=0 exit=0
LOGIN     tty1 Nov 14 13:47   958 id=1    
root   - tty2 Nov 14 19:15 00:19 959      
user   - tty3 Nov 14 19:28 00:06 960      
LOGIN     tty4 Nov 14 13:47   961 id=4    
LOGIN     tty5 Nov 14 13:47   962 id=5    
LOGIN     tty6 Nov 14 13:47   963 id=6    
user   ? :0 Nov 14 13:47 ? 965      
      pts/3 Nov 14 16:29   1746 id=/3 term=0 exit=0
 

    user@3[user]$

It also reads help files for programs, the man command can also give information about shells, functions, and libraries.

 

If you are not sure how to use a specific command, run the command with the -h or –help switches. You will see usage information and a list of options you can use with the command.

Example: If you want to know how to use the wget command, type wget –help or wget -h.

      User@Ubuntu@#$ wget --help
 GNU Wget 1.12, a non-interactive network retriever.
 Usage: wget [OPTION]... [URL]...

 Mandatory arguments to long options are mandatory for short options t
 oo.

 Startup:
  -V, --version display the version of Wget and exit.
  -h, --help print this help.
  -b, --background go to background after startup.
  -e, --execute=COMMAND execute a '.wgetrc' -style command.

 Logging and input file:

This often prints a lot of information to the terminal. It can be unwieldy to scroll through. To read the output more easily, you can pipe it through the less command. Which allows you to scroll through it with the cursor/ARROW keys on your keyboard.

Example: wget -help | less

 GNU Wget 1.12, a non-interactive network retriever.
 Usage: wget [OPTION]... [URL]...

 Mandatory arguments to long options are mandatory for short options t
 oo.

 Startup:
  -V, --version display the version of Wget and exit.
  -h, --help print this help.
  -b, --background go to background after startup.
  -e, --execute=COMMAND execute a '.wgetrc' -style command.

 Logging and input file:
  -o, --output-file=FILE log messages to FILE.
 :

Press q to close the less utility when you are done.

To find a specific option, you can pipe the output through the grep command. For example, use the following command to search for options that contain the word proxy.

wget -help | grep proxy

  User@ubuntu:~$ wget --help | grep proxy
  --no-proxy explicitly turn off proxy.
  --proxy-user=USER set USER as proxy username.
  --proxy-password=PASS set PASS as proxy password.
  User@Ubuntu:~$

 

Some commands are also documented inside the info system. The information here complements what is shown by the man command.

Example: Enter the command info ls, the following output is displayed.

   [support@support]$" info ls

You can now view a manual with important information about the ls command.

   File: coreutils.info, Node: ls invocation, Next: dir invocation, Up: Directory listing

  'ls': List directory contents
  =============================

   The 'ls' program lists information about files (of any type,
  including directories). Options and file arguments can be intermixed
  arbitrarily, as usual.

    For non-option command-line arguments that are directories, by
  default 'ls' lists the contents of directories, not recursively, and
  omitting files with name beginning with '.'. For other non-option
  arguments, be default 'ls' lists just the file name. If no non-option
  argument is specified, 'ls' operates on the current directory, acting
  as if it had been invoked with a single argument of '.'.

   By default, the output is sorted alphabetically, according to the
  locale settings in effect. (1) If standard output is a terminal, the
  output is in columns (sorted vertically) and control characters are
  output as question marks; otherwise, the output is listed one per line
  and control characters are output as-is.
  --zz-Info: (coreutils.info.gz)ls invocation, 48 lines --Top------------------
  Welcome to info version 4.3 Type C-h for help, m for menu item.

You can scroll down the pages by pressing the space bar key or by using the cursor/ARROW keys.

  1. For help, press H.

  2. To quit, press Q.

  3. To search for a menu item, press M.


Back to Top


 

A Terminal Shell Tutorial

 

You can do almost anything in a terminal, which you would also do from a GUI.

As said before, many commands were designed first to work in the terminal and then a GUI was put on top. That is why some GUIs may feel clunky - at first they were an afterthought as most Linux Server builds do not bother with them.

The default location for your terminal to open from the menu is in your home folder. Known as ~

You can find your current directory by the . operator. Most commands when they act on the current folder selection operate on commands, locations, and files are case-sensitive. /home is not the same as /HOME or /Home.

Use the TAB key to complete file names. If you have a long driver title. driver-128947232jaseu.sh for example, simply type dri and it will fill in the rest. Provided you do not have 2 names starting with dri and if you do, add another character to make it driv and try again. Make sure the auto complete matches what you want to see.

Almost any command can be read about in full using the man page or by typing -h or --help after writing the initial command. This syntax is either man command_name, command_name -h or command_name --help.

To get even more information, you can use info. A command can be searched for by using info command_name. For most of these commands which are part of the coreutils package. You can find info as well using info coreutils command_name invocation where command_name is replaced by the command searched for.

Almost any command can show exactly what is happening, step by step. This is usually the -v or --verbose.

You can specify multiple command flags to a command at a time to get more information. See the ls -al example below.

Command names are not always obvious - due to space limitations in the old days of Unix they were shortened and these conventions stuck.


Back to Top


 

Useful Commands to know

 

 

  1. cd - Moves you back to your home, same as cd ~

  2. cd.. - Takes you back one directory. Starting in /home/user/Desktop, cd.. will put you into /home/user. This can be expanded to cd ../../ which will move you back 2 directories to /home.

  3. cd foldername/ - Move you forward to the given folder in your current folder.

SLN265948_en_US__1icon Note: The missing prefix /, it is an important omission. If I am in /home/user and I want to get to Desktop. I must type cd Desktop/ without the / before Desktop. Typing / before it places us in the root of file system which would not work.
  1. cd /some/other/path - Takes you to the specified folder path. As long as you got the path right. Do not forget you can use the TAB key to autocomplete.

 

 

  1. ls - Lists all your files in the current folder.

  2. ls -l - Provides a longer list including owners, permissions, size, and date modified.

  3. ls -a - Displays the hidden files and folders and the normal list.

  4. ls -al - Combines two options to display both the hidden files and folders and do it in the long format.

  5. ls -h - Shows file sizes in human readable format KB, MB, GB, filesizes instead of bytes. Most often used with the -l flag.

  6. You can view files in directories you are not even in. If I am in /home/user/Desktop and I want to view a file in /home/user, I can do ls ../ which will list the files one directory back.

 

  1. cp file /path/to/folder - Copies the specified file to the given path.

  2. cp -r folder /path/to/folder - Copies repeatedly the contents of the folder to another folder.

  3. cp *.extension /path/to/folder - Copies the files matching the given extension to the new folder. To copy all .doc files, it becomes cp *.doc /path/to/folder and the folder must exist.

  4. cp name* /path/to/folder - Copies all the files starting with name to the given folder. To copy all files starting with example, it becomes cp example* /path/to/folder and the folder must already exist.

 

  1. The syntax of mv is similar to the example above with cp exempt for example #2. mv does not take the -r flag since moving a folder also moves its contents. The syntax is not exact in all instances, but works with the above examples. Consult your manpages for more details.

 

SLN265948_en_US__1icon Note: It will not prompt you if something critical is being deleted. If you have to use this, then there has either been a mistake made leading up to this command. Or there is something else wrong with the machine. This command should only be used as a last resort and is not recommended.
  1. Removing files via rm is permanent. It does not use the Trash bin. Use this with caution and make sure you are deleting exactly what you want, before you hit the Enter key. If you overcomplicate your delete commands, it probably will not end well.

  2. rm file - Remove that specific file from the system.

  3. rm -r folder - Remove that specific folder from the system.

  4. rm -rf folder - Removes that specific folder forcefully from the system. This command can mess up your configuration if it is used incorrectly.

 
  1. You can edit files using nano in a terminal to do quick and rough files all the way up to full configurations. It can be useful, but it handles plain text files and programming files, so things like Microsoft Word documents will not open properly.

  2. If a file is owned by the root, a regular user cannot edit it. nano must be prefixed with sudo; in order to save changes. It will open in read-only mode otherwise.

  3. nano newfile.whatever of the specified name and opens it for editing.

  4. nano existing_file - opens the existing file for editing.

  5. From inside nano

  6. Save the file by pressing the CTRL+O keys together and either change the name or press the Enter key to keep the same name. This will save the file.

  7. Exit nano by using the CTRL+X keys together. If you have unsaved changes, then it will ask if you want to save them.

 

  1. mkdir folder_name - Creates the folder with the specified name

  2. mkdir -p /path/to/folder/name - Creates each folder as necessary. To create folder /home/user/1stfolder/2ndfolder, and only /home/user exists, using mkdir -p will make both directories 1stfolder and 2ndfolder.

 

  1. ps aux - Lists all the processes in detail running on the system. This includes user, Process ID PID and name of process. Using this you can view the process list and if necessary you can kill unnecessary or stalled processes.

 

  1. kill PID - PID is a number referencing the offending process. You should obtain the PID from a command like ps aux. If a process refuses to die, you can also specify kill -9 PID which should terminate the process by any means.

SLN265948_en_US__1icon Note: Watch out because this will close it even if it does it in an unclean fashion or if it will mess up the system.
  1. killall program - Killall kills by name all instances of the listed program. If there are for example 3 Firefox Internet browser sessions open, killall Firefox will do just that, kill all Firefox sessions. kill would simply take the specified PID of the offending Firefox process that you wish to kill and kill that one only.

  2. xkill is a GUI way to click and kill windows. Typing in xkill should bring up a skull-and-crossbones icon and the next window clicked on will be killed.

 

  1. Pipes are represented by the straight bar otherwise known as the | key.

  2. It is a rarely used key in Windows, but it is often found on the backslash key.

  3. These are used to link commands together. Pipes take the output of one command and route it to be used as input for a second command when they are chained together.

  4. Consult online resources for more information about pipes and their use as there are volumes that are written on them.

 

  1. > is used to overwrite the existing files contents by replacing them with the output from the new command.

  2. >> is used to append information to the existing files. This is useful for logging actions.

  3. Example: ps aux > processes.log sends the output of ps aux to the file processes.log for viewing the command output in a text editor and overwrites the current contents of the file.

 

  1. tee is used along with a | in order to take the command output and send it somewhere else. This is useful if there are errors which you miss. This way whatever goes on the screen is also captured to a file.

  2. Example: dmesg| tee boot.txt would run the command dmesg which shows the initial boot info. The | sends the output of dmesg to tee, which then does its job by sending it to the terminal and to the log file boot.txt.

 

  1. Do you need to execute a file in the current directory after it is marked executable? The ./ operator can execute the file as a normal user provided you do not need root rights. ./ literally means in the current directory so it does not work on files outside of the present directory.

  2. If you need to execute a file not in the current directory, then you must pass the path to the proper executing program. If it is a python program, it will be python /path/to/file and if it is a shell file, its sh /path/to/file as an example. There are other programs, but these will be the most common.

  3. If you need to execute a file with root rights because you received operation not permitted?. You need to prefix the command with sudo. As with the above example, sudo python /path/to/file will execute the script with root rights.

  4. If you need to execute a GUI program from the terminal, then simply type the program name - case sensitive! and it will launch. This will render the current terminal unusable. Closing the terminal while the program is open will also kill the program. A better way is to background the program, using program_name and then typing the word exit at the terminal to close it and keep the process running.

  5. If you need to run a GUI program with root rights from the terminal, then prefix it with gksudo or gksu and not sudo. Using sudo to launch GUI applications is a bad habit and should be avoided.

  6. Do not use sudo just because something brings up Operation not permitted. Keep in mind that you can destroy systems by running commands in the wrong place with root rights. Make sure your files come from reputable sources.


Back to Top


 

Useful rules to remember

 

Lost yourself in a directory? Type pwd to print working directory.

Want to calculate your disk space? df -h can give you a quick figure.

Want to calculate the size of a folder or file? du -cksh target_name will do exactly that. Want to calculate the size of the current folder? du -cksh.

Want to mark a file executable? chmod +x filename will do that.

Need to mount an iso? Linux has this functionality built in. Create a directory somewhere, say /home/user/isomount and issue the command mount -o loop /path/to/myisofile.iso /home/user/isomount and the contents will be mounted inside that folder.

Having run a command, you need to rerun it, but you cannot remember exactly how it went? Type history into the terminal and it will print your command history. Want to clear your history? history -c will wipe the information.


Back to Top


 

Additional Information:

 

SLN265948_en_US__1icon Note:
Software support is by Canonical through the following methods:
Technical Support is provided by Dell:


Back to Top


Article Properties


Affected Product

Desktops & All-in-Ones, Laptops, Inspiron, Latitude, Vostro, XPS, Fixed Workstations

Last Published Date

21 Feb 2021

Version

4

Article Type

Solution

Rate This Article


Accurate
Useful
Easy to Understand
Was this article helpful?

0/3000 characters