Getting familiar with terminal 2

Riza mohammad Khan
3 min readOct 22, 2023

In this tutorial, we will assume that you are already familiar with the basics of Linux. If not, please review the basics: link.

We will cover some shortcuts, commands, file permissions, and the super user account in this tutorial.

Shortcuts

riza@hussain:~/projects$ ls . # we use dot `.` for current directory 
macro 'main.mojo ' # output

riza@hussain:~/projects$ cd .. # we use .. for previous directory
riza@hussain:~$

riza@hussain:~$ cd - # we use - for previous working directory(previous working)
/home/riza/projects

riza@hussain:~/projects$ echo "hello" > hello.txt
# we use > operator for redirecting output
# similarly we use < operator for redirecting input
# this operation creates a file named hello.txt and writes in "hello" (overide)

riza@hussain:~/projects$ echo "hello" >> hello.txt
# we use >> operator to append output of echo to hello.txt

riza@hussain:~/projects$ cat 'main.mojo ' #we use cat operator to display file content
from sys import argv
fn main():
let li = argv():
print_no_newline(li," ")
print()

rm command

riza@hussain:~/projects$ ls
hello.txt macro 'main.mojo '
riza@hussain:~/projects$ rm hello.txt # we use rm command to remove files
riza@hussain:~/projects$ ls
macro 'main.mojo '

riza@hussain:~/projects$ rm -r * # we use rm -r to recursively remove all files (*)
riza@hussain:~/projects$ ls

File permissions

many times user struggle with this concept in unix. I’ll try to keep it simple

#use ls -l to list all the files in long form 
riza@hussain:~/projects$ ls -l
total 4
-rw-r--r-- 1 riza riza 0 Oct 22 22:02 echo
-rw-r--r-- 1 riza riza 6 Oct 22 22:03 hello.txt

now whats `-rw-r--r- -r- -` its actually mainly three permission for three users. first three are for user u, second three are for group gand last three are for others o. Here r stand for read, w stands for write and x stands for executable. Here in above we see that all the files above are not executable. To change file permission we use chmod [ugo][+-][rwx] file name will make a file executable. let us see some examples

riza@hussain:~/projects$ chmod u+x hello.txt #here we use u for user x to make executable + to add 
riza@hussain:~/projects$ ls -l
total 4
-rw-r--r-- 1 riza riza 0 Oct 22 22:02 echo
-rwxr--r-- 1 riza riza 6 Oct 22 22:03 hello.txt
# here above you see a x has been placed
# now to make this file again not executable we use - instead of +

riza@hussain:~/projects$ chmod u-x hello.txt
riza@hussain:~/projects$ ls -l
total 4
-rw-r--r-- 1 riza riza 0 Oct 22 22:02 echo
-rw-r--r-- 1 riza riza 6 Oct 22 22:03 hello.txt

riza@hussain:~/projects$ chmod g+x hello.txt #here we use g for group
riza@hussain:~/projects$ ls -l
total 4
-rw-r--r-- 1 riza riza 0 Oct 22 22:02 echo
-rw-r-xr-- 1 riza riza 6 Oct 22 22:03 hello.txt

Lets go to the root

In unix installing many packages requires root privilages.To use this we use sudo (do as super user)

riza@hussain:~$ cd /bin
riza@hussain:/bin$ touch hello
touch: cannot touch 'hello': Permission denied
riza@hussain:/bin$ sudo touch hello #it works

To remain continous as super user we use sudo su

riza@hussain:/bin$ cd ~
riza@hussain:~$ sudo su
root@hussain:/home/riza# #changes to root user from riza@hussian to root@hussain

That’s all for this tutorial on Linux basics. Next, we will learn about shell scripting. In the meantime, keep practicing using the Linux shell!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Riza mohammad Khan
Riza mohammad Khan

Written by Riza mohammad Khan

HI my name is Riza mohammad khan.

No responses yet

Write a response