My most useful Linux terminal commands for Ubuntu/Debian


Recommended Posts

Hi all. For a new video I've made a list with my most used/useful terminal commands.
Please let me know what I've missed, or which commands you use most.
 

Useful Linux commands for Ubuntu/Debian
---------------------------------------
Update/Install
--------------
sudo apt update                               Update repolists
sudo apt upgrade                              Upgrade system/programs
sudo apt autoremove                           Remove obsolete programs
sudo apt install programName                  Install program
sudo apt remove programName                   Remove program 
sudo aptitude install                         When having issue's with apt, aptitude can help to solve this
sudo apt update && sudo apt upgrade           Update and upgrade together/You can run multiple commands with &&
sudo dpkg -i packageName.deb                  Install .deb file

Root user
---------
sudo passwd                                   Change root password
su                                            Super User/Enter root user

Debug/Monitor
-------------
dmesg                                         Shows debug messages 
uname -a                                      Shows basic system information
env                                           Shows the environment information
htop                                          Hardware monitor

Switch terminal
---------------
ctrl + ALT + F4       (F1 - F6)                                    Open new terminal 4
ctrl + ALT + F1                                                    Go back to terminal 1
ctrl + ALT + F7                                                    Go back to desktop 

Reboot/Shutdown
---------------
sudo reboot                                   Reboot
sudo shutdown now                             Shutdown

CPU Tools
---------
cpufreq-set -g performance                    Set governor to performance
cpufreq-set -u 2Ghz                           Set max frequency for all cores
cpufreq-set -c 0-1 -u 1.8Ghz                  Set max frequency for specific cores
lscpu | grep MHz                              Show cpu frequency    
taskset -c 3 programName                      Use a specific core for an application   

Files/Directories
-----------------
nano /home/fileToRemove.txt                   Create a txt file with Nano. You could use any other texteditor.
touch filename                                Create an empty file, no matter what kind
cat /home/fileToRemove.txt                    Shows the content of a file
cp /home/fileToRemove.txt /home/copy.txt      Copy file
find /home/ -iname "*.txt"                    Search files that end with .txt
comm /home/fileToRemove.txt /home/copy.txt    Compare files
rm /home/fileToRemove.txt                     Remove file
mv /home/copy.txt ~/Documents/                Move file
mkdir /home/directoryToGoTo/                  Create directory
cd /home/directoryToGoTo/                     Go to directory
ls                                            List directory
ls -l                                         Gives more information about every file/directory
ls -l filename.txt                            Gives file information
pwd                                           Show current working directory
cd ..                                         Go to the above directory
rmdir /home/directoryToGoTo/                  Remove directory                             
wget http://www.website.com/file.txt          Download file

Zip/Tar/GunZip
--------------
zip myzip file1 file2 file3                   Create zip file
unzip myzip.zip                               Unzip file
tar xvf filename.tar
gunzip filename_tar.gz

Mount drives/USB Devices
------------
lsusb                                         List USB devices
lsblb                                         List attached drives
mount /mount/mountedDisk /dev/sda2            Mount drive
sudo chmod -R 777 /mount/mountedDisk          Give user read/write permissions
df -a                                         List all filesystems

Swap file/ZRam
--------------
sudo apt install zram-config                  Install zram script

sudo fallocate -l 8G /swapfile                Allocate 8GB for swapfile
sudo chmod 600 /swapfile                      Give the correct rights for the swapfile
sudo mkswap /swapfile                         Make it a swapfile
sudo swapon /swapfile                         Turn on the swapfile
sudo nano /etc/fstab                          Open fstab and add the line ...
  |_
       /swapfile swap swap defaults 0 0


Wifi
----
sudo nano /etc/network/interfaces 

and write:
 auto wlan0
 iface wlan0 inet dhcp 
                wpa-ssid {ssid}
                wpa-psk  {password}
				
				OR
				
nmcli device wifi rescan                                           Scan for available wifi networks
nmcli device wifi list                                             Show available wifi networks
nmcli device wifi connect SSID-Name password wireless-password	   Connect wifi

ip a                                                               Show ip
ifconfig                                                        
iwconfig

Change Keyboard Layout
----------------------
sudo dpkg-reconfigure keyboard-configuration                       Set keyboard layout

Add display resolution
----------------------
cvt 2560 1440 60                                                   Select the display resolution you want
# 2560x1440 59.96 Hz (CVT 3.69M9) hsync: 89.52 kHz; pclk: 312.25 MHz
Modeline "2560x1440_60.00"  312.25  2560 2752 3024 3488  1440 1443 1448 1493 -hsync +vsync

xrandr --newmode "2560x1440_60.00"  312.25  2560 2752 3024 3488  1440 1443 1448 1493 -hsync +vsync         Add resolution, everything after Modeline from cvt is copied after newmode

xrandr --addmode HDMI-1 2560x1440_60.00                                                                    Add the new resolution to your display

xrandr --newmode "2560x1440_60.00"  312.25  2560 2752 3024 3488  1440 1443 1448 1493 -hsync +vsync && xrandr --addmode HDMI-1 2560x1440_60.00 

