Linux Command Line
The Linux command line is a text interface to your computer, it is a computer program that interprets commands. Allowing users to execute commands by manually typing at the terminal or has the ability to automatically execute commands which were programmed in ‘Shell Scripts’. The shell is a program that takes commands from the keyboard and presents them to the operating system to perform. On most Linux systems a program called ‘bash’ (Bourne Again Shell) acts as the shell program. Besides bash, other shell programs include ksh, tcsh, and zsh.
A terminal is a program called a ‘terminal emulator’. This program opens a window and lets you interact with the shell. There are several different terminal emulators, most Linux distributions supply a few, popular terminals are:
-
Gnome-terminal - is a free open-source terminal emulator for the GNOME desktop environment, terminal emulators allow users to access a UNIX shell while remaining on their graphical desktop. Like most of the terminal emulators in this group, it supports coloured text, a variety of themes, transparency, mouse interaction, multiple tabs, and the automatic rewrapping of text upon resizing. As well as supporting multiple profiles.
-
Konsole or Console - is a free open-source terminal emulator that is part of KDE and ships with the KDE desktop environment. Konsole is the default terminal emulator shipped with KDE. Being a KDE component, it provides the embedded terminal for many other KDE applications, including Konqueror, KDevelop, and Kate. Its features are like the default GNOME terminal but have enhanced bookmarking functions for directories and SSH. It also offers split terminals.
-
xterm - In computing, xterm is the standard terminal emulator for the X Window System. Users may have many different requests of xterm running at once on the same display, each of which provides independent input/output for the process running in it (normally the process is a Unix shell).
-
rxvt - is an acronym for ouR eXtended Virtual Terminal, it is a terminal emulator for the X Window System, and in the form of a Cygwin port, for Windows.
-
Guake – is one of a few terminal emulators with a ‘drop-down’ style interface, emerging from the top of your screen with the press of a hotkey.
-
Tilde – is another Quake-style drop-down terminal emulator, designed for Gtk. Its name is taken from the tilde key, the default key for invoking the Quake terminal. Tilda's default interface is extremely minimal, with no window title or border, but this can be changed in the preferences. And has several options for everything from setting key bindings, setting default size and colour, and scrolling preferences.
-
Terminator - is a terminal emulator designed to make positioning terminals within a single-window easier, it features including several key-bindings, saving of layouts, and the ability to type to multiple terminals at the same time. Mirroring much of the behaviour of the GNOME terminal.
-
Yakuake - another drop-drown terminal emulator, is part of the KDE family. If you like Konsole but prefer the Quake-style approach, this is terminal may be an option.
To start a terminal search through the list of programs to see if anything looks like a terminal emulator:
-
With KDE - the terminal program is called ‘konsole’
-
With Gnome - it is called ‘gnome-terminal
Opening a Linux terminal
To open the terminal, press:
Ubuntu and Mint - Ctrl+Alt+T
gnome-terminal - press Alt+F2, type in gnome-terminal, and press enter
Raspberry Pi - type in lxterminal
Linux Commands
Basic Commands:
pwd (password) - When opening a terminal, you are in the home directory of your user. To know which directory you are in, you can use the ‘pwd’.command. It provides the absolute path, which means, the path that starts from the root. The root is the base of the Linux file system. It is denoted by a forward slash ( / ). The user directory is usually something like ‘/home/username’.
ls (list) - use the ‘ls’ command to know what files are in the directory you are in, but to view hidden files use the command ‘ls -a’.
cd - Use the ‘cd’ command to go to a directory. So, if you are in the home folder, and you want to go to the Documents folder, then you can type in ‘cd Documents’, keep in mind, this command is case sensitive, so if you type documents, it will not work, you must type in the exact name of the folder. If you just type ‘cd’ and press enter, it takes you to the home directory. To go back from a folder to the folder before that, you can type ‘cd ..’. The two dots represent back.
mkdir & rmdir - use the mkdir command when you need to create a folder or a directory. For example, if you want to make a directory called ‘Music’, then you can type ‘mkdir Music’. Remember, as told before, if you want to create a directory named ‘Music Albums’, then you can type ‘mkdir Music\ Albums’. Use rmdir to delete a directory. But rmdir can only be used to delete an empty directory. To delete a directory containing files, use rm.
touch - the touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file. Like, ‘touch new.txt’.
rm (remove) - use the rm command to delete files and directories, typing ‘rm -r’ will delete just the directory. It deletes both the folder and the files it contains when using only the rm command.
man & --help - the man command allows users to find out more about a certain command and how to use the man command. It displays the manual pages of the command. For example, ‘man cd’ shows the manual pages of the cd command. Typing in the command name and the argument helps it show which ways the command can be used, such as ‘cd –help’.
cp (copy) - the cp command to copies files through the command line. It has two arguments:
-
Location of the file to be copied
-
Where to copy
mv (move) - the mv command moves files via the command line. It can also be used to mv command and rename a file. Such as, if we want to rename the file ‘tinder’ to ‘fire’, we can use ‘mv tinder fire’. It takes the two arguments, just like the cp command.
locate - The locate command locates a file in a Linux system, like the search command in Windows. This command is useful when you do not know where a file is saved or the actual name of the file. Using the -i argument with the command helps to ignore the case (it is not case sensitive). So, if you want a file that has the word ‘wolf’, it gives the list of all the files in your Linux system containing the word when you type in ‘locate -i wolf’. If you remember two words, you can separate them using an asterisk (*). Like, to locate a file containing the words ‘wolf" and ‘this’, you can use the command ‘locate -i *wolf*this’.
Intermediate Commands
echo - the echo command allows us to move some data, typically text into a file. For example, if you want to create a new text file or add to an already made text file, you just need to type in, ‘echo beware, the wolf is at the door >> new.txt’. You do not need to separate the spaces by using the backward slash here because we put in two triangular brackets when we finish what we need to write.
sudo - is a widely used command in the Linux command line, sudo means for ‘SuperUser Do’. So, if you want any command to be done with administrative or root privileges, you can use the sudo command. For example, if you want to edit a file like viz. alsa-base.conf, which needs root permissions, you can use the command ‘sudo nano alsa-base.conf’. You can enter the root command line using the command ‘sudo bash’, then type in your user password. You can also use the command ‘su’ to do this, but you need to set a root password before that. For that, you can use the command ‘sudo passwd’ (not misspelled, it is abbreviated to passwd). Then type in the new root password.
cat - the cat command is used to display the contents of a file. It is usually used to easily view programs.
nano, vi, jed - nano, and vi are installed text editors in the Linux command line. The nano command text editor denotes keywords with colour and can recognise most languages, vi is simpler than nano. You can also create a new file or modify a file using this editor. Like, to make a new file named ‘cub.txt’, you can create it by using the command ‘nano cub.txt’. You can save your files after editing by using the sequence Ctrl+X, then Y (or N for no).
tar - use tar to work with tarballs (files compressed in a tarball archive) in the Linux command line. It can compress or un-compress different types of tar archives like .tar, .tar.gz, or .tar.bz2. It works based on the arguments given to it, like, ‘tar -cvf’ for creating a .tar archive, -xvf to untar a tar archive, -tvf to list the contents of the archive.
df - use the df command to see the available disk space in each of the partitions in your system. Type ‘df’ in the command line to see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command ‘df -m’.
du (disk usage) - the du lets you know the disk usage of a file in your system. If you wish to know the disk usage for a particular folder or file in Linux, you can type in the command ‘df’ and the name of the folder or file. So, if you want to know the disk space used by the documents folder in Linux, you can use the command ‘du Documents’. You can also use the command ‘ls -lah’ to view the file sizes of all the files in a folder.
zip, unzip - is used to compress files into a zip archive, and unzip to extract files from a zip archive.
uname - Use uname to show the information about the system your Linux distro is running. Using the command ‘uname -a’ prints most of the information about the system. This prints the kernel release date, version, or processor type.
apt-get - using apt allows users to work with packages in the Linux command line. Users use apt-get to install packages. This requires root privileges, so the sudo command will also be required. Such as, if you want to install the text editor vim, type in the command ‘sudo apt-get install vim’. Similarly, any package can be installed this way. However, it is prudent to update your repository each time you want to install new packages. This can be done by typing ‘sudo apt-get update’. Upgrading the system you type ‘sudo apt-get upgrade’, and for distro upgrades, type ‘sudo apt-get ‘dist-upgrade’. The command ‘apt-cache search’ is used to search for a package. If you want to search for one, you can type in ‘apt-cache search vim’, but this does not require root command.
chmod - use chmod to make a file executable and to change the permissions granted to it in Linux. If you have a python code-named dog.py on your computer. You will need to run ‘python dog.py’ every time you need to run it. Instead of that, when you make it executable, you only just need to run ‘dog.py’ in the terminal to run the file. To make a file executable, you can use the command ‘chmod +x dog.py’. You can use ‘chmod 755 dog.py’ to give it root permissions or ‘sudo chmod +x numbers.py’ for root executable.
ping - is used to check your connection to a server, it is a computer network administration software utility that tests the reachability of a host on an Internet Protocol (IP) network. When ‘ping google.com’ is typed it checks if it can connect to that server and come back, and also measures the round-trip time then gives displays the details about it. Most users use this command to check their internet connection. If it pings the server the internet connection is active.
hostname - hostname provides your name in your host or network. It displays your hostname and IP address. Typing ‘hostname’ gives the output. While typing in ‘hostname -I’ gives you your IP address in your network.