Published on

Linux Terminal Commands

The Linux terminal is a powerful tool for accessing and manipulating your operating system. It allows you to execute commands, navigate the file system, and perform various tasks from the command line. In this blog, we will go over some basic Linux terminal commands that you can use to get started.

One of the most basic things you will need to do in the terminal is navigate the file system. Here are some commands that will help you do this:

pwd

The pwd command stands for "print working directory." When you run this command, it will show you the full path of the current directory you are in. This can be helpful if you need to know where you are in the file system or if you need to specify a file or directory path in a command.

cd

The cd command stands for "change directory." You can use this command to move around the file system. For example, if you want to go to your downloads directory, you can run the following command:

cd downloads

ls

The ls command stands for "list." When you run this command, it will show you a list of the files and directories in the current directory. You can use the -l flag to show more detailed information about each file, such as its size, permissions, and the date it was last modified.

File and Directory Management

In addition to navigating the file system, you will also need to manage files and directories in the terminal. Here are some commands that will help you do this:

touch

The touch command is used to create a new file. You can specify the name of the file you want to create, like this:

touch newfile.txt

This will create a new file called newfile.txt in the current directory.

mkdir

The mkdir command stands for "make directory." You can use this command to create a new directory. For example, to create a new directory called newdir, you can run the following command:

mkdir newdir

cp

The cp command stands for "copy." You can use this command to copy a file or directory to a new location. For example, if you want to copy a file called file.txt to a new directory called backup, you can run the following command:

cp file.txt backup

You can also use the -r flag to copy a directory and all of its contents. For example, to copy the directory mydir and all of its contents to a new location called backup, you can run the following command:

cp -r mydir backup

mv

The mv command stands for "move." You can use this command to move a file or directory to a new location. It is similar to the cp command, but it will delete the original file or directory after it has been copied to the new location.

For example, if you want to move a file called file.txt to a new directory called newdir, you can run the following command:

mv file.txt newdir

You can also use the mv command to rename a file or directory. For example, if you want to rename the file oldfile.txt to newfile.txt, you can run the following command:

mv oldfile.txt newfile.txt

rm

The rm command stands for "remove." You can use this command to delete a file or directory. For example, to delete the file file.txt, you can run the following command:

rm file.txt

You can also use the -r flag to delete a directory and all of its contents. For example, to delete the directory mydir and all of its contents, you can run the following command:

rm -r mydir

Text Editing

The terminal also allows you to edit text files. Here are some commands that will help you do this:

cat

The cat command stands for "concatenate." When you run this command, it will print the contents of a file to the terminal. For example, to print the contents of the file file.txt, you can run the following command:

cat file.txt

nano

The nano command is a text editor that you can use to edit text files. To open a file in nano, you can run the following command:

nano file.txt

grep

The grep command stands for "global regular expression print." You can use this command to search for a string in a file. For example, to search for the string "hello" in the file file.txt, you can run the following command:

grep "hello" file.txt

This will display any lines in the file that contain the word "hello." You can use the -r flag to search recursively through a directory and all of its subdirectories.

Process Management

The terminal also allows you to manage processes. Here are some commands that will help you do this:

ps

The ps command stands for "process status." When you run this command, it will show you a list of all the processes that are currently running on your system. You can use the -a flag to show all processes, including those that are not owned by the current user.

kill

The kill command is used to terminate a process. You can specify the process ID of the process you want to terminate, like this:

kill 1234

top

The top command is used to display a list of all the processes that are currently running on your system. It will show you information about each process, such as its process ID, CPU usage, memory usage, and the command that started it.

Package Management

If you are using a Linux distribution that uses a package manager, such as apt or yum, you can use the terminal to install, update, and remove packages. Here are a few basic commands that you can use:

apt-get install

The apt-get install command is used to install a package. You can specify the name of the package you want to install, like this:

apt-get install vim

apt-get update

The apt-get update command is used to update the list of available packages. You should run this command before installing a package to make sure that you are installing the latest version.

apt-get remove

The apt-get remove command is used to remove a package. You can specify the name of the package you want to remove, like this:

apt-get remove vim