The Terminal - spc-computer-society/spc-cs-db GitHub Wiki
Introduction
If you ask any of the linux users what they think are the best part of linux, most of them will probably answer you with the same answer, the terminal. Indeed, the linux terminal is one of the most efficient way to work around in your computer system. In windows, everything requires a graphical user interface(GUI) to work. Working this way might be the most straightforward to you, but in fact, it is highly inefficient when compared to the command line interface(CLI). This is simply because no graphical interface is needed to perform an action. You do not need to look through thousands of menus, flashing buttons or difficult-to-read fonts to do a simple action. Some of you would say, aren't there terminals in both Windows and MacOS? Yes, there is, but they are barely functional in comparison with the linux terminal. Remember, the linux terminal can do almost everything regarding your computer system. That is why the linux terminal is the core of a linux system.
At first glance, the CLI might seem horrendous and old-fashioned. However, when you start to work around the linux terminal, you will slowly accept it, or even love it after a period of use. Below, we will guide you to the most useful commands of the linux terminal.
List of useful commands
- cd --- change directory
- ls --- list, sometimes used with ls -al to show all hidden files in the form of a detailed list
- pwd --- present working directory, shows the path of your present directory
- whoami --- shows the current logged user
- cp --- copy
- rm --- remove
- mv --- move
- df --- shows information of your mounted partitions
- dd --- disk destroyer
- fdisk --- A disk utility
- gdisk --- Another disk utility
- parted --- Yet another disk utility
- cfdisk --- Still another disk utility
- cgdisk --- Thus another disk utility
- lsblk --- list block devices
- lsusb --- list usb devices
- lspci --- list pci devices
- sudo --- run a command of root privileges
- su --- switch user (default user is root)
- man --- opens a manual of a command
- apt --- package manager for Debian/Ubuntu based distros
- dnf/yum --- package manager for RHEL based distros
- pacman --- package manager for Arch Linux based distros
- zypper --- package manager for Slackware based distros
- portage --- package manager for gentoo based distros
- mkdir --- create a new empty directory
- rmdir --- remove an empty directory
- touch --- creates an empty file
- cat --- reads and outputs content of a file
- echo --- outputs the given string
- nano --- a cli-based user-friendly text editor
- vim/vi --- a cli-based efficient(not beginner-friendly) text editor
- grep --- searches for a pattern of string in an output, often used with other commands with a “|” sign separating.
- find --- finds a file directory
- mount --- mounts a partition
- umount --- unmounts a partition
- fsck --- checks the consistency of a file disk
- efibootmgr --- Manager for booting (e.g. boot order, boot settings)
- update-grub --- updates grub’s boot options
- grub install --- installs grub
- kill --- kills a particular process
- killall --- kills all process regarding the process name
- exit --- exits an interface (e.g. the terminal)
- passwd --- changes unix password
- inxi --- shows information of your system
- neofetch --- also shows information about your system (And a nice logo)
- uname --- obtains primary information of your system
- htop/top --- launches a live system monitor
- alias --- sets aliases for commands
- wget --- grabs and downloads a file from the given url
- curl --- another tool for retrieving files and information from the given url
- dkpg --- unpacks and installs a .deb file(Debian/Ubuntu based distros only)
- clear --- clears your terminal interface
- chmod --- grants permission of a file
- chown --- grants ownership of a file
- chroot --- Accesses a mounted linux filesystem externally (e.g. from a live system)
- tar --- uncompress a tarball file
- unzip --- uncompress a zip file
- snap --- a universal linux package manager(mainly Ubuntu)
- flatpak --- another universal linux package manager(mainly Linux Mint)
- appimage --- another another universal linux package manager
- ping --- receives ping with the given webpage, often used for testing internet connectivity
- shutdown --- shutdowns the computer
- reboot --- reboots the computer
- ip --- shows internet information
- ifconfig --- another utility for showing internet information(Older version of ip)
Detailed Explanation of some Commands
sudo
The sudo command stands for “superuser do”. Since some system files need root privileges to access, running commands related to system files (usually files outside your home directory) requires root privileges. Otherwise, an exception of “permission denied” may be raised. Some commands will always require root privilege (e.g. apt install, apt remove). Please be reminded that using sudo will require sudoer’s password. Be cautious when using sudo, as you may perform more destructive actions easily. Remember to read and understand what you are doing, and don't copy blindly.
Adding “sudo” in front of a command will give root privileges to the user executing the command. Example:
sudo apt install vim
sudo nano /etc/fstab
sudo su
sudo rm -rf /lib/TestFolder
Tip: if you forgot to add in sudo in your previous command, you can quickly add it in by using command “sudo !!” apt install vim
sudo !!
Exceptions: You cannot sudo cd into a locked directory, because it does not make sense theoretically. Example:
sudo cd /root
sudo cd /boot/efi
You will have to login to root user to access those directories.
sudo su or su
cd /root
cd /boot/efi
Another tip:
Read the help of sudo. It has some interesting features.
For example:
sudo -i starts a login session of root. This may be useful if you find yourself using sudo too often.
sudo -e [file] allows you to edit a file as root with the system's default editor. The default is vi. Use EDITOR=[editor] to set the editor used here.
cd
The cd command stands for “change directory”. It is one of the most commonly used commands.
Changing to child directory “Downloads” using relative path
cd Downloads
Changing to directory “/usr/bin/” using absolute path
cd /usr/bin
Falling back to parent directory
cd ..
Tip:
Going back to the home directory is as simple as:
cd
Note: Use tab to autocomplete if there is 1 option. Double tab to show all options when there are more than 2.
ls
The ls command stands for list. It lists all files and directories in the current path.
Normal listing
ls
Listing all files including hidden files in the form of detailed lists
ls -al
Note: The -a flag stands for all, which shows all files/directories including hidden files (files starting with “.”) The -l flag stands for list, which shows files/directories in the form of lists. They can be used dependently.
man
The man command stands for “manual”. It outputs the menu of a command if possible. It will raise an exception if there is no manual available.
Outputting the manual of command “dd”
man dd
Example output
DD(1) User Commands DD(1)
NAME
dd - convert and copy a file
SYNOPSIS
dd [OPERAND]...
dd OPTION
DESCRIPTION
Copy a file, converting and formatting according to the operands.
etc…
cp
The cp command stands for “copy”. Source and Destination paths are required.
Copying file “Downloads/test.txt” to “”Documents/TestFolder/”
cp Downloads/test.txt Documents/TestFolder/
Copying directory “CopyFolder/” to “Documents/TestFolder/”
cp -r CopyFolder Documents/TestFolder/
Copying multiple files to “Documents/TestFolder/”
cp apple.txt banana.jar pear.py Documents/TestFolder/
Copying all files in the current directory with the extension “.txt” to “Documents/TestFolder/”
cp *.txt Documents/TestFolder/
mv
The mv command stands for “move”. It moves files and directories with the given source and destination.
The usage is similar to the cp command. Please refer to the above.
rm
The rm command stands for “remove”. It removes files or directories.
Removing a file “apple.txt”
rm apple.txt
Removing a directory “TestFolder”
rm -r TestFolder
Forcefully removing a file/directory
rm -f file.txt
rm -rf folder
nano/vim
Nano and Vim are CLI-based text editors with their pros and cons. Nano is very user-friendly, commands with descriptions are stated on the bottom. Vim is not beginner-friendly on the other hand, but it is more efficient when you know the hotkeys. For beginners, nano is highly recommended while vim will most likely only going to cause you trouble.
Nano and Vim can be used to open any file as the form of text.
nano apple.txt
vim data.json
Note: when modifying root-level files, root privileges are usually required.
sudo nano /etc/sddm.conf
apt
Apt stands for “Aptitude”. It is the package manager for all Debian/Ubuntu based distros. Most of the actions need root privileges (exceptions: search, list) Note: apt-get is the older version of apt, they basically do the same thing.
Installing package “vim”
sudo apt install vim
Removing package “vim”
sudo apt remove vim
Updating local database
sudo apt update
Upgrading local packages according to the local database
sudo apt upgrade
Doing the above 2 together
sudo apt update && sudo apt upgrade
Listing all installed packages and grepping packages with keyword “vim”
apt list | grep vim
Searching package with keyword “vim” in the repository
apt search vim
Removing unnecessary packages (Orphaned packages)
sudo apt autoremove
pacman
Pacman is the package for all Arch Linux based distros. It is known for its efficiency and stability. However, it is not as user-friendly as its counterparts such as apt and dnf. Again, root privileges are usually required for most of the operations.
Installing package “vim”
sudo pacman -S vim
Removing package “vim”
sudo pacman -R vim
Removing package “vim” with unnecessary dependencies and config files
sudo pacman -Rns vim
Updating local database
sudo pacman -Sy
Upgrading local packages according to the database
sudo pacman -Su
Performing the above 2 together
sudo pacman -Syu
Same as above, but with force syncing and allowing downgrades
sudo pacman -Syyuu
Listing all installed packages and grepping packages with keyword “vim”
pacman -Qs vim
Searching package with keyword “vim” in the repository
pacman -Ss vim
Removing cache
sudo pacman -Sc
Force removing all cache
sudo pacman -Scc
su
The su command stands for “switch user”. If the argument is left blank, it will be root user by default.
Switching to user root
su
sudo su # This allows sudoers to access root account without such
account’s password.
Switching to user “charles”
su charles
sudo su charles
tar
The tar command uncompresses a tarball file (e.g. .tar.gz, .tar.xz).
Uncompressing “tarfile.tar.gz”
tar -xzvf tarfile.tar.gz
unzip
The unzip command unzips a zip file(.zip)
Unzipping “zipfile.zip”
unzip zipfile.zip
inxi
The inxi shows detailed system information including your hardware and network.
Showing cpu information
inxi -c
Showing full information with maximum level(3) of detailness, covering sensitive information and including administrative information
inxi -Fxxxza
alias
The alias command sets aliases for commands.
Setting alias “sd” for command “shutdown”.
alias sd=’shutdown’
alias newfile=’nano newfile.txt’
mount/umount
The mount and umount commands mounts and unmounts partitions.
Mounting and unmounting /dev/sdb1 on /mnt
sudo mount /dev/sdb1 /mnt
sudo umount /dev/sdb1
Addendum
Commands (Sorted in alphabetical order)
- alias --- sets aliases for commands
- appimage --- another another universal linux package manager
- apt --- package manager for Debian/Ubuntu based distros
- cat --- reads and outputs content of a file
- cd --- change directory
- cfdisk --- Still another disk utility
- cgdisk --- Thus another disk utility
- chmod --- grants permission of a file
- chown --- grants ownership of a file
- chroot --- Accesses a mounted linux filesystem externally (e.g. from a live system)
- clear --- clears your terminal interface
- cp --- copy
- curl --- another tool for retrieving files and information from the given url
- dd --- disk destroyer
- df --- shows information of your mounted partitions
- dkpg --- unpacks and installs a .deb file(Debian/Ubuntu based distros only)
- dnf/yum --- package manager for RHEL based distros
- echo --- outputs the given string
- efibootmgr --- Manager for booting (e.g. boot order, boot settings)
- exit --- exits an interface (e.g. the terminal)
- fdisk --- A disk utility
- find --- finds a file directory
- flatpak --- another universal linux package manager(mainly Linux Mint)
- fsck --- checks the consistency of a file disk
- gdisk --- Another disk utility
- grep --- searches for a pattern of string in an output, often used with other commands with a “|” sign separating.
- grub install --- installs grub
- htop/top --- launches a live system monitor
- ifconfig --- another utility for showing internet information(Older version of ip)
- inxi --- shows information of your system
- ip --- shows internet information
- kill --- kills a particular process
- killall --- kills all process regarding the process name
- ls --- list, sometimes used with ls -al to show all hidden files in the form of a detailed list
- lsblk --- list block devices
- lspci --- list pci devices
- lsusb --- list usb devices
- man --- opens a manual of a command
- mkdir --- create a new empty directory
- mount --- mounts a partition
- mv --- move
- nano --- a cli-based user-friendly text editor
- neofetch --- also shows information about your system (And a nice logo)
- pacman --- package manager for Arch Linux based distros
- parted --- Yet another disk utility
- passwd --- changes unix password
- ping --- receives ping with the given webpage, often used for testing internet connectivity
- portage --- package manager for gentoo based distros
- pwd --- present working directory, shows the path of your present directory
- reboot --- reboots the computer
- rm --- remove
- rmdir --- remove an empty directory
- shutdown --- shutdowns the computer
- snap --- a universal linux package manager(mainly Ubuntu)
- su --- switch user (default user is root)
- sudo --- run a command of root privileges
- tar --- uncompress a tarball file
- touch --- creates an empty file
- umount --- unmounts a partition
- uname --- obtains primary information of your system
- unzip --- uncompress a zip file
- update-grub --- updates grub’s boot options
- vim/vi --- a cli-based efficient(not beginner-friendly) text editor
- wget --- grabs and downloads a file from the given url
- whoami --- shows the current logged user
- zypper --- package manager for Slackware based distros