Linux is a free, open-source operating system. It broadly denotes operating systems distributions built around the Linux kernel. Linux kernel is an operating system kernel first released on September 17, 1991 by Linus Torvadls.
This guide will introduce you to the Linux operating system and will equip you to learn more about Linux.
The Linux terminal is an extremely powerful tool that goes well beyond the GUI. To open a terminal, the shortcut Ctrl+Alt+T will work on most distributions and desktop environments.
This is the basic anatomy of most Linux commands:
[sudo] command [optional switch] [file or directory path]
The Linux commands are case-sensitive. When the command is pwd
everything part for pwd
would throw an error. For example, Pwd
, PWD
, pWd
, etc
A space is also equally important.
Note: The infamous Ctrl+C and Ctrl+V won't work! Instead, you must use Ctrl+Shift+C and Ctrl+Shift+V; or you can right click and use the commands from the dropdown menu.
Before you dive into the basics it is probably helpful to remember these:
[command] --help
will show the usage of the command, and the available options and switchesman [command]
will show the command's manual, which is an extended version of the --help output
And just so you know, not all Linux commands have a manual page. But, most of them that you would be learning, do have a manual page.
All the commands henceforth demonstrated are expected to be typed into your terminal unless otherwise specified.
In this section, we demonstrate commands that will help you navigate to particular directories (folders) and locate files.
ls -- list directory contents
This command is used for listing all the directory contents. Make sure you read the ls --help to learn about the options...
ls
cd -- change directory
This command is used for navigation within your file system.
To put in 'Windows' terms this command is used to switch between folders.
cd [directory]
pwd -- print working directory
This command is used to print the full path to the directory that you are presently situated in. pwd stands for print working directory.
pwd
find -- search for a file
This command is used to find a particular file in the present working directory.
find [file or directory]
locate -- locate a file or directory This command is used to locate a file or a directory in the entire file system.
locate [file or directory]
In this section you will learn how to create, delete, and basic file manipulation.
mkdir -- make directory
This command is used to create a directory.
mkdir [path to new directory]
You can include the absolute path to the directory to create it anywhere on the disk.
touch -- create an empty file
This command is used to create a new(empty) file.
touch [path to file]
If the file already exists, touch
won't erase its contents, it will just change the last access time to the current time.
cp -- copy
This command is used to, well, copy stuff.
cp [path to source] [path to destination]
The cp
command copies the file at source to the file at destination. This is the equivalent copy-paste.
If the file at destination does not exist then, the file is created.
To copy directories and their contents, we need to use:
cp -r [path to source] [path to destination]
mv -- move
This command is used to move files between locations
mv [path to source] [path to destination]
The mv
command is the equivalent of cut-paste. The command also works with directories without the need of an option.
The mv
command is the only way to rename files in Linux.
rm -- remove
This command is used to delete files or directories.
rm [path]
To delete a directory and all its contents, we need to use:
rm -r [path to directory]
The rm command will immediately remove any files/directories, without using Trash. Exercise caution while usage of this command.
zip -- creates a zipped folder
This command creates a zipped folder that contains a compressed file.
zip [archive.zip] [file]
unzip -- unzips a compressed folder
This command unzips a compressed folder.
unzip [archive.zip]
By default, unzip will extract all the files in the working directory.
echo - write arguments to standard output
This command writes the arguments to the specified location.
echo "text" > [path to file]
Caution! If the file already exists, the echo "text" > file
will overwrite it, deleting all of its previous content.
Using >>
instead of >
will append the text at the end.
echo "text" >> [path to file]
cat -display the contents of the file
This command display all the contents of a text file on the terminal.
cat [path to file]
We can also use head [text file]
to only show the first ten lines, and tail [text file]
to display the last ten lines.
wc -- word count
Prints the word count, number of lines and the number of characters in a file.
wc [path to file]