Welcome to the QChartist blog QChartist Community – Your way to financial freedom

February 21, 2023

Useful shell commands and apps under Ubuntu 12.04 and later

Filed under: Computers — admin @ 2:27 pm

Useful shell commands and apps under Ubuntu 12.04:

“cat /var/log/apache2/access.log” provides information on the latest visitors to your website
For the last lines : “cat /var/log/apache2/access.log | tail”
To search lines containing a specific string use : “cat /var/log/apache2/access.log | grep [my string]”
To know if the user with ip 1.2.3.4 surfed on the page contact.html use : “cat /var/log/apache2/access.log | grep 1.2.3.4 | grep contact.html”
To display all the lines, except those containing my local address : “cat /var/log/apache2/access.log | grep -v 127.0.0.1”

tcpspy allows to log most of tcp connections.
Use “cat /var/log/syslog | grep tcpspy”

slurm : know your bandwidth usage
usage example : “slurm -i eth0”

snort gets all what passes by your Internet cable (useful to see all what is hidden with netstat, like udp connections)
usage example : “sudo snort -i eth0 -X -v”

tcpdump can also help you if you want to optimize your network
example : “sudo tcpdump -i eth0 -n -N”

to know who is currently connected to your server use :
“netstat -taunp”

whois gets informations about the Internet services provider of an ip
usage example : “whois [ip or domain name]”

How to download an entire “Index of /” tree of a website ? : “wget -e robots=off -r —no-parent —reject “index.html*” http://www.mywebsite.com/files/”

Some packages related to “os user statistics” you could remove :
“sudo apt-get remove –purge zeitgeist zeitgeist-core zeitgeist-datahub”
“sudo apt-get remove –purge unity-lens-shopping”
https://www.howtogeek.com/349844/how-to-stop-ubuntu-from-collecting-data-about-your-pc/


display only the last 333 lines of a file:
tail myfile.txt -n 333

display line jumps and line numbers of a file:
cat -A -n myfile.txt

search for the string “my search” in all files of the actual directory and subdirectories and display file path and name for each result:
grep “” * -r | grep “my search”

change the owner of all files, directories and subdirectories of the directory “mydir” to dupont:dupont:
chown dupont:dupont mydir -R

change chmod permissions to 400 for all files, directories and subdirectories of the directory “mydir”:
chmod 400 mydir -R

add chmod execution permission for the user of all files, directories and subdirectories of the directory “mydir”:
chmod u+x mydir -R

change chmod permissions to 400 for files but not directories :
find . -type f – print0 | xargs -0 chmod 400

find for files or directories which name look like “log” in all the tree “/var/log/”:
find /var/log/ | grep log

display the temperature near the cpu:
sensors

display all services with their status (started or not):
service –status-all

Tip to decrease the reactivity of your pc/laptop the way it consumes less energy and heats less:
Install and configure the packages laptop-mode and powernap and then start them with “sudo service myservice start”
You can also know the consumption of each process with the package powertop

how to display a list with the full process names (not truncated):
ps aux | less -+S
or
ps aux | most -w

how to display the list of all documents and files that archive.org has archived for the website http://www.mywebsite.com/ :
https://web.archive.org/web/*/http://www.mywebsite.com/*

List all members of a group using members command:
Install it with “sudo apt-get install members”
use : “members mygroup”

To do integer & float calculations:
type “bc”
enter your calculation: type “1+1” and hit the enter key
type “quit” to quit the program

To list all users you can use:
cut -d: -f1 /etc/passwd

To add a new user you can use:
sudo adduser new_username
or
sudo useradd new_username

To remove/delete a user, first you can use:
sudo userdel username

Then you may want to delete the home directory for the deleted user account :
sudo rm -r /home/username

To modify the username of a user:
usermod -l new_username old_username

To change the password for a user:
sudo passwd username

To change the shell for a user:
sudo chsh username

To change the details for a user (for example real name):
sudo chfn username

To remove a user from a group use:
gpasswd -d user group

display the last (new) lines of a log file live:
tail -f /var/log/apache2/access.log

How do I download a package from apt-get without installing it?
There are a least these apt-get extension packages that can help:
apt-offline – offline apt package manager
apt-zip – Update a non-networked computer using apt and removable media
This is specifically for the case of wanting to download where you have network access but to install on another machine where you do not.
Otherwise, the –download-only option to apt-get is your friend:
-d, –download-only
    Download only; package files are only retrieved, not unpacked or installed.
    Configuration Item: APT::Get::Download-Only.

Close a tcp connection 111.222.333.444 in netstat:
tcpkill -i eth0 host 111.222.333.444
You need the package dsniff

To see realtime usage by IP (rather, by IP and port):
sudo apt install tcptrack
sudo tcptrack -i eth0
To see realtime usage by MAC address, a nice ncurses based tool is iptraf-ng:
sudo apt install iptraf-ng
sudo iptraf-ng
(And then, select “LAN station monitor → eth0”.)
To see daily aggregate data volume by IP, my favourite is ipfm. Install with:
sudo apt install ipfm
Then configure in /etc/ipfm.conf according to man ipfm.conf and start with sudo ipfm

The host command in unix or linux operating system can be used to get the hostname from an IP address. An example is shown below:
> host 4.59.125.171
171.125.59.4.in-addr.arpa is an alias for 171.128-254.125.59.4.in-addr.arpa.
171.128-254.125.59.4.in-addr.arpa domain name pointer 4-59-125-171-hou.servercraft.co.
Another way to get the hostname is to user the nslookup command.
> nslookup 4.59.125.171

Show tcp connections for my Firefox web browser on port 443 but hide ips like 92.223.127. and show only blocked connections
netstat -anlpc |grep ‘Lien vers fire’ | grep 443 | grep -v 92.223.127. | grep SYN_SENT
or
netstat -taunpc |grep ‘Lien vers fir’ | grep 443 | grep -v 92.223.127. | grep SYN_SENT

How to view Hard Disk Activity on Ubuntu:
install packages iotop or htop

Computer hardware info: sudo lshw
Memory info: sudo lshw -C memory

Find previous commands you typed in the terminal (netstat for example):
history | grep netstat

How to delete Mozilla Firefox telemetry trackers (site in french):
https://www.malekal.com/supprimer-telemetrie-mozilla-firefox/

Block certain websites and limit access here’s what you need to know about the /etc/hosts file
By editing the hosts files, you can achieve the following things:
– Block a website
– Handle an attack or resolve a prank
– Create an alias for locations on your local server
– Override addresses that your DNS server provides
– Control access to network traffic
sudo gedit /etc/hosts
For example, if we want to block google.com, we can add the following text to our file:
127.0.0.1 www.google.com
or simply
127.0.0.1 google.com
Save your changes
You don’t need to reboot or restart a service. Changes are instant.

How to manage rc.d and systemd services:
https://www.debuntu.org/how-to-managing-services-with-update-rc-d/
https://superuser.com/questions/513159/how-to-remove-systemd-services
https://linoxide.com/enable-disable-services-ubuntu-systemd-upstart/

In which package can i find a specific file? Useful for C headers for example:
apt-file search pango.h | grep pango.h
result package: libpango1.0-dev: /usr/include/pango-1.0/pango/pango.h

Find packages related to llvm:
apt-cache search llvm

Find a package filename and its description:
apt-cache show llvm

Find a file quickly on your hard drive:
locate gtk.h
or
plocate gtk.h
or
mlocate gtk.h
or
whereis gtk

Run the package manager:
sudo synaptic

Return metainformation about installed libraries:
(useful for the gcc compiler using GTK in your code)
pkg-config gtk+-3.0 –libs

returns: -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

then you can compile your code with:
gcc myapp.c -lgtk-3 -lgobject-2.0 -lgdk_pixbuf-2.0 -lglib-2.0

kill a process by its name:
pkill galculator

List all processes by id # order:
ps -A

configure Wine:
winecfg

Find an application from the Snap software list:
snap find tradingview

then install it with:
snap install tradingview

Text editors:
vi myfile.txt
nano myfile.txt

Remove a directory and all its content (subfolders and subfiles):
sudo rm -r -f myfolder

Don’t type all the characters in the terminal with a wildcard (faster):
(with Wine installed)
cd ~/.win*
cd dr*
then list the files in the windows directory:
ls win*
cd win*s
then list all files with details (file size etc…):
ls -l
then run notepad.exe with wine:
wine notepad.exe

Read the manual of a tool (nano for example):
man nano

Clear the terminal text:
clear

Go to the home folder:
cd ~ (Tilde)

Know the current path folder:
pwd

Determine direct shared object dependencies of a linux binary:
readelf -d myprogram
result:
La section dynamique à l’offset 0x6c40 contient 31 entrées :
 Étiquettes Type                         Nom/Valeur
0x0000000000000001 (NEEDED)             Bibliothèque partagée: [libgtk-3.so.0]
0x0000000000000001 (NEEDED)             Bibliothèque partagée: [libgobject-2.0.so.0]
0x0000000000000001 (NEEDED)             Bibliothèque partagée: [libglib-2.0.so.0]
0x0000000000000001 (NEEDED)             Bibliothèque partagée: [libm.so.6]
0x0000000000000001 (NEEDED)             Bibliothèque partagée: [libc.so.6]
etc…

How to run a Linux terminal under Windows?
– install Cygwin

How to run a Linux terminal under Android?
– install Termux

How to run Windows apps under Linux?
– install Wine
type in the terminal: wineconsole cmd
for the Windows Commands Interpreter (like Windows’s cmd.exe)

How to repair a failed or corrupted media using fsck :

in root type: /usr/sbin/dosfsck -w -r -l -a -v -t /dev/sdc1

where sdc1 is the media

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

Powered by WordPress