Introduction

According to William Shotts in the Fifth Internet Edition of the book “The Linux Command Line” described “Freedom is the power to decide what your computer does, and the only way to have this freedom is to know what your computer is doing. Freedom is a computer that is without secrets, one where everything can be known if you care enough to find out.”

This article help you remember some basic Linux Commands that every Linux user should know. It’s basic but useful.

Few recommand Websites:

First view

First understand of the Shell

date Command

Displays the current time and date.

1
date
1
2
kali@kali:~$ date
Sun Nov 27 07:55:49 AM UTC 2022

df Command

To see the current amount of free space on our disk drives

1
df
1
2
3
4
5
6
7
8
9
kali@kali:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 400252 1224 399028 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 10218772 3719172 5958928 39% /
tmpfs 2001244 0 2001244 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
/dev/nvme0n1p2 1768056 141524 1518400 9% /boot
/dev/nvme0n1p1 973952 5220 968732 1% /boot/efi
tmpfs 400248 4 400244 1% /run/user/1000

For exampleUbuntu 22.10 aarch64 Server Vertual Machine

free Command

To display the amount of free memory

1
free
1
2
3
4
kali@kali:~$ free
total used free shared buff/cache available
Mem: 4002488 197008 3568192 1228 237288 3650284
Swap: 0 0 0

exit Command

Ending a Terminal Session

1
exit
1
2
3
4
kali@kali:~$ exit
logout

[*] Connection Closed

Help you navigate the file system on Linux which is cool

pwd Command

Print name of current working directory

1
pwd
1
2
kali@kali:~$ pwd
/home/kali

ls command

List directory contents

1
ls
1
2
kali@kali:~$ ls
Workspace

If you want check more information like size,time,etc.

1
ls -l
1
2
3
kali@kali:~$ ls -l
total 4
drwxrwxr-x 3 kali kali 4096 Nov 27 08:54 Workspace

We can specify the directory to list, for example under /usr

1
ls /usr
1
2
kali@kali:~$ ls /usr
bin games include lib libexec local sbin share src

cd Command

Move from one directory to another

1
cd

Move to the Workspacefor example

1
2
3
4
kali@kali:~$ cd Workspace
kali@kali:~/Workspace$ ls
python
kali@kali:~/Workspace$

What if I want to back to the orignial directory

1
cd ~
1
2
3
4
kali@kali:~/Workspace$ cd ~
kali@kali:~$ ls
Workspace
kali@kali:~$

tree Command

Use tree structure to show the directory

(You may need to install that first)

For under APT package manager

1
sudo apt install tree
1
tree
1
2
3
4
5
6
7
kali@kali:~/Desktop $ tree
.
└── Info
└── Photo
└── wallpapers.jpg

2 directories, 1 file

More about file

file Command

Determining a File’s Type with file

1
file filename
1
2
kali@kali:~/Workspace/python/env$ file pyvenv.cfg
pyvenv.cfg: ASCII text

less Command

A program to view text files

1
less filename
1
kali@kali:~/Workspace/python/env$ less pyvenv.cfg

File context:

1
2
3
4
5
6
7
8
9
10
home = /usr/bin
implementation = CPython
version_info = 3.10.7.final.0
virtualenv = 20.16.7
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3
~
(END)

Click q :quit less

Click h :Display help screen

Less Is More

Manipulating Files and Directories

cp Command

Copy files and directories

1
cp existing_file.txt existing_file.back
1
2
3
4
kali@kali:~/Workspace/python/env$ cp pyvenv.cfg pyvenv.cfg.2
kali@kali:~/Workspace/python/env$ ls
bin lib pyvenv.cfg pyvenv.cfg.2
kali@kali:~/Workspace/python/env$

mv Command

Move/rename files and directories

1
mv item1 item2
1
2
3
4
5
6
7
8
9
kali@kali:~/Workspace/python/env$ ls
bin lib pyvenv.cfg pyvenv.cfg.2
kali@kali:~/Workspace/python/env$ mv pyvenv.cfg.2 /home/kali
kali@kali:~/Workspace/python/env$ ls
bin lib pyvenv.cfg
kali@kali:~/Workspace/python/env$ cd ~
kali@kali:~$ ls
pyvenv.cfg.2 Workspace
kali@kali:~$

rm Command

Remove Files and Directories

1
rm item1
1
rm item1 item2
1
2
3
4
5
6
kali@kali:~$ ls
pyvenv.cfg.2 Workspace
kali@kali:~$ rm pyvenv.cfg.2
kali@kali:~$ ls
Workspace
kali@kali:~$
PurposeCommand
Delete a single filerm filename
Delete multiple filesrm file1 file2 file3
Force remove filesrm -f file1 file2 file3
Remove files interactivelyrm -i *.txt
Remove an empty directoryrm -d dir
Remove a directory with its contentsrm -r dir
Remove multiple directoriesrm -r dir1 dir 2 dir3

Table Sources: linuxhandbook.com

Be Careful with rm

1
sudo rm -rf /*

sudo: root user permission

-r : is an option of the rm command, indicating recursive processing, all files in the specified directory will be processed together with subdirectories

-f : is optional to the rm command, which means to force the deletion of a file or directory

🤭

mkdir Command

Create Directories

1
mkdir directory
1
2
3
4
kali@kali:~$ mkdir Test
kali@kali:~$ ls
Test Workspace
kali@kali:~$

Collection

clear Command

clean your shell and feel better

1
clean

ps Command

Manage the processes running on your system

1
ps
1
2
3
4
5
kali@kali:~$ ps
PID TTY TIME CMD
1346 pts/0 00:00:00 bash
1670 pts/0 00:00:00 ps
kali@kali:~$

See all processes running by all users

1
ps aux
1
2
3
4
5
6
7
8
9
kali@kali:~$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 167500 11340 ? Ss 07:55 0:00 /sbin/init
root 2 0.0 0.0 0 0 ? S 07:55 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 07:55 0:00 [rcu_gp]
...
...
...
kali@kali:~$

lsblk Command

Displays disks and partitions

1
lsblk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
kali@kali:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 131.3M 1 loop /snap/lxd/23687
loop1 7:1 0 132.2M 1 loop /snap/lxd/23996
loop2 7:2 0 43M 1 loop /snap/snapd/17579
loop3 7:3 0 59M 1 loop /snap/core20/1699
loop4 7:4 0 41.5M 1 loop /snap/snapd/17339
loop5 7:5 0 59M 1 loop /snap/core20/1627
sr0 11:0 1 1024M 0 rom
nvme0n1 259:0 0 20G 0 disk
├─nvme0n1p1 259:1 0 953M 0 part /boot/efi
├─nvme0n1p2 259:2 0 1.8G 0 part /boot
└─nvme0n1p3 259:3 0 17.3G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 10G 0 lvm /
kali@kali:~$

history Command

Go back and see what commands you’ve run in the past

1
history
1
2
3
4
5
6
7
8
9
10
kali@kali:~$ history
1 ls
2 sudo apt update
3 sudo apt upgrade -y
4 htop
5 ls
...
...
...
kali@kali:~$

ping Command

1
ping ip_address
1
2
3
4
5
6
7
8
9
10
kali@kali:~$ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.069 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.150 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.299 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2054ms
rtt min/avg/max/mdev = 0.069/0.172/0.299/0.095 ms
kali@kali:~$
Continuously updated

Cover: Ubuntu Discourse(Jocix)