svg
Post Image
By Daniel Tanque11 de Outubro, 2023In BashLearning

Linux : Bash basics

One of the first ways to interact with a computer was the usage of a terminal, mostly called shell, but currently known as bash or terminal. This is a way to interact with the machine and perform task, mostly used in Linux environments, and still it is very important because when a OS problem appears and there’s no GUI you have to go with the terminal.

Using the terminal it’s not always the most desired thing, but it’s not that hard to use it. In this article you will learn handy commands that may help you on operating in a machine using terminal.

Basic Commands

echo

Used to print a variable

ls

Used to list all content present in a directory

cd 

Used to change directory

pwd

Prints the path of the current directory

mkdir

Creates a new directory

Basic Directory Commands

Imagine you have the following folders path “/tmp/europe/portugal/lisbon” you may create each folder with mkdir, but imagine that there are several folders, it will take a bit of time. To have it all folders generated using the terminal you use the following command:

mkdir -p /tmp/europe/portugal/lisbon

To remove a directory and all its content we use:

rm -r /tmp/my_dir1

To copy a directory and its content:

cp -r my_dir1 /tmp/my_dir1

Basic Files Commands

To create a file:

touch new_file1.txt

To write inside the article on terminal you use (to close you used CTRL+D):

cat > new_file1.txt

To print the content of a file into the terminal:

cat new_file1.txt

To copy or to rename a file:

cp new_file.txt copy_file.txt
mv new_file.txt sample_file.txt

Basic User Commands

To check the who is the current user:

whoami

To get the userid and groupid:

id

To access higher privileges:

sudo

Note that it’s not a good practice to use root, this should be limited and privileges should be carefully given to the users.

To change user:

su <username>

To access via ssh:

ssh <username>@<host>

To download content you can use “curl” or “wget”:

curl <url> -O 
wget <url> -O <filename>

This -O flag enables to save in file format otherwise will be only display in the terminal.

To check the OS version you can access the location:

ls /etc/*release*

You have to use the wildcard * because different systems have different nomenclatures, to get the information you can perform a cat:

cat /etc/*release*

Conclusion

Here you’ve seen the basic of using the bash and some operations you can perform to navigate and interact with files and folders, as well as operating you user commands and downloading files.

svgHow to build a fully fledged app?
svg
svgVi Editor - Basics

Leave a reply