Asciinaut.sh
post-img

Introduction

It doesn't matter if you are already working on Linux or not. In this post, you will learn some Linux commands. There are 25 of them absolutely everybody should know! What you will learn with this post (or add it to favorites and copy-paste) will boost you both as a user, as well as an admin.

cd

What this command does is to browse throughout directories. Example usage: cd /var

ls

With this command you list files. You can use it both for your current directory with a simple ls or you can use it to see the contents of different directory ls /desired/directory. You can use the a flag to show hidden files(starting with .) ls -a. If you want to get more information about the files, for example, what their permissions are, who the owner is, and at what time & date they have been updated/created, you can use the -l argument - ls -l. You can of course merge both of the arguments and list all the hidden files, as well as get a lot of information - ls -la.

nano

With this command you can edit files - it is a text editor. However, you can use it to create files as well. If you open a not existing file with nano you can save it and this way you create the file. Example usage: nano my-new-file. You can save with ctrl+o & exit with ctrl+x.

touch

With this command you create files. Example usage: touch my-new-file.

cat

With this command, you print the contents of a file. Example usage cat my-file.

less

With this command, you can in a way 'open' the file and browse through it with the arrows. You can also search in the file with /. Example usage: less my-file

tail

With this command, we print the finishing lines of a file. We can specify how many lines to print with the -n flag. Example usage tail -n 15 my-file to print 15 lines of a file.

head

This command is the same as tail but from the start of the document.

df

With this command, we check what our storage usage is. For a more human-readable version of the number, we use the -h flag. Example usage df -h.

mv

With this command, we move a file from one directory to another. Example usage mv /path1/file1 /path2/. We also rename files with this command. Example usage mv file-name-1 file-name-2.

ping

With this command, we test our connectivity to a server. We can also check for packet loss in the output of the command. Example usage ping google.com.

rm

With this command, we remove/delete. We can delete files with rm my-file or delete directories with rm -r my-directory. There is one more flag we can is - f which FORCES the delete. This(rm -rf is one of the most dangerous commands to use because it does not prompt you to ask if you want to delete the directory specified - it deletes it on the go. Careful!

mkdir

With this command, we create a directory. Example usage mkdir my-new-dir.

cp

With this command we copy. We can copy the contents of a file and output it to another, already existing one - cp existing-file1 existing-file2, or we can copy the content of the file and create a new file and output it there cp existing-file my-new-file.

sudo

With this command, we execute a command with administrative privileges. Of course, this is only possible if the user is in the sudoers group. Example usage sudo <command>.

su

With this command, we switch users. Example usage su user1.

useradd

With this command, we create a new user. Example usage useradd username.

passwd

With this command, we change the password of an existing user. Example usage passwd user1.

chmod

With this command, we change the permissions of a file/directory. Permissions are being calculated accordingly - 1 execute; 2 - write; 4 - read. When we assign permissions we use 3 digit number structured from the permissions for the owner, permissions for the group, and permissions for others. Example: chmod 754 file1 - in this command, we specified file1 has full read, write & execute access for the owner, read and execute permissions for the group, and read-only for everybody else. To understand more about permissions, please check this source.

chown

With this command, we change the owner for the directory/files. Example usage chown userA.

grep

With this command, we can filter data. We can, for example, use it while trying to cat a file and we only need a specific word. Example scenario: We need to find the line where the word 'Dinosaur' exists in a file named 'myFile'. Example command: cat myFile | grep 'Dinosaur'.

Bonus: we use | when we want to execute 2 commands at the same time to work together.

clear ctrl+l

We use this command to clear the screen of the terminal. pssst, we don't use it. We use ctrl + l to clear the screen.

ip a

With this command, we can find the IP of our server. The command is pretty straight forward - ip a.

Conclusion

Today you learned 25 crucial to your admin journey commands. I hope you feel safer in the terminal and I hope you are going to be careful with the rm -rf one.

Happy browsing & be safe!

© 2020 | Denislav Gavrilov

Subscribe