Unify Blog

Basic Ubuntu 20 Linux Commands & Tips


If you are new to Ubuntu or Linux it can be quite daunting when you need to dive into the terminal or ssh. Below are some common Ubuntu/Linux commands along with explanations of their use to make your journey and experience easier as you dive into Linux.

The basics of Ubuntu commands explained

sudo which stands for Superuser DO is a linux command that runs a command with admin privileges, much like “run as administrator” on windows.

apt-get is a commonly used command for all users. APT, standing for ‘advance packaging tool’ and get implies ‘get package’. Packages being the term used for install files.

Ubuntu commands for beginners

sudo apt-get update should always be ran after a fresh install, this command checks through the database to see if there are any update available. Note, this doesn’t install them, only checks.

sudo apt-get update

sudo apt-get upgrade (once you have ran sudo apt-get update) will upgrade all the installed packages. You can also choose to upgrade only one package.

sudo apt-get upgrade
sudo apt-get upgrade <packagename>

sudo -apt-get install is used to install new packages (software) on linux.

sudo apt-get install <packagename>

dpkg –list will list all packages currently installed on the system, you can use this to find the exact name of the package should you want to upgrade or install it.

dpkg --list

Now you know the exact name of the package, you can uninstall it on linux using the sudo apt-get remove <packagename> command. Keep in mind this removes the package, but not the config or data files, this is helpful should you need to reinstalled the package.

sudo apt-get remove <packagename>

To completely removed the package, including its config and data files, you need to use the sudo apt-get purge command. Let the purge begin.

sudo apt-get purge <packagename>

Cleanup, its not only important at home, but on Linux. When you install packages/software on Linux you might notice it also installed ‘dependencies’ so the package can run correctly. Running apt-get autoremove will remove any dependencies that are not being used and clean up your system. You should run this after removing any packages.

sudo apt-get autoremove

ls command short for list, will list all the contents of a directory. ls on its own with show the current directory, ls /path/to/directory will show other directory contents.

ls
ls </path/to/directory/>

cd short for change directory, will change the current directory to navigate your way around the file system. You can just to the next directory, or type the full path to jump multiple directorys. It is also extremely helpful to know that you can pres tab once to finish the typing automatically, or tap tab twice to view the contents so you can view what it contains.

cd </path>
cd </path/to/deeper/directory/>

Navigating to folders is common, but so is navigating out of them. You can jump back one directory using the cd .. command, or just back to the root directory using cd / command

cd ..
cd /

The cp linux command is used for copying files and directories. It can be used for both folders and directories, by specifying the source, then new location.

cp </path/filename> </newpath/newfilename>
cp </path> </newpath>

mv command is very common to cp (copy), but instead this command is used to move files or folders in Linux instead of copying them. It can also be used to move both folders and directories, by specifying the source, then new location.

mv </path/filename> </newpath/newfilename>
mv </path> </newpath>

rm is short for remove, this command is used to delete files and directories. Note the directory must be empty, if not you need to add a option -rf (r meaning recursive all folders and files contained, f meaning force). Sometimes you need to add sudo if you do not have the correct permissions to delete the file or folder.

rm </path/filename>
rm </emptydirectory>
rm -rf </directorywithcontents>

Options, this is a good time to mention them. Commands have options like above, it can make a command act differently or show more information. Every command has options and listing them all ineffective, instead you can see a commands options by adding –help to the base command as shown in some examples below. –help will explain the commands purpose, the correct syntax (how to use it), command options and much more information. If you ever forget a command you can also use whatis to view a breif description of it.

cd --help
cp --help
whatis mv
whatis rm

history command can be helpful if your trying to recall a command you used. You can recall your commands previously used on screen by using the history command.

history

df and du are helpful commands to see either the filesystem information about the disk space usage, or display the directory and file sizes. free command also shows the amount of free space available on the system

df
du
free

Other helpful system wide commands are Uname -A and Man. uname -a provide a wide range of information across the system. Man command provide a onscreen terminal manual page with much detail, this can be great to learn more commands or understand others better. info is also very similar to man but much more detailed information.

uname -A
man
info

Lastly, but not least – passwd command is used to change your password, or change the password of a specified user. Note, you might need to add sudo to run as admin if you do not have the rights.

passwd
passwd <username>
sudo passwd <username>



Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *