Linux Commands - DAY 6
technonotes-hacker
Posted on August 12, 2023
26-07-2023
REBOOT
- restart or reboot of the Linux system .
sudo reboot
sudo shutdown -r now
sudo reboot -f --> force reboot
ssh root@remote-server /sbin/reboot --> remote server restart
cat /sbin/reboot --> not in readable form
HELP
- help command provides information on built-in commands.
- which helps get information about all commands.
help help
help cd
help -d help
help -d ls
help -d cd
help -m help
help -m pwd
d --> short description
m --> pseudo-manpage format
help -m ls [ not working , why ? ]
help -d cat [ not working , why ? ]
help cat [ not working , why ? ]
AT, ATQ, BATCH, ATRM
- to schedule commands to be executed at a particular time.
- queue, examine, or delete jobs for later execution.
sudo apt install at
at
date
at 23.33
at> df -Th > df.txt
at> CTRL+D
atq --> to list the jobs in queue
atrm <job_number> --> cancel the jobs in queue
Why these commands not working ???
NOLOGIN
- it will allow users with no shell access.
sudo useradd -s /sbin/nologin user
cat /etc/passwd | grep nologin
tail -2 /etc/passwd
CHSH
- change to shell.
sudo chsh -s /bin/bash user4
tail -2 /etc/passwd
chsh ( just typing this will be helpful for current user logged in or To change the login shell for user)
CRONTAB
- used to automatic schedule.
crontab -l
crontab -e
Eg., create a script name sample.sh to display amount of free
and used memory in the system with timestamp
cat > sample.sh
#!/bin/bash
free -h
echo "this is memory available"
current_time=$(date)
echo "time is: $current_time"
To execute this script for every 2 minutes and write to
file called free.log
create free.log file
touch free.log
crontab -e
*/2 * * * * /bin/bash /home/venus/sample.sh >>
/home/venus/free.log
Restart the service which is very important,
sudo systemctl restart cron.service
crontab -l
WGET
- used to non-interactive download of files from the web or to view the site status like testing the site is accessible or not.
wget http://path/to/url
wget https://www.kaniyam.com/download/Learn%20GNU
%20Linux%20in%20Tamil%20-%20Part%201.pdf
wget https://www.kaniyam.com/download/Learn-GNU-Linux-
in-Tamil-Part-2.pdf
cat downloads.txt --> download multiple sites
http://path/to/url1
http://path/to/url2
http://path/to/url3
wget -i downloads.txt
wget http://path/to/url1 http://path/to/url2
DU
- to estimate file space usage.
du /etc --> it will show all files or folders size
du /home
du -h /etc --> size in human readable format
du -h /home/testing
du -sh /etc --> total usage size of a particular directory
du -hs * --> size of current folder
du -chs *
du -hsc /home/testing --> grand total of the folder
SYSTEMCTL
- to control the service managers.
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl status mariadb.service
sudo systemctl enable mariadb.service --> this will help to start the service when the system gets rebooted.
sudo systemctl disable mariadb.service
sudo systemctl list-units --type=service --> status of all service
sudo systemctl list-units --type=service --state=active/running/stopped/enabled/disabled/failed
sudo systemctl kill -s 9 <service_name> ( kill the service too)
systemctl daemon-reload ( reload all daemon services )
TAR
- an archiving utility
mkdir tar_examples && cd tar_examples
mkdir files && cd files
touch file{0..1000}.txt
cd ..
tar cf myfiles.tar files --> archiving using tar
tar tf myfiles.tar --> list the files in tar
tar -xvf myfiles.tar --> to extract
tar cf myfiles.tar.gz files --> archive using gzip
tar tf myfiles.tar.gz --> to list
tar -xvzf myfiles.tar.gz --> to extract
APT
- command-line interface for the package management.
- Advanced package tool, or APT, is a free-software user interface that works with core libraries to handle the installation and removal of software on Debian, and Debian-based Linux distributions.
sudo apt update
sudo apt install vsftpd apache2 mariadb-server --> install packages
sudo apt depends bind9 --> check dependencies
sudo apt search apache2 --> search packages
sudo apt show apache2 --> information about the package
sudo apt upgrade --> mostly don't try this , until any issues are faced in the current version.
sudo apt autoremove --> remove unused package
sudo apt autoclean --> clean the repository
To removed any package, first keep in mind - stop the service,
sudo systemctl stop apache2
sudo apt purge apache2
sudo apt list
ADD-APT-REPOSITORY
- Adds a PPA repository into the /etc/apt/sources.list.
- Is a script which adds an external APT repository to either /etc/apt/sources.list or a file in /etc/apt/sources.list.d/ or removes an already existing repository.
- A personal package archive (PPA) is a repository that hosts software packages built and maintained by individuals or groups and made available for others.
- PPAs are a convenient way to access the latest software versions that are not yet available in the official repositories of the operating system.
sudo add-apt-repository ppa:PPA_REPOSITORY_NAME/PPA
sudo add-apt-repository ppa:ondrej/php --> php PPA repository
sudo apt update
sudo apt install php
sudo add-apt-repository --remove ppa:PPA_REPO_NAME/PPA
sudo add-apt-repository --remove ppa:ondrej/php
RSYNC
- a fast, versatile, remote (and local) file-copying tool.
- Its an alternate for scp.
- scp will start from the begining if any network issue happens in between but rsync will start from where it stopped.
mkdir -p /home/venus/Documents/backup
rsync -v *.txt /home/venus/Documents/backup
rsync -av --progress *.txt
your_username@remote_server:/home/testing/ --> local to remote
rsync -av --progress testing@ip:/home/testing/*.txt . --> remote to local
SCP
- OpenSSH secure file copy.
scp *.txt testing@remote_server:/home/testing/
scp testing@remote_server:/home/testing/file.txt . --> server to local
scp -r example_folder testing@remote_server:/home/testing/ --> copy folder
scp -r testing@remote_server:/home/testing/example_folder . --> remote to local
CURL
- curl (short for "Client URL") is a command line tool that enables data transfer over various network protocols.
- Linux curl command is used to download or upload data to a server via supported protocols such as HTTP, FTP, IMAP, SFTP, TFTP, IMAP, POP3, SCP, etc. It is a remote utility, so it works without user interaction.
curl https://www.kaniyam.com/foundation/
curl https://www.kaniyam.com/foundation/ > curl_file.txt
curl -# -O https://www.kaniyam.com/download/Learn%20GNU%20Linux%20in%20Tamil%20-%20Part%201.pdf --> shows the download and transfer rate.
FREE
- free and used memory in the system.
free
free -h --> human readable
free -g/m/k/b --> in Bytes/KB/MB/GB
free -s 2 --> every 2 sec
free -h > free.log --> redirect
IFCONFIG
- shows network interface.
ifconfig -a
ifconfig -s --> short
ifconfig lo --> to display any one network
IP
- show / manipulate routing, network devices, interfaces and tunnels.
- It is similar to the ifconfig command.
- all these below commands will have information about the connected networks.
ip -a
ip -4 a
ip link ls up --> shows the running interface
ip addr show
ip route show --> IP route table
NETSTAT
- The network statistics ( netstat ) command is a networking tool used for troubleshooting and configuration, that can also serve as a monitoring tool for connections over the network.
netstat --all
netstat -l --> list the port
netstat -at --> list TCP port
netstat -au --> UDP port alone
netstat -lt --> TCP port
netstat -s --> statistics for all ports
netstat -c --> continuously
sudo netstat -tulpn | grep 80
sudo netstat -tulpn | grep https
PING
- send ICMP ECHO_REQUEST to network hosts.
ping google.com
ping -c 5 google.com --> limit the number of pings
ping -c 5 -q google.com --> print the statistics
ALIAS
- creating alias for a command which you use frequently or any command.
- Aliases expire with the current shell session . or
- Define in ~/.bashrc. which will be permanent.
alias c=clear
alias f=free -h
c
f
Above command won't work with another session.
vi ~/.bashrc
alias c=’clear’
alias u=’uptime’
aliad f=’free -h’
:wq! Save and exit
After adding enter the below command , so that the file gets refreshed.
source ~/.bashrc
UNALIAS
- to remove the alias.
unalias u
unalias f
CLEAR
- which is used to clear the terminal.
clear
control + l
reset
SOURCE
- source is a shell built-in command which is used to read and execute the content of a file(generally set of commands), passed as an argument in the current shell script.
- Execute commands from a file in the current shell.
source ~/.bashrc
source /etc/profile
cat > example.txt
free -h
pwd
date
time
uptime
source example.txt
SH
- is a command language interpreter that executes commands read from a command line string, the standard input, or a specified file.
sh
sh sample.sh
SSH
- is a program for logging into a remote machine and for executing commands on a remote machine.
ssh user@122.132.123.33
ssh user@server.com
ssh user@my.server.in -p 2222 --> using port
TLDR
- Display simple help pages for command-line tools.
- The TLDR (stands for “Too Long; Didn't Read“) is a community-driven project that provides concise and simplified documentation for various Linux commands.
tldr -u --> update the local cache of tldr pages
tldr free
Need to discuss this error ,
Important Notes:
- The Internet Control Message Protocol (ICMP) is a protocol that devices within a network use to communicate problems with data transmission. In this ICMP definition, one of the primary ways in which ICMP is used is to determine if data is getting to its destination and at the right time.
- Ping works by sending an Internet Control Message Protocol (ICMP) Echo Request to a specified interface on the network and waiting for a reply.
💖 💪 🙅 🚩
technonotes-hacker
Posted on August 12, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.