linux (Arch) usefull commands #022

Remove a file:

rm boringvideo.mp4

Remove a non empty folder (-rf ) displaying more information (-v):

rm -rf -v boringvideosfolder

Remove a folder in the user home folder:

rm ref -v ~/FutileVideos



MOVE a file or RENAME it

mv original_file_name.mp4 renamed_file_name.mp4

examples:
  • move this_file.mp4 to /home/thisguy/Downloads
mv this_file.mp4 ~/Downloads/

note: the ~/ means home directory of the user
  • move a file two folders up from the local directory:
mv ../../some_file.mp4  .
  • move all files with mp4 extension into Videos folder, located in current user home directoy ( /home/thisGuy/Videos/) 
mv *.mp4  ~/Videos/

Compare two files:

diff file_name_1.zip file_name_2.zip

check available FREE SPACE:

df




use with  -mT to display the size in megabytes (-m) and display file system type (-T):
df -mT:


check DISK USAGE of a file, since ls command doesn't always display the correct size

du sample_video_file.mp4

use with -h to see size in Mbytes, GBytes "human" readable sizes:

du -h sample_video_file.mp4

Print work directory / display the full path:

pwd

Check manjaro version :

cat /etc/lsb-release

Pause/Stop/Continue a process using the terminal (Konsole):

htop displays the application PID

kill -STOP 16143
kill -CONT 16143

 ^  for the PID process 16143

Pause/Stop/Continue a process in the desktop environment using KSysGuard, just right click to access the menu:


its possible to add default parameters to a bash/terminal command using alias, to see active alias use:


to add more, edit

 open ~/.bashrc with nano(or another text editor) ,  add to the file section of alias(search for alias in it):

 alias ls="ls -ahl" ; this will replace ls command with ld -ashl
 alias lsa="ls -ahl" ; when you type lsa you will get ls -ahl
 alias mpvv="mpv --cache=yes --hwdec=vaapi"
 alias mpva="mpv --cache=yes --player-operation-mode=pseudo-gui"


Mounting a device, umounting and error correction:

the following notes were created after dealing with a mounted usb pendrive that despite being mounted was no longer accessible.

list the devices using lsblk -f ( the -f is for file type)

lsblk -f



or use findmnt command:

findmnt



the pendrive is mounted and the filesystem is extfat
atempt to unmount the device and perform a file system check using umount returns an error, use it again with -l to perform a lazy umount

umount /dev/sda2



now perform a file system check using fsck, -a for auto correct file system
note: exfatfsck /dev/sda2 or fsck.exfat /dev/sda2 perform the same action

fsck -a /dev/sda2


The solution was to mount the device and remove the file, the other solution is to use a Windows OS to fix the USB pendrive

cd /mnt
sudo mkdir usbpart
sudo mount /dev/sda2 /mnt/usbpart/
cd usbpart/
rm f?????????????????3.mp4
sudo umount /dev/sda2
sudo fsck.exfat /dev/sda2



its possible to create new partitions in GParted or KDE Partition Manager, however both those utilities can't format the partitions
to list partitions use:

lsblk -f

to format using NTFS filesystem, use (-f for fast formating):

sudo mkfs.nts /dev/sda2


For other file systems:

sudo mkfs -t vfat /dev/sda1
sudo mkfs -t ext4 /dev/sda1
sudo mkfs -t ntfs /dev/sda1

After, its possible to mount the partitions:

mkdir ~/NewPart
mount /dev/sda2/ ~/NewPart

Monitor disk I/O application: iotop

to install it just run pacman -S iotop, it requires super user privileges, -d 2 parameter makes it refresh every 2 seconds, -o (--only ) to only display process with I/O activity and -a to show accumulated values instead of instant bandwidth:

sudo iotop -d 2 -a -o


Useful keyboard shortcuts:
LEFT and RIGHT arrow keys : choose the sorting order
r : reverse the selected order
o : toggle only display process with I/O activity
a : a to show accumulated values instead of instant bandwidth
q : quit

Shutdown or Restart the computer using commands:

sudo systemctl reboot

sudo systemctl poweroff

display network interfaces:

ip link show


Monitor network I/O application: nethogs

to install it just run pacman -S nethogs, it requires super user privileges, -d 2 parameter makes it refresh every 2 seconds, the -v 3 will display a counter of the total amount of data. If there are several netowork devices either use -a or specify the device, example : nethogs eth0 eth1. Help output of nethogs:



sudo nethogs -d 2 -a



Useful keyboard shortcuts:
m: mode (KB/s, total KB, total B, total MB)
s: sort by SENT traffic
r: sort by RECEIVE traffic
q : quit




Comments