{"id":71,"date":"2023-02-21T14:27:15","date_gmt":"2023-02-21T14:27:15","guid":{"rendered":"http:\/\/www.qchartist.net\/blog\/?p=71"},"modified":"2023-09-08T05:58:31","modified_gmt":"2023-09-08T05:58:31","slug":"useful-shell-commands-and-apps-under-ubuntu-12-04-and-later","status":"publish","type":"post","link":"https:\/\/www.qchartist.net\/blog\/useful-shell-commands-and-apps-under-ubuntu-12-04-and-later\/","title":{"rendered":"Useful shell commands and apps under Ubuntu 12.04 and later"},"content":{"rendered":"\n<p>Useful shell commands and apps under Ubuntu 12.04:<br><br>&#8220;cat \/var\/log\/apache2\/access.log&#8221; provides information on the latest visitors to your website<br>For the last lines : &#8220;cat \/var\/log\/apache2\/access.log | tail&#8221;<br>To search lines containing a specific string use : &#8220;cat \/var\/log\/apache2\/access.log | grep [my string]&#8221;<br>To know if the user with ip 1.2.3.4 surfed on the page contact.html use : &#8220;cat \/var\/log\/apache2\/access.log | grep 1.2.3.4 | grep contact.html&#8221;<br>To display all the lines, except those containing my local address : &#8220;cat \/var\/log\/apache2\/access.log | grep -v 127.0.0.1&#8221;<br><br>tcpspy allows to log most of tcp connections.<br>Use &#8220;cat \/var\/log\/syslog | grep tcpspy&#8221;<br><br>slurm : know your bandwidth usage<br>usage example : &#8220;slurm -i eth0&#8221;<br><br>snort gets all what passes by your Internet cable (useful to see all what is hidden with netstat, like udp connections)<br>usage example : &#8220;sudo snort -i eth0 -X -v&#8221;<br><br>tcpdump can also help you if you want to optimize your network<br>example : &#8220;sudo tcpdump -i eth0 -n -N&#8221;<br><br>to know who is currently connected to your server use :<br>&#8220;netstat -taunp&#8221;<br><br>whois gets informations about the Internet services provider of an ip<br>usage example : &#8220;whois [ip or domain name]&#8221;<br><br>How to download an entire &#8220;Index of \/&#8221; tree of a website ? : &#8220;wget -e robots=off -r \u2014no-parent \u2014reject &#8220;index.html*&#8221; http:\/\/www.mywebsite.com\/files\/&#8221;<br><br>Some packages related to &#8220;os user statistics&#8221; you could remove :<br>&#8220;sudo apt-get remove &#8211;purge zeitgeist zeitgeist-core zeitgeist-datahub&#8221;<br>&#8220;sudo apt-get remove &#8211;purge unity-lens-shopping&#8221;<br><a href=\"https:\/\/www.howtogeek.com\/349844\/how-to-stop-ubuntu-from-collecting-data-about-your-pc\/\">https:\/\/www.howtogeek.com\/349844\/how-to-stop-ubuntu-from-collecting-data-about-your-pc\/<\/a><br><br><br>display only the last 333 lines of a file:<br>tail myfile.txt -n 333<br><br>display line jumps and line numbers of a file:<br>cat -A -n myfile.txt<br><br>search for the string &#8220;my search&#8221; in all files of the actual directory and subdirectories and display file path and name for each result:<br>grep &#8220;&#8221; * -r | grep &#8220;my search&#8221;<br><br>change the owner of all files, directories and subdirectories of the directory &#8220;mydir&#8221; to dupont:dupont:<br>chown dupont:dupont mydir -R<br><br>change chmod permissions to 400 for all files, directories and subdirectories of the directory &#8220;mydir&#8221;:<br>chmod 400 mydir -R<br><br>add chmod execution permission for the user of all files, directories and subdirectories of the directory &#8220;mydir&#8221;:<br>chmod u+x mydir -R<br><br>change chmod permissions to 400 for files but not directories :<br>find . -type f &#8211; print0 | xargs -0 chmod 400<br><br>find for files or directories which name look like &#8220;log&#8221; in all the tree &#8220;\/var\/log\/&#8221;:<br>find \/var\/log\/ | grep log<br><br>display the temperature near the cpu:<br>sensors<br><br>display all services with their status (started or not):<br>service &#8211;status-all<br><br>Tip to decrease the reactivity of your pc\/laptop the way it consumes less energy and heats less:<br>Install and configure the packages laptop-mode and powernap and then start them with &#8220;sudo service myservice start&#8221;<br>You can also know the consumption of each process with the package powertop<br><br>how to display a list with the full process names (not truncated):<br>ps aux | less -+S<br>or<br>ps aux | most -w<br><br>how to display the list of all documents and files that archive.org has archived for the website http:\/\/www.mywebsite.com\/ :<br>https:\/\/web.archive.org\/web\/*\/http:\/\/www.mywebsite.com\/*<br><br>List all members of a group using members command:<br>Install it with &#8220;sudo apt-get install members&#8221;<br>use : &#8220;members mygroup&#8221;<br><br>To do integer &amp; float calculations:<br>type &#8220;bc&#8221;<br>enter your calculation: type &#8220;1+1&#8221; and hit the enter key<br>type &#8220;quit&#8221; to quit the program<br><br>To list all users you can use:<br>cut -d: -f1 \/etc\/passwd<br><br>To add a new user you can use:<br>sudo adduser new_username<br>or<br>sudo useradd new_username<br><br>To remove\/delete a user, first you can use:<br>sudo userdel username<br><br>Then you may want to delete the home directory for the deleted user account :<br>sudo rm -r \/home\/username<br><br>To modify the username of a user:<br>usermod -l new_username old_username<br><br>To change the password for a user:<br>sudo passwd username<br><br>To change the shell for a user:<br>sudo chsh username<br><br>To change the details for a user (for example real name):<br>sudo chfn username<br><br>To remove a user from a group use:<br>gpasswd -d user group<br><br>display the last (new) lines of a log file live:<br>tail -f \/var\/log\/apache2\/access.log<br><br>How do I download a package from apt-get without installing it?<br>There are a least these apt-get extension packages that can help:<br>apt-offline &#8211; offline apt package manager<br>apt-zip &#8211; Update a non-networked computer using apt and removable media<br>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.<br>Otherwise, the &#8211;download-only option to apt-get is your friend:<br>-d, &#8211;download-only<br>\u00a0 \u00a0 Download only; package files are only retrieved, not unpacked or installed.<br>\u00a0 \u00a0 Configuration Item: APT::Get::Download-Only.<br><br>Close a tcp connection 111.222.333.444 in netstat:<br>tcpkill -i eth0 host 111.222.333.444<br>You need the package dsniff<br><br>To see realtime usage by IP (rather, by IP and port):<br>sudo apt install tcptrack<br>sudo tcptrack -i eth0<br>To see realtime usage by MAC address, a nice ncurses based tool is iptraf-ng:<br>sudo apt install iptraf-ng<br>sudo iptraf-ng<br>(And then, select &#8220;LAN station monitor \u2192 eth0&#8221;.)<br>To see daily aggregate data volume by IP, my favourite is ipfm. Install with:<br>sudo apt install ipfm<br>Then configure in \/etc\/ipfm.conf according to man ipfm.conf and start with sudo ipfm<br><br>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:<br>> host 4.59.125.171<br>171.125.59.4.in-addr.arpa is an alias for 171.128-254.125.59.4.in-addr.arpa.<br>171.128-254.125.59.4.in-addr.arpa domain name pointer 4-59-125-171-hou.servercraft.co.<br>Another way to get the hostname is to user the nslookup command.<br>> nslookup 4.59.125.171<br><br>Show tcp connections for my Firefox web browser on port 443 but hide ips like 92.223.127. and show only blocked connections<br>netstat -anlpc |grep &#8216;Lien vers fire&#8217; | grep 443 | grep -v 92.223.127. | grep SYN_SENT<br>or<br>netstat -taunpc |grep &#8216;Lien vers fir&#8217; | grep 443 | grep -v 92.223.127. | grep SYN_SENT<br><br>How to view Hard Disk Activity on Ubuntu:<br>install packages iotop or htop<br><br>Computer hardware info: sudo lshw<br>Memory info: sudo lshw -C memory<br><br>Find previous commands you typed in the terminal (netstat for example):<br>history | grep netstat<br><br>How to delete Mozilla Firefox telemetry trackers (site in french):<br><a href=\"https:\/\/www.malekal.com\/supprimer-telemetrie-mozilla-firefox\/\">https:\/\/www.malekal.com\/supprimer-telemetrie-mozilla-firefox\/<\/a><br><br>Block certain websites and limit access here&#8217;s what you need to know about the \/etc\/hosts file<br>By editing the hosts files, you can achieve the following things:<br>&#8211; Block a website<br>&#8211; Handle an attack or resolve a prank<br>&#8211; Create an alias for locations on your local server<br>&#8211; Override addresses that your DNS server provides<br>&#8211; Control access to network traffic<br>sudo gedit \/etc\/hosts<br>For example, if we want to block google.com, we can add the following text to our file:<br>127.0.0.1 www.google.com<br>or simply<br>127.0.0.1 google.com<br>Save your changes<br>You don&#8217;t need to reboot or restart a service. Changes are instant.<br><br>How to manage rc.d and systemd services:<br><a href=\"https:\/\/www.debuntu.org\/how-to-managing-services-with-update-rc-d\/\">https:\/\/www.debuntu.org\/how-to-managing-services-with-update-rc-d\/<\/a><br><a href=\"https:\/\/superuser.com\/questions\/513159\/how-to-remove-systemd-services\">https:\/\/superuser.com\/questions\/513159\/how-to-remove-systemd-services<\/a><br><a href=\"https:\/\/linoxide.com\/enable-disable-services-ubuntu-systemd-upstart\/\">https:\/\/linoxide.com\/enable-disable-services-ubuntu-systemd-upstart\/<\/a><br><br>In which package can i find a specific file? Useful for C headers for example:<br>apt-file search pango.h | grep pango.h<br>result package: libpango1.0-dev: \/usr\/include\/pango-1.0\/pango\/pango.h<br><br>Find packages related to llvm:<br>apt-cache search llvm<br><br>Find a package filename and its description:<br>apt-cache show llvm<br><br>Find a file quickly on your hard drive:<br>locate gtk.h<br>or<br>plocate gtk.h<br>or<br>mlocate gtk.h<br>or<br>whereis gtk<br><br>Run the package manager:<br>sudo synaptic<br><br>Return metainformation about installed libraries:<br>(useful for the gcc compiler using GTK in your code)<br>pkg-config gtk+-3.0 &#8211;libs<br><br>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<br><br>then you can compile your code with:<br>gcc myapp.c -lgtk-3 -lgobject-2.0 -lgdk_pixbuf-2.0 -lglib-2.0<br><br>kill a process by its name:<br>pkill galculator<br><br>List all processes by id # order:<br>ps -A<br><br>configure Wine:<br>winecfg<br><br>Find an application from the Snap software list:<br>snap find tradingview<br><br>then install it with:<br>snap install tradingview<br><br>Text editors:<br>vi myfile.txt<br>nano myfile.txt<br><br>Remove a directory and all its content (subfolders and subfiles):<br>sudo rm -r -f myfolder<br><br>Don&#8217;t type all the characters in the terminal with a wildcard (faster):<br>(with Wine installed)<br>cd ~\/.win*<br>cd dr*<br>then list the files in the windows directory:<br>ls win*<br>cd win*s<br>then list all files with details (file size etc&#8230;):<br>ls -l<br>then run notepad.exe with wine:<br>wine notepad.exe<br><br>Read the manual of a tool (nano for example):<br>man nano<br><br>Clear the terminal text:<br>clear<br><br>Go to the home folder:<br>cd ~ (Tilde)<br><br>Know the current path folder:<br>pwd<br><br>Determine direct shared object dependencies of a linux binary:<br>readelf -d myprogram<br>result:<br>La section dynamique \u00e0 l&#8217;offset 0x6c40 contient 31 entr\u00e9es :<br>\u00a0\u00c9tiquettes Type \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Nom\/Valeur<br>0x0000000000000001 (NEEDED) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Biblioth\u00e8que partag\u00e9e: [libgtk-3.so.0]<br>0x0000000000000001 (NEEDED) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Biblioth\u00e8que partag\u00e9e: [libgobject-2.0.so.0]<br>0x0000000000000001 (NEEDED) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Biblioth\u00e8que partag\u00e9e: [libglib-2.0.so.0]<br>0x0000000000000001 (NEEDED) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Biblioth\u00e8que partag\u00e9e: [libm.so.6]<br>0x0000000000000001 (NEEDED) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Biblioth\u00e8que partag\u00e9e: [libc.so.6]<br>etc&#8230;<br><br>How to run a Linux terminal under Windows?<br>&#8211; install Cygwin<br><br>How to run a Linux terminal under Android?<br>&#8211; install Termux<br><br>How to run Windows apps under Linux?<br>&#8211; install Wine<br>type in the terminal: wineconsole cmd<br>for the Windows Commands Interpreter (like Windows&#8217;s cmd.exe)<\/p>\n\n\n\n<p>How to repair a failed or corrupted media using fsck :<\/p>\n\n\n\n<p>in root type: \/usr\/sbin\/dosfsck -w -r -l -a -v -t \/dev\/sdc1<\/p>\n\n\n\n<p>where sdc1 is the media<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Useful shell commands and apps under Ubuntu 12.04: &#8220;cat \/var\/log\/apache2\/access.log&#8221; provides information on the latest visitors to your websiteFor the last lines : &#8220;cat \/var\/log\/apache2\/access.log | tail&#8221;To search lines containing a specific string use : &#8220;cat \/var\/log\/apache2\/access.log | grep [my string]&#8221;To know if the user with ip 1.2.3.4 surfed on the page contact.html use : [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[30],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/posts\/71"}],"collection":[{"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":4,"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qchartist.net\/blog\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}