Useful console linux commands
Introduction
Below are some linux commands you might find useful.
They can be run from any terminal emulator (xterm, konsole, etc.) or from a virtual console by pressing Ctrl+Alt+F{1..12}
.
The uptime
console command shows the time (days) the computer has been up without a reboot.
admin@ip-172-31-27-178:~/quickstart$ uptime
15:11:49 up 42 days, 19:50, 1 user, load average: 0.00, 0.00, 0.00
For disk usage by filesystem, use the df
console command.
admin@ip-172-31-27-178:~/quickstart$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 98M 544K 97M 1% /run
/dev/xvda1 ext4 7.7G 1.9G 5.4G 27% /
tmpfs tmpfs 486M 0 486M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/xvda15 vfat 124M 12M 113M 10% /boot/efi
tmpfs tmpfs 98M 0 98M 0% /run/user/1000
If you want to see the memory usage in the Linux console:
admin@ip-172-31-27-178:~/quickstart$ free -m
total used free shared buff/cache available
Mem: 970 327 137 0 662 642
Swap: 499 4 495
The tail
command shows the last 10 lines from a text file, such as a log file.
The -f
option will update the screen if there are new lines in the file.
admin@ip-172-31-27-178:~/quickstart$ tail -f /var/log/apache2/access.log
31.94.30.124 - - [02/Jan/2025:15:06:15 +0000] "GET /livereload.js?mindelay=10&v=2&port=1313&path=livereload HTTP/1.1" 404 521 "https://www.georgetech.co.uk/posts/my-second-post/" "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0"
31.94.30.124 - - [02/Jan/2025:15:06:15 +0000] "GET /css/style.css HTTP/1.1" 200 4835 "https://www.georgetech.co.uk/posts/my-second-post/" "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0"
31.94.30.124 - - [02/Jan/2025:15:06:32 +0000] "GET / HTTP/1.1" 200 2329 "https://www.georgetech.co.uk/posts/my-second-post/" "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0"
The systemctl status
command is useful to see the status of a service (loaded/active).
Use this for example if you asked your web server to reread its configuration files with systemctl reload apache2.service
.
It also shows associated log entries, useful to see if there are issues with the application.
admin@ip-172-31-27-178:~/quickstart$ systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-12-06 19:08:23 UTC; 3 weeks 5 days ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 92234 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 49693 (apache2)
Tasks: 55 (limit: 1137)
Memory: 28.3M
CPU: 1min 20.933s
CGroup: /system.slice/apache2.service
├─49693 /usr/sbin/apache2 -k start
├─92238 /usr/sbin/apache2 -k start
└─92239 /usr/sbin/apache2 -k start
Dec 06 19:48:42 ip-172-31-27-178 apachectl[50534]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using fe>
Dec 06 19:48:42 ip-172-31-27-178 systemd[1]: Reloaded apache2.service - The Apache HTTP Server.
Dec 06 19:51:52 ip-172-31-27-178 systemd[1]: Reloading apache2.service - The Apache HTTP Server...