Others
------
reset                                                              Clear terminal 
shift + page up                                                    Scroll up
shift + page down                                                  Scroll down 
tab                                                                Autocomplete
ctrl + c                                                           Quit for many programs 
date                                                               Show date/time
cal                                                                Show calender


Funny commands
--------------
sl                                                                 First need to install "sudo apt install sl", then try it out. It's great :) 
sl -alF
cmatrix
fortune/fortune-mod
cowsay 
figlet 
toilet 
ponysay 
inxi 
cat /dev/urandom 
:(){ :|:& };:                                                     Endless loop (useful to test CPU maximized temperatures)

Armbian
-------
sudo armbianmonitor -m                                             
sudo armbian-config

change cpu settings
sudo nano /etc/default/cpufrequtils

Made by NicoD 	

 

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?

Pimp your bash. To be fair I copied some from the link at the bottom:

 

A few commands are needed quite often and to reduce typing a little bit, voila:

To create the file  nano ~/.bash_aliases


############################
# my personal Aliases list #
############################
# to create the file  nano ~/.bash_aliases


# **** DIRECTORY LISTING in human-readable units ****
alias ll="ls -lhAF"
alias ..="cd .."
alias ...="cd ../../../"
alias back="cd $OLDPWD"

alias lsmount="mount |column -t"


# * Disk Space Usage in human-readable units,  including filesystem type *
alias dfh="df -Tha --total"

alias df="df -h --exclude=squashfs"


# * ALL files in a directory listed,  according their size *
alias du="du -ach | sort -h"


# * listing process table in detail *
alias psa="ps auxf"

alias dmesg="dmesg --human"


# * How to really CLEAR the terminal *
alias clr='printf "\033c"'

alias h="history"



# reload bash config
alias reload="source ~/.bashrc"
Now execute  . ~/.bashrc  in your terminal (there should be a space between the . and ~/.bashrc )

 

https://pastebin.com/kzPjE8y4    |   http://smlr.us/

 

Link to post
Share on other sites
37 minutes ago, qstaq said:

Looks good! Only thing missing for my linux noobs is a simple tar overview for extracting and creating archives and a simple grep overview

Thank you. That's indeed missing. I'll add it for the next video.

 

38 minutes ago, qstaq said:

Can I win the hat this time please?

I still haven't found a hat sponsor. Sorry :)
 

Link to post
Share on other sites

 

As having to get along with old alcatel and debian 

I come along with this script for DHCP is crap.

 

ip link set dev enp4s0 down
ip addr del 169.254.7.102/16 dev enp4s0
ip addr add dev enp4s0 local 10.0.1.1/24 broadcast 10.0.0.31
ip link set dev enp4s0 up

 

For the other netcard I have to add

ip route add default dev enp4s6 src 10.0.0.7 via 10.0.0.138

 

now everthing works fine here. Never use alcatel!

Link to post
Share on other sites

sudo reboot Reboot                      try  systemctl reboot

sudo shutdown now Shutdown   try  systemctl poweroff

systemctl restart gpm often needed with debian

   - " -       start, stop, ....  program instead of /etc/init.d/program startm restart, stop

journalctl -b -p err Bootmeldungen, dazu nur die Fehlermeldungen wasaschaßis,
            weil da haddascho gestiefelt    --since-yesterday
journalctl --since=2012-10-15 --until="2011-10-16 23:59:59"
journalctl -u httpd --since=00:00 --until=9:30 
journalctl /dev/sdc
journalctl /usr/sbin/vpnc
journalctl -o verbose -n
journalctl -xe
journalctl -b > /0/jounalctl-ge4-ox.txt journalctl -b > /7/journalctl_gd3_.txt

systemctl status tahoe-lafs.service
systemctl -t service      

systemd-cgls | less?
systemctl -a

systemctl list-unit-files  | less
systemctl -r
systemctl --failed
systemctl --now

systemctl --message=ciao --halt
systemctl poweroff  never --force
systemctl start sshd  

systemctl status /dev/sda = systemctl status dev-sda.device
systemctl status /home = systemctl status home.mount  
systemctl stop sshd@*.service
systemctl kill crond.service

systemctl stop sshd
systemctl kill crond.service better than  killall -9 or kill
systemctl enable example1 
systemctl disable example1
systemctl disable ntpd.service   '
systemctl stop ntpd.service
systemctl link /path/to/foo.service
systemctl status networking.service
systemctl list-units 
'systemctl status bluetooth.service' and 'journalctl -xn'
ln -s /dev/null /etc/systemd/system/ntpd.service  

systemctl daemon-reload  

 

BUT

systemd-analyze plot > /tmp/plot.svg  fascinating!

Link to post
Share on other sites
On 12/19/2019 at 5:15 AM, gleam said:

AFAIK i really use often commands with systemctl and pure ip. Both are very useful. Especially "ip"for all problems with net.

systemD is worth to learn about

Ciao

Well I looked at  https://linuxjourney.com/ carefully but by lack of all systemD commands it might be a little bit outdated, Routing is not worth to be mentioned as IPv6 never ist mentioned

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...