← all writing

Linux SHELL Guide

· 5 min read · linux / shell-script / bash / cli

Shows all hidden files and folders along with normal ones.

sh
ls -a

list lot of information about non-hidden files and directories

sh
ls -l

list above info for hidden files and directories too

sh
ls -la OR ls -l -a

to switch to a dir same as cd but it just saves the path from which you came

sh
pushd <path>

to switch back to dir from which you came with pushd.

sh
popd

tells details of file

sh
file <name of file>

search a directory or a file in data base

sh
locate <name of file or directory>

or

sh
mlocate <name of file or directory>

NOTE: run before locate/mlocate to update database

sh
sudo updatedb

see calander

sh
cal

see if command is installed or not, returns path of the command

sh
which <command>

brief one-line discription of what a command can do

sh
whatis <command>

shows the commands related to or contain given keyword

sh
apropos <keyword>

equivalent to apropos but show information in readable format

sh
man <keyword>

copy a files and directories

sh
cp -r<path of the file to be copied> <name of the copied file>

move files and directories

sh
mv <path of file> <path to be moved>

delete/remove files

sh
rm <file>

delete/remove directories

sh
rm -r <directorie>

create a text file.

sh
touch <file_name>
echo 'write text here' > textfile.txt
printf 'write \\ntext \\nhere' > textfile.txt

NOTE: use printf for format the text

show the content of a text file on terminal

sh
cat <file>

write into the text file

sh
cat >> <file_name>

copy file1 to file2

sh
cat <file1> >> <file2>

“>” operator will overwrite the existing data

“>>” operator will append data

bash text editor for editing files in CLI format. there are others too

sh
nano <file1>
ls -la ~ >> textfile.txt

switch to root user or root account, to exit type exit

sh
sudo -s

switch to another user account, to exit type exit

sh
su - <username>

move to root user account

sh
su
su -

see how many accounts are logged in

sh
users

executable permission to file for everyone

sh
chmod +x <file_name>

get the PID of programme and all its instances

sh
pidof brave

see the running process

sh
top

kill process by their name

sh
pkill brave
killall brave

kill process by their PID

sh
kill <PID of the process>

get the snapshot of top (Best)

sh
ps aux | grep <name of programme or running file or path or aything relatable to it>

find the exact package

sh
apt search --names--only ___

Install .deb files, then fix missing dependencies

sh
sudo dpkg -i /path/to/.deb/file
sudo apt-get install -f

see package details and dependencies

sh
apt-cache showpkg package-name
apt-cache depends package-name

see package info

sh
dpkg-deb -I package.deb

create and edit cronjobs (scheduled server tasks)

sh
crontab -e

see cronjobs on terminal

sh
crontab -l

create a SCREEN session with name

sh
screen -S <name_of_session>

see detached and running screen session

sh
screen -ls

reattach to detached screen session

sh
screen -r <pid_of_screen_session>

see cronjobs-logs with

sh
journalctl -t CROND

install/extract tar files

sh
tar xvf <file_name>

Find Public IPv4 address

sh
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com

Fix bluetooth in ubuntu>18.04

sh
sudo modprobe -r btusb && sudo modprobe btusb

Instll/Add PPA repository

sh
sudo add-apt-repository ppa:dr-akulavich/lighttable  # adds repository link to /etc/apt/source.list
sudo apt-get update
sudo apt-get install lighttable-installer  # installing the software

Remove PPA repository and link

sh
listppa.sh

Use the above script to see the list of installed PPAs

now remove the ppa

sh
sudo add-apt-repository --remove ppa:bluetooth/bluez

Check mounted/connected disks to the system

sh
lsblk

Command for burning USB {notice the of and if carefully}

sh
sudo dd bs=4M if=Downloads/endeavouros-2021.08.27-x86_64.iso of=/dev/sdb conv=fdatasync status=progress

Set-up ssh key for connecting to git

sh
eval "$(ssh-agent -s)"
chmod 400 <private_key_file>
ssh-add ~/.ssh/<private_key_file> > /dev/null 2>&1

https://stackoverflow.com/questions/10508843/what-is-dev-null-21

Pacman, AUR

List dependency of a package

sh
pacman -Si
or
pacman -Si package_name | grep 'Depends On'
or
pactree -s package_name
or
pactree -sr package_name #see reverse dependency
or
pactree package_name -lu #in format for reinstalling dependency

See locally installed packages~ AUR(s) or installed with AUR helpers.

sh
pacman -Qm or pacman -Qmq

To list all the Fonts installed in your system

sh
fc-list

How to add users in arch Linux

Create the user with adduser or useradd, whichever is present in your system, then set a password for NAME.

sh
useradd NAME
passwd NAME

Give Sudo Privileges to NAME

To give sudo rights to a user you can add him to group wheel. Wheel is the group for users who get every system administrator privilege.

sh
gpasswd -a NAME wheel

Users of the wheel group also need root privileges in /etc/sudoers, otherwise even if you add users to wheel group they will not be able to use sudo. Always edit /etc/sudoers with sudo visudo to avoid errors, and add this line for wheel group users:

sudoers
%wheel ALL=(ALL) ALL

Or you can give a single user root privileges by adding this line to /etc/sudoers. If you choose to do this then you don’t need to add NAME to wheel group.

sudoers
USER_NAME ALL=(ALL) ALL

But the first approach is recommended.