A powerful tool, the Linux command line is fast and effective. It lets you complete tasks faster that would otherwise take longer using the GUI. Being familiar with basic commands goes a long way. To help you get started with Linux, we cover some of the most frequently used commands.
Though we are using Ubuntu 20.04, you will be fine if you have other Linux versions.
pwd (print working directory)
One of the simplest commands, pwd lets you print the path of the folder you are in, your current working directory.
Run:
pwd
cd (Change directory)
One of the most commonly used commands, cd lets you change directories. Let’s say you want to go to the Downloads directory. It would be:
cd Downloads
If you want to go back to your previous directory, use:
cd -
To move up one directory, use:
cd ..
To go to your home directory, use:
cd ~
ls (Listing files)
This command is used to list the contents of a directory by default, it displays the content of your current working directory. The command is:
ls
If you want to see the contents of other directors, go to the directory’s path to view them.
You can use different variations of the command to view specific information.
To view the contents of subdirectories, use:
ls –R
To view hidden files:
ls –a
To view details like file size, permissions, owners, etc., use:
ls –al
cat (concatenate)
This command lets you create files, view its contents, redirect input to files, and concatenate them.
Let’s see how this works. The command is:
cat >> filename
Next, you enter your text and then hit CTRL+d to exit.
To view the contents of this file, use:
cat filename
Let’s see how concatenation works. We will create another file first.
To combine both files, use:
cat {file1} {file2} > {newfile}
We have combined the files in catfile3.txt. To view the contents of catfile3.txt, use:
mkdir (make directory)
This command lets you create new directories. Run:
mkdir {directoryname}
To verify if the directory was created, use ls.
To create multiple directories, use:
mkdir {directoryname1 directoryname2 directoryname3}
rm
To delete a single file, use:
rm filename
To verify if it was deleted, use ls.
As you may have noticed, you don’t have the option to confirm if you really want to delete the file. To change that, use:
rm –i {filename}
As you can see, it asks first, to confirm, hit Enter.
To delete a directory, use:
rm -d {directory name}
To verify if the directory was deleted, use ls.
This command only deletes empty directories, if it has content, you cannot use it.
To delete such directories, use:
rm –r {directoryname}
To verify if the directory was deleted, use ls.
passwd (Change password)
You can change passwords using this command. Unless you are a root, you can only change your password.
The command for changing your own password is:
passwd
You will be asked to enter the following:
Current password
New password
Retype the new password
You will have to en-enter your new password if it’s the same as your current one.
Entering the wrong password causes the authentication to fail.
clear
If you want to clear the clutter on your terminal, use:
clear
It clears the terminal and gives you a clean space to work on.
history
To view all the commands you have used in the current terminal session, use:
history
By default, history shows you the past five hundred commands you have used.
man (manual)
This command is very helpful on getting help on commands you don’t understand. It gives details on the command, its options, errors, return values, versions, examples, etc.
Run:
man {command}
And there you have it some useful Linux commands to help you get started.