10 commands to get started with Linux

10 commands to get started with Linux

cd

The cd command or the current directory command lets us change the current directory we are in. When we start a terminal, it starts with the root directory.

As we can see, we have entered into the Desktop directory.

Oh wait, for someone who is new to Linux, directories are window's equivalent of folders.

mkdir

The mkdir command or the 'make directory' command is used to create a new directory.

To make a new directory, we type mkdir filename. The syntax accepts only one word as a filename. If we want to give it a name that contains more than one word then it must be enclosed in double quotes "" like this mkdir "file name"

ls

We have created multiple folders in the above example, but how do we know if they are created or not? The ls command or the list command helps us in this situation. It is used to list the components in the current directory we are in.

As we can see, the folders we created are all there in the folder and listed out.

pwd

Sometimes, we change the present working directory so much, that we might forget which directory we are currently in. To know which directory we are operating from, we can use the pwd or the present working directory command.

As we can see, the pwd command gives us the present working directory relative to the root directory.

rmdir

If we are making something, it is obvious that we would want to delete it in the future too. This command is the counterpart of mkdir command. And you guessed it right, it is supposed to remove a directory. It is used as rmdir filename or rmdir "file name"

As we try to list out the contents of the folder, the directory named folder 2 is not there. It is deleted.

touch

We have created folders, so naturally, we would want to create files inside it too. There are a lot of ways to create a file in Linux. touch is one of them. This command is used to create, change, and modify the timestamps of a file.

We use the command followed by the name of the file. touch file1

As we can see, we can create multiple files at once too.

cat

The cat command is a very commonly used command in Linux. It stands for concatenate and can be used to create, view, and update the contents of a file.

The use of this command is pretty extensive and there is a lot it can do(maybe a topic for another blog) but for now, we are going to use it to create and view a file.

To create a file, we use cat >> anotherfile1.txt This not only creates a file but allows us to edit the file as well. We can press ctrl+c to exit the file. And then we can use cat anotherfile.txt to view the contents of the file.

One thing to notice, which is not clear from this screenshot is that using >> with cat allows us to create the file and edit it too, but cat alone just lets us view the file.

rm

This is similar to rmdir, except that it is used to remove files. rm command followed by the filename will do the trick rm filename

cp

The cp command or copy command is used to do what its name suggests. It copies the contents of a folder or files from one to another. It requires at least two arguments. cp source destination (Source and destination refer to the names of files or directories)

We have copied the contents of anotherfile1.txt to file1 and then we are viewing using cat command. We notice the contents of anotherfile1.txt remain unchanged.

mv

The mv command or the move command works just like copy except it moves the contents so now the source will be empty.

Its syntax is also similar to copy. mv source destination

As we can see, after using the mv command to move anotherfile1.txt to file2. When we try to view the file using cat, the file no longer exists thereby implying that it has moved.