ZSH
Your computer can teach you a lot about how to use it. You have to do the work. You have to study and learn how your computer works. Your computer is the most important source of information about how to install, operate, maintain and repair your computer and the software running on it.
Investigate your terminal and your shell, to make yourself a high performance Linux user. Your terminal is the dashboard for managing your computer. Zsh is one of the most important languages you can use to communicate with your computer.
Bash is usually the default shell for Linux operating systems. Whenever I install a new Linux installation, I usually change my default shell from Bash to Zsh. If you want to use Zsh, you’ll probably have to install it.
Zsh is a more advanced shell. It does everything Bash does and a few more things. It’s easy to install. Use the chsh command (change shell) to change your default shell. Use chsh without sudo to just change your user account to Zsh. Use it with sudo to change the root account.
sudo apt install zsh
works fine. Then use
whereis zsh
to find the path to zsh and then use
sudo chsh -s /usr/bin/zsh
to set it as your default shell. You’ll have to restart your shell for Zsh to run. You may have to restart your computer.
Get in the habit of using your terminal as much as possible. Install your applications with your shell. I read somewhere that installing them on the command line affects how they’re installed. Maintain a smooth running Linux, by using the command line to install most of the applications on your system.
Use, “sudo apt install“, or, “sudo pkcon install“, to install applications. These are commands you will use often and using them will help you get familiar with the terminal and shell. Use the terminal as much as possible. Use your graphical tools when you need to.
Use Discover and Muon Package Manager to supplement your shell, rather than replace it. Install applications from the command line, whenever you can. You can use Discover and Muon to find applications, especially extensions to applications, and then install them using the command line. You can install applications with Discover or Muon, when that is the best strategy.
Explore your file system. Pay particular attention to the /etc directory. That is where the configuration files for many of your applications are. That is where you can get in there and adjust the global settings for your applications, if you want to.
The configuration files for your user account are usually hidden files in your Home directory. You can find them by selecting the hamburger, the three lines at the top right corner of Dolphin, and selecting, “Show Hidden Files” or by entering ls -a on the command line.
The files for the applications you install on your system are in the /etc or the /opt directory. If you want to edit the configuration of the applications in the root account, make sure you edit the correct file for each application, in order to prevent it from being clobbered when the application is updated. You may also need to create a custom.d file with your custom configuration, linked to the default config file, to prevent updates from clobbering your custom settings. Clobbered means the config file is reset to the default settings, whenever that application is updated.
I’m still learning how to use the command line myself. Learning the file structure of Linux is a very complicated puzzle. Writing scripts is like writing in a foreign language. Zsh is actually a computer programming language.
Be careful. Make a back up copy of your files, before you start changing things, so you can replace it in case you break something.
One of the first things I always do is to add this snippet to my .zshrc file
# prompt before overwrite alias rm='rm -i' alias cp='cp -i' alias mv='mv -i'
It commands the shell to ask me if I really want to move or delete any files. This protects me from accidentally deleting important files. You can copy and paste that right into your .zshrc file. It will work just like it is and it is one of the most important safety features for using Linux.
AWK and ZSH scripting are very valuable skills. C, C++, QML and JavaScript are the languages we will be focusing on learning. Get familiar with AWK to learn how to communicate with your computer. It is one of the most powerful shell commands. C, C++, QML and JavaScript are the languages that Linux and KDE are written in.
Have fun and be careful, learning how to use Linux to expand your consciousness onto our global cloud of artificial intelligence. Be creative. Add value to the cloud. Make something valuable and trade it in our one world wide free marketplace of ideas, products and services.
Using all these tools to create something valuable is way more interesting and fun than playing any game.
Learn how to use C, C++, QML, Python and JavaScript to create applications. Websites are just one particular kind of application. They depend on a browser to run them. Native applications run on your desktop. Your browsers are native applications that you can run web applications in.
There are many clouds of artificial intelligence. Microsoft owns one. Apple owns one. Google owns once. China owns one. KDE owns one. The Internet itself is a global cloud of artificial intelligence.
Learning how to use your shell well, is an important stage of learning how to create your own, “do it yourself,” cloud of artificial intelligence and to harness other clouds of artificial intelligence for your own benefit. The following is a tiny fraction of what you can do with AWK and ZSH.
Shell Commands
man pages are the official Linux manual for the programs on your computer. Type man followed by the command you want to investigate.
Info pages are similar to man pages, written in a different style, with a little more info.
Command - Description ls - list files in pwd cd - change directory pwd - present working directory touch - create new file mkdir - create new directory echo - print something in the shell whoami - prints current user name whereis - locates the binary, source and manual files for the specified command names. which - locate a command cat - concatenate files to standard output chgrp - change file group ownership chmod - change file access permissions chown - change file owner and group cp - copy files and directories date - print or set the system data and time dd - convert and copy a file df - report filesystem disk space usage dmesg - print or control the kernel message buffer echo - display a line of text false - do nothing, unsuccessfully hostname - show or set the system's host name kill - send signals to processes ln make links between files login - begin a session on the system ls - list directory contents mkdir - make directories mknod - make block or character special files more - page through text mount - mount a filesystem mv - move/rename files ps - report process status pwd - print name of current working directory rm - remove files or directories rmdir - remove empty directories sed - The `sed' stream editor sh - POSIX compatible command shell stty - change and print terminal line settings su - change user ID to super user sync - flush filesystem buffers true - do nothing, successfully umount - unmount file systems uname - print system information
Environment variables
Environment variables are placeholders for data that can change. For example, the HOME variable can change depending on who is logged in.
export VARIABLE=example
prompt$ echo $VARIABLE
example
Delete a variable with
prompt$ unset VARIABLE
Use sudo to make global variables.
Here is a list of common environment variables in Linux:
$USER - your current user name. $SHELL - the path to the current command shell. $PWD - the current working directory. $HOSTNAME - the host name of the computer $HOME - your home directory. $MAIL - the location of the user's mail spool $LANG - your current language. $TZ - your time zone. $PS1 - the default prompt in Bash. $TERM - the current terminal type. $DISPLAY - the display used by X. $HISTFILESIZE - the maximum number of lines in the history file. $EDITOR - the user's preferred text editor, $MANPATH - the list of directories to search for man pages. $OSTYPE - the type of operating system.
PATH Environment Variable
A command or script must be located in one of the directories listed in your PATH, to be executed when you prompt for it on your command line. Use
echo $PATH
to display the path on your computer. You can run a program that is in your path from anywhere, just by entering the name of the program. Your computer will automatically search your $PATH and run the program. You can add a directory to your path with the command
export PATH="$HOME/bin:$PATH"
bin is the name of the directory, located in your home directory in this case, that you are adding to your $PATH.
Inode
An inode is metadata about a file, such as the access mode (read, write, execute permissions), ownership, file type, file size, group, number of links, etc. Inodes are identified by an integer number assigned to a file when the file is created
ls -il
Links
Hard links point directly to an inode. Links are hard links by default. Hard links have the same inode as the file they point to. Hard links cannot link to a file in another partition.
Use ln -s to make a symbolic link. Symbolic links are a special kind of file, pointing to other files. Symbolic links have a different inode than the file they point to. Symbolic links contain an automatically interpreted string that the operating system follows as a path to another file or directory. Symbolic links are more common than hard links and can link to any file on any partition.
Wild Cards
Wild cards are character variables
? matches a single character. * matches any characters, including any number of characters. [1-9] matches any single digit.
Streams
Streams are inputs to and outputs from programs.
Standard input (stdin) is the stream of data into a program. stdin usually comes from the keyboard, but can be redirected from another source, such as a file or an ssh connection.
Standard output (stdout) is the stream of data out of a program. stdout usually goes to the screen, but can be redirected to go somewhere else, such as a file or an ssh connection.
Standard error (stderr) is a stream of data for printing diagnostic or error messages. stderr usually goes to the screen, but can be redirected to a file or other device, depending on what the parent process sets up.
Redirecting streams
linux redirection symbols
> - redirects standard output to a file. If the file already exists, it is overwritten. >> - redirects output to a file, appending to the file if it already exists. 2> - directs stderr to a file. 2>> - appends stderr to a file. &> - directs stdout and stderr to a file. < - directs contents of a file to the command. << - accepts text as stdin on the following lines. <> - the specified file is used for stdin and stdout.
Pipe data between programs
Use the pipe symbol | to make the stdout of one program be the stdin of another program.
For example, ps -A | sort -k 2 | head
ps -A - lists all processes running on your system. sort -k 2 - sorts the processes using the process name in the second column. head - only prints the first ten lines of the output.
Sort lines of text in a file
The sort command is used to sort lines of text in a file. sort all by itself, orders the lines alphabetically.
-r - reverses the order -k - sorts the file by a certain column, -k 2 sorts the data using the second column.
grep
grep is used to find certain info, within large amounts of info. grep is case sensitive by default. Use -i option for case insensitive search.
grep [OPTIONS] PATTERN FILE
ps -A | grep htop
ps -A - lists all running processes. grep htop - limits the output to lines with the word htop in it.
find
The find command searches for files in the directory tree, starting from the specified location.
find PATH EXPRESSION
You can search files by filename, size, permissions, group, UID, etc.
name - searches by filename perm - searches for files with certain permissions size - searches by file size type d - searches for directories type f - searches for files user - searches by user group - searches by group
Wildcards must be enclosed in double quotes
When using -size, use c for bytes, k for kilobytes, M for megabytes and G for gigabytes.
locate
The locate command searches a database of names. locate finds files by name only. Use
sudo updatedb
to update the database and locate recently added files.
Word Count
wc displays the number of lines, words and bytes in a file
Options -l, -w -c limit the output to lines only, words only or bytes only, respectively.
File Type
file command will tell what kind of file a selected file is.
whereis
The whereis command is used to locate the binary, source and manual pages of a command.
head
You can display the first ten lines of a file with the head command. Use -n to change the number of lines. You can display more than one file with head.
tail
The tail command displays the last 10 lines of a file by default. Use the -n option to change the number of lines. The -f option keeps the file open and displays new lines as they are added to the file.
tee
Split the output of a program with the tee command. The output will be displayed on the screen and entered into a designated file. The file will be overwritten by default. Use -a option to append it, rather than overwriting it.
Swapping the <esc> and <caps lock> keys
Entering this command into your .zshrc file switches the esc and caps lock keys globally.
setxkbmap -option caps:swapescape
Source
geek-university