Introduction to Linux
Commands
Nicolas El Khoury
Introduction
Linux Shell
Basic Linux Commands
Introduction
Linux is an Operating System, similar to Microsoft Windows and MAC OS. It is
completely open source and free. Several distributions (flavors) exist, including, but
not limited to Ubuntu, Kali Linux, Red Hat Enterprise Linux (RHEL), CentOS, etc.
Linux Servers are used across the vast majority of the servers online due to their
fast, secure, and free characteristics.
Linux Shell
One way to interact with the Operating System is through the Graphical User
Interface. However, this is not the only way. As a matter of fact, most Linux servers
online cannot be accessed through a GUI. An alternative is using the Command Line
Interface, which allows the user to interact with the Operating System through
commands. The Linux Shell is then a program that takes these commands from the
user and sends them to the Operating System to Process.
Basic Linux Commands
In this lecture, we go over some of the Linux commands, especially those that we
will use in this course:
pwd - Short for Print Working Directory. As the name states, this command
prints the absolute path to the current directory.
ls - List files and directories. There are many flags that can be used with this
command. An example is ls -lah:
Introduction to Linux Commands 1
1. -l: Lists files in the long format (permissions, file and directory owners, file
and directory size, date modified, etc).
2. -a : Includes hidden directories and files.
3. -h : Prints sizes in a human-readable format.
man - Displays the user manual for any Linux command (i.e., man ls displays
information about the ls command).
mkdir - used to create directories. mkdir /home/ubuntu/directories Creates the
directory /home/ubuntu/directories . The -p flag ensures that intermediate
directories are created when needed. For example, creating the
/home/ubuntu/directories/directory1/subdirectory1 without the -p flag will not
succeed if the directory1 directory does not exist. mkdir -p
/home/ubuntu/directories/directory1/subdirectory1
cd - Short for Change Directory, used to navigate between directories. For
instance, cd /home/ubuntu/directories/directory1/subdirectory1 will navigate the
user to the directory /home/ubuntu/directories/directory1/subdirectory1 . cd ..
navigates the user to the previous directory.
Introduction to Linux Commands 2
touch - used to create a file. For instance touch newFile.txt
cp - Copy files and directories from the source to the destination. For example,
cp /home/ubuntu/directories/directory1/newFile.txt /home/ubuntu/directories copies
the newFile.txt file from its old directory to /home/ubuntu/directories .
mv - Move files and directories from the source to the destination. For example,
mv /home/ubuntu/directories/directory1/newFile.txt
/home/ubuntu/directories/directory1/subdirectory1 moves the newFile.txt file from
its current directory to /home/ubuntu/directories/directory1/subdirectory1 .
Introduction to Linux Commands 3
echo - Writes characters to the console. The "echo" command also allows
writing content to a file.
1. Write to the console: echo 'hello world!' prints “hello world!” to the console.
2. Write to file: echo 'hello world!' > file.txt prints “hello world!” to a file
named file.txt
cat - Prints the content of a file to the console. cat file.txt
nano - Text Editor. nano file.txt . Allows us to access and edit a file. nano
allows the creation of a file if it doesn’t exist: nano nanoFile.txt
Introduction to Linux Commands 4
chmod - Modify the set of permissions for a file or directory. Currently,
nanoFile.txt has read/write permissions. Modify the permissions of nanoFile.txt
to read-only chmod 400 nanoFile.txt . As you can see, the permissions clearly
changed giving the user only read permissions. Now attempting to modify the
content of the file won’t work.
Code Permission User
0400 Read Owner
0200 Write Owner
0100 Execute / Search Owner
0040 Read Group
0020 Write Group
0010 Execute / Search Group
Introduction to Linux Commands 5
Code Permission User
0004 Read Others
0002 Write Others
0001 Execute / Search Others
chown - Changes the ownership of a file or directory. Currently, nanoFile.txt is
owned by the ubuntu user that created the file. Change the ownership of the
nanoFile.txt file to root chown root:root nanoFile.txt . This command cannot be
performed without root privileges, which brings us to the next command.
sudo - Short for “SuperUser Do”. Performs a command with root permissions or
privileges. Similar to “Run as Administrator” on Windows. sudo chown root:root
nanoFile.txt . This command is now performed using root privileges. Since we
are logged in using the ubuntu user, we are no longer able to see the contents of
the file without using sudo .
rm - Delete files or directories. rm -rf /home/ubuntu/directories
1. -r remove the directory and all subdirectories and files.
2. -f remove the desired files and directories without prompt.
Introduction to Linux Commands 6
Introduction to Linux Commands 7