Welcome to our ultimate guide to the Linux Command Line. This tutorial will show you some of the key Linux command line technologies and introduce you to the Bash scripting language.
Now the first question arises in your mind is that What is Bash?
Bash (short for Bourne Again Shell) is a Unix shell, and a command language interpreter. A shell is simply a macro processor that executes commands.
Many things that can be done Linux operating system can be done via command line. Some examples are…
- Editing files
- Adjusting the volume of the operating system
- Fetching web pages from the internet
- Automating work you do every day
- Downloading the Github repositories
Linux Command Line Terminal Shortcuts:
First, we’ll cover some tips that will make the command line easier to use:
- Use tab for auto completion. After you start typing something in the Linux terminal, hit tab and it will suggest possible options that start with the string you have typed so far.
ctrl+r search_termto search commands you have previously used.
- Quickly move to the beginning or end of a line with
- Reuse the previous command in the present command with
- You can run multiple commands in a single line by separating commands with a
Linux Command Line:
Linux has a ton of commands, but most people only use a fraction of them. Here are some of the most used Linux commands to use in the terminal.
List directory contents.
ls /applications will display all the files and folders stored in the applications folder.
Change to a directory.
Example: Change from the current directory to /usr/local with
Rename or move file(s) or directories.
Example: the command
mv app.txt /home/alifya/Documents would move “app.txt” to the “Documents” directory.
Create a new directory.
mkdir iotfiles will make a directory named “iotfiles”.
Delete empty directories.
Create an empty file with the specified name.
Remove file(s) and/or directories.
rm app.txt will delete the file.
Locate a specific file.
locate -i rust*module command will search for any file that contains the word “rust” and “module”. The
-i makes the search case-insensitive.
Clear a command line screen/window for a fresh start.
Copy files and directories.
Example: the command
cp app.txt /home/alifya/Documents would create a copy of “app.txt” to the “Documents” directory.
Create an alias for Linux commands.
alias search=grep will allow you to use
search instead of
Display the contents of a file on the screen.
cat app.txt will show the text of “app.txt” on the screen.
Change who owns a file.
chown alifya app.txt will make “alifya” the owner of “app.txt”.
Change a file’s permissions.
chmod 777 app.txt will make “app.txt” readable, writable, and executable by everyone. The digits in “777” specify the permissions for user, group, and others, in that order.
How to Write permissions?
Here are some of the examples that will help you understand the structure of writing the permissions.
Perform tasks that require administrative or root permissions.
sudo passwd alifdgr8y to change the password of user “alifya”.
for files matching a provided pattern. This command is for searching
file(s) and folder(s) using filters such as name, size, access time, and
find /home/ -name todo.txt will search for a file named “todo.txt” within the home directory and its subdirectories.
Search files or output for a particular string or expression. This command searches for lines containing a specified pattern and, by default, writes them to the standard output.
grep run todo.txt will search for the word “run” in the “todo.txt” file. Lines that contain “run” will be displayed.
Display or set the system date and time.
Display report on the system’s disk space usage.
how much space each file takes up. This will show the size in disk
block numbers. If you want to see it in bytes, kilobytes, and megabytes,
-h argument like this:
Determine the type of a file.
file todo.txt would likely show the type of “ASCII text”.
Shows the command history.
Stop a process.
Example: Stop a process with a PID of 485 using the command
kill 485 Use the
ps command (below) to determine the PID of a process.
View the contents of a file one page at a time.
less todo.txtwill display the contents of “todo.txt”.
Display a list of the currently running processes. This can be used to determine PIDs needed to
Display the pathname for the current directory. “print working directory”
Remotely log in to another Linux machine, over the network.
ssh firstname.lastname@example.org will login to 220.127.116.11 using the username “alif”.
tail – Display the last 10 lines of a file. See fewer or more lines by using the -n (number) option.
tail -n 5 todo.txt will display the last 5 lines of “todo.txt”.
Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz).
Displays the resources being used on your system, similar to the task manager in Windows.