Skip to content

Linux Commands#

Basic Linux Commands#

Install .deb files#

1
sudo dpkg -i package_file.deb

Remove an application#

1
sudo apt remove application-name

Create a new file#

1
touch fileName.md

Search a file that you don't remember exactly the name#

  • Search files that contains "school" and "note".
1
locate -i school*note

Search text in a given file#

  • Search all lines in file notepad.txt that contains word "blue"
1
grep blue notepad.txt

View first lines of any text file.#

  • Show the first five lines.
1
head -n 5 filename.md

View the last 10 lines of any text file.#

  • Show the last 10 lines.
1
tail -n 10 filename.md

Compare 2 files line by line#

  • Show lines that are different between 2 files.
1
diff file1.md file2.md

Extract tar file#

1
sudo tar -xvf filename.tar

Turn Off Swap Memory#

1
sudo swapoff -a

Open Folder UI From Terminal#

  • Use the command below to open the current folder UI from terminal
1
xdg-open .
  • If you want to open a specific folder UI from terminal then you can put the path.
1
xdg-open xdg-open ~/Downloads

Install .rpm files#

sudo rpm -i package_file.rpm

Fix Can't Mount Drive NTFS#

sudo ntfsfix <drive lable>

# Example

sudo ntfsfix /dev/sda

Mount Drive By Terminal#

  • Create a folder for mounting
1
mkdir ~/share
  • List Disks
1
lsblk
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS                                                     2367* sudo umount /dev/sda                                                            
loop0    7:0    0     4K  1 loop /var/lib/snapd/snap/bare/5                                      2368  cd                                                                              
loop1    7:1    0  63.9M  1 loop /var/lib/snapd/snap/core20/2105                                 2369  clear                                                                           
loop2    7:2    0 349.7M  1 loop /var/lib/snapd/snap/gnome-3-38-2004/143                         2370* sudo umount /dev/sda                                                            
loop3    7:3    0  91.7M  1 loop /var/lib/snapd/snap/gtk-common-themes/1535                      2371* ls                                                                              
loop4    7:4    0  40.9M  1 loop /var/lib/snapd/snap/snapd/20290                                 2372* sudo mount /dev/sda  /home/duc/Shared                                           
loop5    7:5    0 417.2M  1 loop /var/lib/snapd/snap/wine-platform-7-stable-core20/6             2373* systemctl deamon-reload                                                         
loop6    7:6    0 495.1M  1 loop /var/lib/snapd/snap/wine-platform-runtime-core20/91             2374* systemctl daemon-reload                                                         
sda      8:0    0 465.8G  0 disk                                                                 2375  history                                                                         
sdb      8:16   0 238.5G  0 disk                                                                 2376* sudo systemctl daemon-reload                                                    
├─sdb1   8:17   0   600M  0 part /boot/efi                                                       2377* clear                                                                           
├─sdb2   8:18   0     1G  0 part /boot                                                           2378* ls                                                                              
└─sdb3   8:19   0 236.9G  0 part /home       
  • Print device attributes.
1
sudo blkid
  • Mount disk to folder.
1
sudo mount <disk> <mount folder>
1
sudo mount /dev/sda /home/duc/share
  • Mount with Options.
1
sudo mount -o rw,user,uid=1000,dmask=007,fmask=117  /dev/sda  /home/duc/Shared